@@ -86,7 +86,7 @@ func TestEmptyFile(t *testing.T) {
8686 }
8787}
8888
89- func TestEmptyJson (t * testing.T ) {
89+ func TestEmptyJSON (t * testing.T ) {
9090 tmpHome , err := ioutil .TempDir ("" , "config-test" )
9191 if err != nil {
9292 t .Fatal (err )
@@ -193,7 +193,7 @@ func TestOldValidAuth(t *testing.T) {
193193 }
194194}
195195
196- func TestOldJsonInvalid (t * testing.T ) {
196+ func TestOldJSONInvalid (t * testing.T ) {
197197 tmpHome , err := ioutil .TempDir ("" , "config-test" )
198198 if err != nil {
199199 t .Fatal (err )
@@ -219,7 +219,7 @@ func TestOldJsonInvalid(t *testing.T) {
219219 }
220220}
221221
222- func TestOldJson (t * testing.T ) {
222+ func TestOldJSON (t * testing.T ) {
223223 tmpHome , err := ioutil .TempDir ("" , "config-test" )
224224 if err != nil {
225225 t .Fatal (err )
@@ -265,7 +265,7 @@ func TestOldJson(t *testing.T) {
265265 }
266266}
267267
268- func TestNewJson (t * testing.T ) {
268+ func TestNewJSON (t * testing.T ) {
269269 tmpHome , err := ioutil .TempDir ("" , "config-test" )
270270 if err != nil {
271271 t .Fatal (err )
@@ -304,7 +304,7 @@ func TestNewJson(t *testing.T) {
304304 }
305305}
306306
307- func TestNewJsonNoEmail (t * testing.T ) {
307+ func TestNewJSONNoEmail (t * testing.T ) {
308308 tmpHome , err := ioutil .TempDir ("" , "config-test" )
309309 if err != nil {
310310 t .Fatal (err )
@@ -343,7 +343,7 @@ func TestNewJsonNoEmail(t *testing.T) {
343343 }
344344}
345345
346- func TestJsonWithPsFormat (t * testing.T ) {
346+ func TestJSONWithPsFormat (t * testing.T ) {
347347 tmpHome , err := ioutil .TempDir ("" , "config-test" )
348348 if err != nil {
349349 t .Fatal (err )
@@ -376,6 +376,78 @@ func TestJsonWithPsFormat(t *testing.T) {
376376 }
377377}
378378
379+ func TestJSONWithCredentialStore (t * testing.T ) {
380+ tmpHome , err := ioutil .TempDir ("" , "config-test" )
381+ if err != nil {
382+ t .Fatal (err )
383+ }
384+ defer os .RemoveAll (tmpHome )
385+
386+ fn := filepath .Join (tmpHome , ConfigFileName )
387+ js := `{
388+ "auths": { "https://index.docker.io/v1/": { "auth": "am9lam9lOmhlbGxv", "email": "[email protected] " } }, 389+ "credsStore": "crazy-secure-storage"
390+ }`
391+ if err := ioutil .WriteFile (fn , []byte (js ), 0600 ); err != nil {
392+ t .Fatal (err )
393+ }
394+
395+ config , err := Load (tmpHome )
396+ if err != nil {
397+ t .Fatalf ("Failed loading on empty json file: %q" , err )
398+ }
399+
400+ if config .CredentialsStore != "crazy-secure-storage" {
401+ t .Fatalf ("Unknown credential store: %s\n " , config .CredentialsStore )
402+ }
403+
404+ // Now save it and make sure it shows up in new form
405+ configStr := saveConfigAndValidateNewFormat (t , config , tmpHome )
406+ if ! strings .Contains (configStr , `"credsStore":` ) ||
407+ ! strings .Contains (configStr , "crazy-secure-storage" ) {
408+ t .Fatalf ("Should have save in new form: %s" , configStr )
409+ }
410+ }
411+
412+ func TestJSONWithCredentialHelpers (t * testing.T ) {
413+ tmpHome , err := ioutil .TempDir ("" , "config-test" )
414+ if err != nil {
415+ t .Fatal (err )
416+ }
417+ defer os .RemoveAll (tmpHome )
418+
419+ fn := filepath .Join (tmpHome , ConfigFileName )
420+ js := `{
421+ "auths": { "https://index.docker.io/v1/": { "auth": "am9lam9lOmhlbGxv", "email": "[email protected] " } }, 422+ "credHelpers": { "images.io": "images-io", "containers.com": "crazy-secure-storage" }
423+ }`
424+ if err := ioutil .WriteFile (fn , []byte (js ), 0600 ); err != nil {
425+ t .Fatal (err )
426+ }
427+
428+ config , err := Load (tmpHome )
429+ if err != nil {
430+ t .Fatalf ("Failed loading on empty json file: %q" , err )
431+ }
432+
433+ if config .CredentialHelpers == nil {
434+ t .Fatal ("config.CredentialHelpers was nil" )
435+ } else if config .CredentialHelpers ["images.io" ] != "images-io" ||
436+ config .CredentialHelpers ["containers.com" ] != "crazy-secure-storage" {
437+ t .Fatalf ("Credential helpers not deserialized properly: %v\n " , config .CredentialHelpers )
438+ }
439+
440+ // Now save it and make sure it shows up in new form
441+ configStr := saveConfigAndValidateNewFormat (t , config , tmpHome )
442+ if ! strings .Contains (configStr , `"credHelpers":` ) ||
443+ ! strings .Contains (configStr , "images.io" ) ||
444+ ! strings .Contains (configStr , "images-io" ) ||
445+ ! strings .Contains (configStr , "containers.com" ) ||
446+ ! strings .Contains (configStr , "crazy-secure-storage" ) {
447+ t .Fatalf ("Should have save in new form: %s" , configStr )
448+ }
449+ }
450+
379451// Save it and make sure it shows up in new form
380452func saveConfigAndValidateNewFormat (t * testing.T , config * configfile.ConfigFile , homeFolder string ) string {
381453 if err := config .Save (); err != nil {
@@ -420,7 +492,7 @@ func TestConfigFile(t *testing.T) {
420492 }
421493}
422494
423- func TestJsonReaderNoFile (t * testing.T ) {
495+ func TestJSONReaderNoFile (t * testing.T ) {
424496 js := ` { "auths": { "https://index.docker.io/v1/": { "auth": "am9lam9lOmhlbGxv", "email": "[email protected] " } } }` 425497
426498 config , err := LoadFromReader (strings .NewReader (js ))
@@ -435,7 +507,7 @@ func TestJsonReaderNoFile(t *testing.T) {
435507
436508}
437509
438- func TestOldJsonReaderNoFile (t * testing.T ) {
510+ func TestOldJSONReaderNoFile (t * testing.T ) {
439511 js := `{"https://index.docker.io/v1/":{"auth":"am9lam9lOmhlbGxv","email":"[email protected] "}}` 440512
441513 config , err := LegacyLoadFromReader (strings .NewReader (js ))
@@ -449,7 +521,7 @@ func TestOldJsonReaderNoFile(t *testing.T) {
449521 }
450522}
451523
452- func TestJsonWithPsFormatNoFile (t * testing.T ) {
524+ func TestJSONWithPsFormatNoFile (t * testing.T ) {
453525 js := `{
454526 "auths": { "https://index.docker.io/v1/": { "auth": "am9lam9lOmhlbGxv", "email": "[email protected] " } }, 455527 "psFormat": "table {{.ID}}\\t{{.Label \"com.docker.label.cpu\"}}"
@@ -465,7 +537,7 @@ func TestJsonWithPsFormatNoFile(t *testing.T) {
465537
466538}
467539
468- func TestJsonSaveWithNoFile (t * testing.T ) {
540+ func TestJSONSaveWithNoFile (t * testing.T ) {
469541 js := `{
470542 "auths": { "https://index.docker.io/v1/": { "auth": "am9lam9lOmhlbGxv" } },
471543 "psFormat": "table {{.ID}}\\t{{.Label \"com.docker.label.cpu\"}}"
@@ -507,7 +579,7 @@ func TestJsonSaveWithNoFile(t *testing.T) {
507579 }
508580}
509581
510- func TestLegacyJsonSaveWithNoFile (t * testing.T ) {
582+ func TestLegacyJSONSaveWithNoFile (t * testing.T ) {
511583
512584 js := `{"https://index.docker.io/v1/":{"auth":"am9lam9lOmhlbGxv","email":"[email protected] "}}` 513585 config , err := LegacyLoadFromReader (strings .NewReader (js ))
0 commit comments