Fix linter

Signed-off-by: Guillaume Tardif <guillaume.tardif@docker.com>
This commit is contained in:
Guillaume Tardif 2020-08-21 18:52:07 +02:00
parent 7204692e3a
commit 2bac8cf94e
5 changed files with 23 additions and 26 deletions

View File

@ -43,11 +43,11 @@ func TestMain(m *testing.M) {
func TestLocalBackend(t *testing.T) { func TestLocalBackend(t *testing.T) {
c := NewParallelE2eCLI(t, binDir) c := NewParallelE2eCLI(t, binDir)
c.RunDocker( "context", "create", "local", "test-context").Assert(t, icmd.Success) c.RunDocker("context", "create", "local", "test-context").Assert(t, icmd.Success)
c.RunDocker("context", "use", "test-context").Assert(t, icmd.Success) c.RunDocker("context", "use", "test-context").Assert(t, icmd.Success)
t.Run("run", func(t *testing.T) { t.Run("run", func(t *testing.T) {
res := c.RunDocker( "run", "-d", "nginx") res := c.RunDocker("run", "-d", "nginx")
containerName := strings.TrimSpace(res.Combined()) containerName := strings.TrimSpace(res.Combined())
t.Cleanup(func() { t.Cleanup(func() {
_ = c.RunDockerOrFail("rm", "-f", containerName) _ = c.RunDockerOrFail("rm", "-f", containerName)
@ -57,14 +57,14 @@ func TestLocalBackend(t *testing.T) {
}) })
t.Run("run with ports", func(t *testing.T) { t.Run("run with ports", func(t *testing.T) {
res := c.RunDocker( "run", "-d", "-p", "8080:80", "nginx") res := c.RunDocker("run", "-d", "-p", "8080:80", "nginx")
containerName := strings.TrimSpace(res.Combined()) containerName := strings.TrimSpace(res.Combined())
t.Cleanup(func() { t.Cleanup(func() {
_ = c.RunDockerOrFail("rm", "-f", containerName) _ = c.RunDockerOrFail("rm", "-f", containerName)
}) })
res = c.RunDocker( "inspect", containerName) res = c.RunDocker("inspect", containerName)
res.Assert(t, icmd.Expected{Out: `"Status": "running"`}) res.Assert(t, icmd.Expected{Out: `"Status": "running"`})
res = c.RunDocker( "ps") res = c.RunDocker("ps")
res.Assert(t, icmd.Expected{Out: "0.0.0.0:8080->80/tcp"}) res.Assert(t, icmd.Expected{Out: "0.0.0.0:8080->80/tcp"})
}) })

View File

@ -87,8 +87,8 @@ func TestLoginLogout(t *testing.T) {
_ = deleteResourceGroup(rg) _ = deleteResourceGroup(rg)
}) })
res := c.RunDocker("context", "create", "aci", contextName, "--subscription-id", sID, "--resource-group", rg, "--location", location) c.RunDocker("context", "create", "aci", contextName, "--subscription-id", sID, "--resource-group", rg, "--location", location)
res = c.RunDocker("context", "use", contextName) res := c.RunDocker("context", "use", contextName)
res.Assert(t, icmd.Expected{Out: contextName}) res.Assert(t, icmd.Expected{Out: contextName})
res = c.RunDocker("context", "ls") res = c.RunDocker("context", "ls")
res.Assert(t, icmd.Expected{Out: contextName + " *"}) res.Assert(t, icmd.Expected{Out: contextName + " *"})
@ -402,9 +402,8 @@ func TestCompose(t *testing.T) {
t.Run("compose up", func(t *testing.T) { t.Run("compose up", func(t *testing.T) {
// Name of Compose project is taken from current folder "acie2e" // Name of Compose project is taken from current folder "acie2e"
res := c.RunDocker("compose", "up", "-f", composeFile) c.RunDocker("compose", "up", "-f", composeFile)
res := c.RunDocker("ps")
res = c.RunDocker("ps")
out := strings.Split(strings.TrimSpace(res.Stdout()), "\n") out := strings.Split(strings.TrimSpace(res.Stdout()), "\n")
// Check three containers are running // Check three containers are running
assert.Assert(t, is.Len(out, 4)) assert.Assert(t, is.Len(out, 4))
@ -438,9 +437,8 @@ func TestCompose(t *testing.T) {
}) })
t.Run("update", func(t *testing.T) { t.Run("update", func(t *testing.T) {
res := c.RunDocker("compose", "up", "-f", composeFileMultiplePorts, "--project-name", composeProjectName) c.RunDocker("compose", "up", "-f", composeFileMultiplePorts, "--project-name", composeProjectName)
res := c.RunDocker("ps")
res = c.RunDocker("ps")
out := strings.Split(strings.TrimSpace(res.Stdout()), "\n") out := strings.Split(strings.TrimSpace(res.Stdout()), "\n")
// Check three containers are running // Check three containers are running
assert.Assert(t, is.Len(out, 4)) assert.Assert(t, is.Len(out, 4))
@ -481,9 +479,8 @@ func TestCompose(t *testing.T) {
}) })
t.Run("down", func(t *testing.T) { t.Run("down", func(t *testing.T) {
res := c.RunDocker("compose", "down", "--project-name", composeProjectName) c.RunDocker("compose", "down", "--project-name", composeProjectName)
res := c.RunDocker("ps")
res = c.RunDocker("ps")
out := strings.Split(strings.TrimSpace(res.Stdout()), "\n") out := strings.Split(strings.TrimSpace(res.Stdout()), "\n")
assert.Equal(t, len(out), 1) assert.Equal(t, len(out), 1)
}) })
@ -584,8 +581,8 @@ func createResourceGroup(sID, rgName string) error {
} }
func createAciContextAndUseIt(t *testing.T, c *E2eCLI, sID, rgName string) { func createAciContextAndUseIt(t *testing.T, c *E2eCLI, sID, rgName string) {
res := c.RunDocker("context", "create", "aci", contextName, "--subscription-id", sID, "--resource-group", rgName, "--location", location) c.RunDocker("context", "create", "aci", contextName, "--subscription-id", sID, "--resource-group", rgName, "--location", location)
res = c.RunDocker("context", "use", contextName) res := c.RunDocker("context", "use", contextName)
res.Assert(t, icmd.Expected{Out: contextName}) res.Assert(t, icmd.Expected{Out: contextName})
res = c.RunDocker("context", "ls") res = c.RunDocker("context", "ls")
res.Assert(t, icmd.Expected{Out: contextName + " *"}) res.Assert(t, icmd.Expected{Out: contextName + " *"})

View File

@ -357,8 +357,8 @@ func TestLegacyLogin(t *testing.T) {
func TestUnsupportedCommand(t *testing.T) { func TestUnsupportedCommand(t *testing.T) {
c := NewParallelE2eCLI(t, binDir) c := NewParallelE2eCLI(t, binDir)
res := c.RunDocker("context", "create", "example", "test-example") c.RunDocker("context", "create", "example", "test-example")
res = c.RunDockerOrFail("--context", "test-example", "images") res := c.RunDockerOrFail("--context", "test-example", "images")
res.Assert(t, icmd.Expected{ res.Assert(t, icmd.Expected{
ExitCode: 1, ExitCode: 1,
Err: `Command "images" not available in current context (test-example), you can use the "default" context to run this command`, Err: `Command "images" not available in current context (test-example), you can use the "default" context to run this command`,

View File

@ -71,8 +71,8 @@ func TestSecrets(t *testing.T) {
}) })
t.Run("rm secret", func(t *testing.T) { t.Run("rm secret", func(t *testing.T) {
res := cmd.RunDocker("secret", "rm", secretName) cmd.RunDocker("secret", "rm", secretName)
res = cmd.RunDocker("secret", "list") res := cmd.RunDocker("secret", "list")
assert.Check(t, !strings.Contains(res.Stdout(), secretName)) assert.Check(t, !strings.Contains(res.Stdout(), secretName))
}) })
} }
@ -132,7 +132,7 @@ func setupTest(t *testing.T) (*E2eCLI, string) {
if localTestProfile != "" { if localTestProfile != "" {
region := os.Getenv("TEST_AWS_REGION") region := os.Getenv("TEST_AWS_REGION")
assert.Check(t, region != "") assert.Check(t, region != "")
res = c.RunDocker("context", "create", "ecs", contextName, "--profile", localTestProfile, "--region", region) c.RunDocker("context", "create", "ecs", contextName, "--profile", localTestProfile, "--region", region)
} else { } else {
profile := contextName profile := contextName
region := os.Getenv("AWS_DEFAULT_REGION") region := os.Getenv("AWS_DEFAULT_REGION")
@ -141,7 +141,7 @@ func setupTest(t *testing.T) (*E2eCLI, string) {
assert.Check(t, keyID != "") assert.Check(t, keyID != "")
assert.Check(t, secretKey != "") assert.Check(t, secretKey != "")
assert.Check(t, region != "") assert.Check(t, region != "")
res = c.RunDocker("context", "create", "ecs", contextName, "--profile", profile, "--region", region, "--secret-key", secretKey, "--key-id", keyID) c.RunDocker("context", "create", "ecs", contextName, "--profile", profile, "--region", region, "--secret-key", secretKey, "--key-id", keyID)
} }
res = c.RunDocker("context", "use", contextName) res = c.RunDocker("context", "use", contextName)
res.Assert(t, icmd.Expected{Out: contextName}) res.Assert(t, icmd.Expected{Out: contextName})

View File

@ -53,7 +53,7 @@ func init() {
type E2eCLI struct { type E2eCLI struct {
BinDir string BinDir string
ConfigDir string ConfigDir string
test *testing.T test *testing.T
} }
// NewParallelE2eCLI returns a configured TestE2eCLI with t.Parallel() set // NewParallelE2eCLI returns a configured TestE2eCLI with t.Parallel() set
@ -163,7 +163,7 @@ func (c *E2eCLI) NewDockerCmd(args ...string) icmd.Cmd {
// RunDockerOrFail runs a docker command and returns a result // RunDockerOrFail runs a docker command and returns a result
func (c *E2eCLI) RunDockerOrFail(args ...string) *icmd.Result { func (c *E2eCLI) RunDockerOrFail(args ...string) *icmd.Result {
fmt.Printf(" [%s] docker %s\n", c.test.Name() , strings.Join(args, " ") ) fmt.Printf(" [%s] docker %s\n", c.test.Name(), strings.Join(args, " "))
return icmd.RunCmd(c.NewDockerCmd(args...)) return icmd.RunCmd(c.NewDockerCmd(args...))
} }