integration test: specify image name for testing dev container (#15069)

* integration test: specify image name for testing dev container

* Add todo
pull/15086/head
cskh 2022-10-20 17:12:36 -04:00 committed by GitHub
parent 91e40195bd
commit fa970a85ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 32 additions and 18 deletions

View File

@ -144,7 +144,7 @@ func newContainerRequest(config Config, name, configFile, dataDir, license strin
app := testcontainers.ContainerRequest{ app := testcontainers.ContainerRequest{
NetworkMode: dockercontainer.NetworkMode("container:" + name + "-pod"), NetworkMode: dockercontainer.NetworkMode("container:" + name + "-pod"),
Image: consulImage + ":" + config.Version, Image: config.Image + ":" + config.Version,
WaitingFor: wait.ForLog(bootLogLine).WithStartupTimeout(10 * time.Second), WaitingFor: wait.ForLog(bootLogLine).WithStartupTimeout(10 * time.Second),
AutoRemove: false, AutoRemove: false,
Name: name, Name: name,

View File

@ -2,5 +2,3 @@
// +build !consulent // +build !consulent
package node package node
const consulImage = "consul"

View File

@ -18,6 +18,7 @@ type Node interface {
// Config is a set of configurations required to create a Node // Config is a set of configurations required to create a Node
type Config struct { type Config struct {
HCL string HCL string
Image string
Version string Version string
Cmd []string Cmd []string
} }

View File

@ -5,5 +5,10 @@ package utils
import "flag" import "flag"
var TargetImage = flag.String("target-version", "local", "docker image to be used as UUT (unit under test)") // TODO: need a better way to abstract the container creation and configuration;
var LatestImage = flag.String("latest-version", "1.11", "docker image to be used as latest") // please refer to the discussion in github PR
var TargetImage = flag.String("target-image", "consul", "docker image name to be used under test (Default: consul)")
var TargetVersion = flag.String("target-version", "local", "docker image version to be used as UUT (unit under test)")
var LatestImage = flag.String("latest-image", "consul", "docker image name to be used under test (Default: consul)")
var LatestVersion = flag.String("latest-version", "1.11", "docker image to be used as latest")

View File

@ -29,7 +29,8 @@ func TestLeadershipMetrics(t *testing.T) {
statsite_address = "127.0.0.1:2180" statsite_address = "127.0.0.1:2180"
}`, }`,
Cmd: []string{"agent", "-client=0.0.0.0"}, Cmd: []string{"agent", "-client=0.0.0.0"},
Version: *utils.TargetImage, Version: *utils.TargetVersion,
Image: *utils.TargetImage,
}) })
numServer := 3 numServer := 3
@ -41,7 +42,8 @@ func TestLeadershipMetrics(t *testing.T) {
bootstrap_expect=3 bootstrap_expect=3
server=true`, server=true`,
Cmd: []string{"agent", "-client=0.0.0.0"}, Cmd: []string{"agent", "-client=0.0.0.0"},
Version: *utils.TargetImage, Version: *utils.TargetVersion,
Image: *utils.TargetImage,
}) })
} }

View File

@ -4,3 +4,5 @@
- run the tests. - run the tests.
To specify targets and latest image pass `target-version` and `latest-version` to the tests. By default, it uses the `consul` docker image with respectively `local` and `latest` tags. To specify targets and latest image pass `target-version` and `latest-version` to the tests. By default, it uses the `consul` docker image with respectively `local` and `latest` tags.
To use dev consul image, pass `target-image` and `target-version`, `-target-image hashicorppreview/consul -target-version 1.14-dev`.

View File

@ -22,10 +22,10 @@ func TestTargetServersWithLatestGAClients(t *testing.T) {
numClients = 1 numClients = 1
) )
cluster := serversCluster(t, numServers, *utils.TargetImage) cluster := serversCluster(t, numServers, *utils.TargetVersion, *utils.TargetImage)
defer terminate(t, cluster) defer terminate(t, cluster)
clients := clientsCreate(t, numClients, *utils.LatestImage, cluster.EncryptKey) clients := clientsCreate(t, numClients, *utils.LatestImage, *utils.LatestVersion, cluster.EncryptKey)
require.NoError(t, cluster.AddNodes(clients)) require.NoError(t, cluster.AddNodes(clients))
@ -78,7 +78,8 @@ func TestMixedServersMajorityLatestGAClient(t *testing.T) {
log_level="DEBUG" log_level="DEBUG"
server=true`, server=true`,
Cmd: []string{"agent", "-client=0.0.0.0"}, Cmd: []string{"agent", "-client=0.0.0.0"},
Version: *utils.TargetImage, Version: *utils.TargetVersion,
Image: *utils.TargetImage,
}) })
for i := 1; i < 3; i++ { for i := 1; i < 3; i++ {
@ -89,7 +90,8 @@ func TestMixedServersMajorityLatestGAClient(t *testing.T) {
bootstrap_expect=3 bootstrap_expect=3
server=true`, server=true`,
Cmd: []string{"agent", "-client=0.0.0.0"}, Cmd: []string{"agent", "-client=0.0.0.0"},
Version: *utils.LatestImage, Version: *utils.LatestVersion,
Image: *utils.LatestImage,
}) })
} }
@ -102,7 +104,7 @@ func TestMixedServersMajorityLatestGAClient(t *testing.T) {
numClients = 1 numClients = 1
) )
clients := clientsCreate(t, numClients, *utils.LatestImage, cluster.EncryptKey) clients := clientsCreate(t, numClients, *utils.LatestImage, *utils.LatestVersion, cluster.EncryptKey)
require.NoError(t, cluster.AddNodes(clients)) require.NoError(t, cluster.AddNodes(clients))
@ -156,7 +158,8 @@ func TestMixedServersMajorityTargetGAClient(t *testing.T) {
bootstrap_expect=3 bootstrap_expect=3
server=true`, server=true`,
Cmd: []string{"agent", "-client=0.0.0.0"}, Cmd: []string{"agent", "-client=0.0.0.0"},
Version: *utils.TargetImage, Version: *utils.TargetVersion,
Image: *utils.TargetImage,
}) })
} }
@ -166,7 +169,8 @@ func TestMixedServersMajorityTargetGAClient(t *testing.T) {
log_level="DEBUG" log_level="DEBUG"
server=true`, server=true`,
Cmd: []string{"agent", "-client=0.0.0.0"}, Cmd: []string{"agent", "-client=0.0.0.0"},
Version: *utils.LatestImage, Version: *utils.LatestVersion,
Image: *utils.LatestImage,
}) })
cluster, err := libcluster.New(configs) cluster, err := libcluster.New(configs)
@ -177,7 +181,7 @@ func TestMixedServersMajorityTargetGAClient(t *testing.T) {
numClients = 1 numClients = 1
) )
clients := clientsCreate(t, numClients, *utils.LatestImage, cluster.EncryptKey) clients := clientsCreate(t, numClients, *utils.LatestImage, *utils.LatestVersion, cluster.EncryptKey)
require.NoError(t, cluster.AddNodes(clients)) require.NoError(t, cluster.AddNodes(clients))
@ -220,7 +224,7 @@ func TestMixedServersMajorityTargetGAClient(t *testing.T) {
} }
} }
func clientsCreate(t *testing.T, numClients int, version string, serfKey string) []node.Node { func clientsCreate(t *testing.T, numClients int, image string, version string, serfKey string) []node.Node {
clients := make([]node.Node, numClients) clients := make([]node.Node, numClients)
for i := 0; i < numClients; i++ { for i := 0; i < numClients; i++ {
var err error var err error
@ -232,6 +236,7 @@ func clientsCreate(t *testing.T, numClients int, version string, serfKey string)
encrypt = %q`, utils.RandName("consul-client"), serfKey), encrypt = %q`, utils.RandName("consul-client"), serfKey),
Cmd: []string{"agent", "-client=0.0.0.0"}, Cmd: []string{"agent", "-client=0.0.0.0"},
Version: version, Version: version,
Image: image,
}) })
require.NoError(t, err) require.NoError(t, err)
} }
@ -251,7 +256,7 @@ func serviceCreate(t *testing.T, client *api.Client, serviceName string) uint64
return meta.LastIndex return meta.LastIndex
} }
func serversCluster(t *testing.T, numServers int, version string) *libcluster.Cluster { func serversCluster(t *testing.T, numServers int, version string, image string) *libcluster.Cluster {
var configs []node.Config var configs []node.Config
for i := 0; i < numServers; i++ { for i := 0; i < numServers; i++ {
configs = append(configs, node.Config{ configs = append(configs, node.Config{
@ -261,6 +266,7 @@ func serversCluster(t *testing.T, numServers int, version string) *libcluster.Cl
server=true`, server=true`,
Cmd: []string{"agent", "-client=0.0.0.0"}, Cmd: []string{"agent", "-client=0.0.0.0"},
Version: version, Version: version,
Image: image,
}) })
} }
cluster, err := libcluster.New(configs) cluster, err := libcluster.New(configs)