integration-cli: DockerRegistryAuthHtpasswdSuite: replace dockerCmd

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-07-27 18:27:51 +02:00
parent d3f4580519
commit 8e2e1f3d28
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
2 changed files with 10 additions and 8 deletions

View file

@ -7,6 +7,7 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/docker/docker/integration-cli/cli"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
) )
@ -30,7 +31,7 @@ func (s *DockerCLILoginSuite) TestLoginWithoutTTY(c *testing.T) {
// run the command and block until it's done // run the command and block until it's done
err := cmd.Run() err := cmd.Run()
assert.ErrorContains(c, err, "") //"Expected non nil err when logging in & TTY not available" assert.ErrorContains(c, err, "") // "Expected non nil err when logging in & TTY not available"
} }
func (s *DockerRegistryAuthHtpasswdSuite) TestLoginToPrivateRegistry(c *testing.T) { func (s *DockerRegistryAuthHtpasswdSuite) TestLoginToPrivateRegistry(c *testing.T) {
@ -40,5 +41,5 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestLoginToPrivateRegistry(c *testing.
assert.Assert(c, strings.Contains(out, "401 Unauthorized")) assert.Assert(c, strings.Contains(out, "401 Unauthorized"))
// now it's fine // now it's fine
dockerCmd(c, "login", "-u", s.reg.Username(), "-p", s.reg.Password(), privateRegistryURL) cli.DockerCmd(c, "login", "-u", s.reg.Username(), "-p", s.reg.Password(), privateRegistryURL)
} }

View file

@ -9,6 +9,7 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/docker/docker/integration-cli/cli"
"github.com/docker/docker/testutil" "github.com/docker/docker/testutil"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
) )
@ -26,7 +27,7 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestLogoutWithExternalAuth(c *testing.
testPath := fmt.Sprintf("%s%c%s", osPath, filepath.ListSeparator, absolute) testPath := fmt.Sprintf("%s%c%s", osPath, filepath.ListSeparator, absolute)
c.Setenv("PATH", testPath) c.Setenv("PATH", testPath)
repoName := fmt.Sprintf("%v/dockercli/busybox:authtest", privateRegistryURL) imgRepoName := fmt.Sprintf("%v/dockercli/busybox:authtest", privateRegistryURL)
tmp, err := os.MkdirTemp("", "integration-cli-") tmp, err := os.MkdirTemp("", "integration-cli-")
assert.NilError(c, err) assert.NilError(c, err)
@ -46,9 +47,9 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestLogoutWithExternalAuth(c *testing.
assert.Assert(c, !strings.Contains(string(b), `"auth":`)) assert.Assert(c, !strings.Contains(string(b), `"auth":`))
assert.Assert(c, strings.Contains(string(b), privateRegistryURL)) assert.Assert(c, strings.Contains(string(b), privateRegistryURL))
_, err = s.d.Cmd("--config", tmp, "tag", "busybox", repoName) _, err = s.d.Cmd("--config", tmp, "tag", "busybox", imgRepoName)
assert.NilError(c, err) assert.NilError(c, err)
_, err = s.d.Cmd("--config", tmp, "push", repoName) _, err = s.d.Cmd("--config", tmp, "push", imgRepoName)
assert.NilError(c, err) assert.NilError(c, err)
_, err = s.d.Cmd("--config", tmp, "logout", privateRegistryURL) _, err = s.d.Cmd("--config", tmp, "logout", privateRegistryURL)
assert.NilError(c, err) assert.NilError(c, err)
@ -58,7 +59,7 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestLogoutWithExternalAuth(c *testing.
assert.Assert(c, !strings.Contains(string(b), privateRegistryURL)) assert.Assert(c, !strings.Contains(string(b), privateRegistryURL))
// check I cannot pull anymore // check I cannot pull anymore
out, err := s.d.Cmd("--config", tmp, "pull", repoName) out, err := s.d.Cmd("--config", tmp, "pull", imgRepoName)
assert.ErrorContains(c, err, "", out) assert.ErrorContains(c, err, "", out)
assert.Assert(c, strings.Contains(out, "no basic auth credentials")) assert.Assert(c, strings.Contains(out, "no basic auth credentials"))
} }
@ -88,14 +89,14 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestLogoutWithWrongHostnamesStored(c *
err = os.WriteFile(configPath, []byte(externalAuthConfig), 0o644) err = os.WriteFile(configPath, []byte(externalAuthConfig), 0o644)
assert.NilError(c, err) assert.NilError(c, err)
dockerCmd(c, "--config", tmp, "login", "-u", s.reg.Username(), "-p", s.reg.Password(), privateRegistryURL) cli.DockerCmd(c, "--config", tmp, "login", "-u", s.reg.Username(), "-p", s.reg.Password(), privateRegistryURL)
b, err := os.ReadFile(configPath) b, err := os.ReadFile(configPath)
assert.NilError(c, err) assert.NilError(c, err)
assert.Assert(c, strings.Contains(string(b), fmt.Sprintf(`"https://%s": {}`, privateRegistryURL))) assert.Assert(c, strings.Contains(string(b), fmt.Sprintf(`"https://%s": {}`, privateRegistryURL)))
assert.Assert(c, strings.Contains(string(b), fmt.Sprintf(`"%s": {}`, privateRegistryURL))) assert.Assert(c, strings.Contains(string(b), fmt.Sprintf(`"%s": {}`, privateRegistryURL)))
dockerCmd(c, "--config", tmp, "logout", privateRegistryURL) cli.DockerCmd(c, "--config", tmp, "logout", privateRegistryURL)
b, err = os.ReadFile(configPath) b, err = os.ReadFile(configPath)
assert.NilError(c, err) assert.NilError(c, err)