MCPcopy Index your code
hub / github.com/docker/cli / TestGetDefaultAuthConfig

Function TestGetDefaultAuthConfig

cli/command/registry_test.go:31–83  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

29}
30
31func TestGetDefaultAuthConfig(t *testing.T) {
32 testCases := []struct {
33 checkCredStore bool
34 inputServerAddress string
35 expectedAuthConfig registry.AuthConfig
36 }{
37 {
38 checkCredStore: false,
39 inputServerAddress: "",
40 expectedAuthConfig: registry.AuthConfig{
41 ServerAddress: "",
42 Username: "",
43 Password: "",
44 },
45 },
46 {
47 checkCredStore: true,
48 inputServerAddress: testAuthConfigs[0].ServerAddress,
49 expectedAuthConfig: testAuthConfigs[0],
50 },
51 {
52 checkCredStore: true,
53 inputServerAddress: testAuthConfigs[1].ServerAddress,
54 expectedAuthConfig: testAuthConfigs[1],
55 },
56 {
57 checkCredStore: true,
58 inputServerAddress: "https://" + testAuthConfigs[1].ServerAddress,
59 expectedAuthConfig: testAuthConfigs[1],
60 },
61 }
62
63 tmpDir := t.TempDir()
64 cfg := configfile.New(filepath.Join(tmpDir, "cli-config.json"))
65 for _, authConfig := range testAuthConfigs {
66 assert.Check(t, cfg.GetCredentialsStore(authConfig.ServerAddress).Store(configtypes.AuthConfig{
67 Username: authConfig.Username,
68 Password: authConfig.Password,
69 ServerAddress: authConfig.ServerAddress,
70
71 // TODO(thaJeztah): Are these expected to be included?
72 Auth: authConfig.Auth,
73 IdentityToken: authConfig.IdentityToken,
74 RegistryToken: authConfig.RegistryToken,
75 }))
76 }
77 for _, tc := range testCases {
78 serverAddress := tc.inputServerAddress
79 authCfg, err := command.GetDefaultAuthConfig(cfg, tc.checkCredStore, serverAddress, serverAddress == "https://index.docker.io/v1/")
80 assert.NilError(t, err)
81 assert.Check(t, is.DeepEqual(tc.expectedAuthConfig, authCfg))
82 }
83}
84
85func TestGetDefaultAuthConfig_HelperError(t *testing.T) {
86 cfg := configfile.New("filename")

Callers

nothing calls this directly

Calls 2

GetCredentialsStoreMethod · 0.80
StoreMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…