|
| 1 | +package registry |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "path/filepath" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/docker/cli/cli/config/configfile" |
| 9 | + configtypes "github.com/docker/cli/cli/config/types" |
| 10 | + "github.com/docker/cli/internal/test" |
| 11 | + "gotest.tools/v3/assert" |
| 12 | +) |
| 13 | + |
| 14 | +func TestRunLogoutMixedCaseServerAddress(t *testing.T) { |
| 15 | + cfg := configfile.New(filepath.Join(t.TempDir(), "config.json")) |
| 16 | + cli := test.NewFakeCli(nil) |
| 17 | + cli.SetConfigFile(cfg) |
| 18 | + |
| 19 | + const serverAddress = "myregistry.example.com" |
| 20 | + assert.NilError(t, cfg.GetCredentialsStore(serverAddress).Store(configtypes.AuthConfig{ |
| 21 | + Username: "my-username", |
| 22 | + Password: "my-password", |
| 23 | + ServerAddress: serverAddress, |
| 24 | + })) |
| 25 | + |
| 26 | + assert.NilError(t, runLogout(context.Background(), cli, "MyRegistry.Example.com")) |
| 27 | + credentials, err := cfg.GetAllCredentials() |
| 28 | + assert.NilError(t, err) |
| 29 | + assert.DeepEqual(t, credentials, map[string]configtypes.AuthConfig{}) |
| 30 | +} |
| 31 | + |
| 32 | +func TestRunLogoutUpperCaseServerAddress(t *testing.T) { |
| 33 | + cfg := configfile.New(filepath.Join(t.TempDir(), "config.json")) |
| 34 | + cli := test.NewFakeCli(nil) |
| 35 | + cli.SetConfigFile(cfg) |
| 36 | + |
| 37 | + const serverAddress = "MYREGISTRY.EXAMPLE.COM" |
| 38 | + assert.NilError(t, cfg.GetCredentialsStore(serverAddress).Store(configtypes.AuthConfig{ |
| 39 | + Username: "my-username", |
| 40 | + Password: "my-password", |
| 41 | + ServerAddress: serverAddress, |
| 42 | + })) |
| 43 | + |
| 44 | + assert.NilError(t, runLogout(context.Background(), cli, serverAddress)) |
| 45 | + credentials, err := cfg.GetAllCredentials() |
| 46 | + assert.NilError(t, err) |
| 47 | + assert.DeepEqual(t, credentials, map[string]configtypes.AuthConfig{}) |
| 48 | +} |
0 commit comments