MCPcopy Create free account
hub / github.com/docker/cli / TestJSONWithCredentialHelpers

Function TestJSONWithCredentialHelpers

cli/config/config_test.go:250–281  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

248}
249
250func TestJSONWithCredentialHelpers(t *testing.T) {
251 tmpHome := t.TempDir()
252
253 fn := filepath.Join(tmpHome, ConfigFileName)
254 js := `{
255 "auths": { "https://index.docker.io/v1/": { "auth": "am9lam9lOmhlbGxv", "email": "user@example.com" } },
256 "credHelpers": { "images.io": "images-io", "containers.com": "crazy-secure-storage" }
257}`
258 if err := os.WriteFile(fn, []byte(js), 0o600); err != nil {
259 t.Fatal(err)
260 }
261
262 config, err := Load(tmpHome)
263 assert.NilError(t, err)
264
265 if config.CredentialHelpers == nil {
266 t.Fatal("config.CredentialHelpers was nil")
267 } else if config.CredentialHelpers["images.io"] != "images-io" ||
268 config.CredentialHelpers["containers.com"] != "crazy-secure-storage" {
269 t.Fatalf("Credential helpers not deserialized properly: %v\n", config.CredentialHelpers)
270 }
271
272 // Now save it and make sure it shows up in new form
273 configStr := saveConfigAndValidateNewFormat(t, config, tmpHome)
274 if !strings.Contains(configStr, `"credHelpers":`) ||
275 !strings.Contains(configStr, "images.io") ||
276 !strings.Contains(configStr, "images-io") ||
277 !strings.Contains(configStr, "containers.com") ||
278 !strings.Contains(configStr, "crazy-secure-storage") {
279 t.Fatalf("Should have save in new form: %s", configStr)
280 }
281}
282
283// Save it and make sure it shows up in new form
284func saveConfigAndValidateNewFormat(t *testing.T, config *configfile.ConfigFile, configDir string) string {

Callers

nothing calls this directly

Calls 3

ContainsMethod · 0.80
LoadFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…