@@ -19,6 +19,7 @@ package docker
19
19
import (
20
20
"context"
21
21
"fmt"
22
+ "runtime"
22
23
"testing"
23
24
24
25
"github.com/docker/docker/api/types"
@@ -44,11 +45,52 @@ var allAuthConfig = map[string]types.AuthConfig{
44
45
func (t testAuthHelper ) GetAuthConfig (string ) (types.AuthConfig , error ) {
45
46
return gcrAuthConfig , t .getAuthConfigErr
46
47
}
47
-
48
- func (t testAuthHelper ) GetAllAuthConfigs () (map [string ]types.AuthConfig , error ) {
48
+ func (t testAuthHelper ) GetAllAuthConfigs (context.Context ) (map [string ]types.AuthConfig , error ) {
49
49
return allAuthConfig , t .getAllAuthConfigsErr
50
50
}
51
51
52
+ func TestGetAllAuthConfigs (t * testing.T ) {
53
+ testutil .Run (t , "auto-configure gcr.io" , func (t * testutil.T ) {
54
+ if runtime .GOOS == "windows" {
55
+ t .Skip ("test doesn't work on windows" )
56
+ }
57
+
58
+ tmpDir := t .NewTempDir ().
59
+ Write ("config.json" , `{"credHelpers":{"my.registry":"helper"}}` ).
60
+ Write ("docker-credential-gcloud" , `#!/bin/sh
61
+ read server
62
+ echo "{\"Username\":\"<token>\",\"Secret\":\"TOKEN_$server\"}"` ).
63
+ Write ("docker-credential-helper" , `#!/bin/sh
64
+ read server
65
+ echo "{\"Username\":\"<token>\",\"Secret\":\"TOKEN_$server\"}"` )
66
+ t .Override (& configDir , tmpDir .Root ())
67
+ t .SetEnvs (map [string ]string {"PATH" : tmpDir .Root ()})
68
+
69
+ auth , err := DefaultAuthHelper .GetAllAuthConfigs (context .Background ())
70
+
71
+ t .CheckNoError (err )
72
+ t .CheckDeepEqual (map [string ]types.AuthConfig {
73
+ "asia.gcr.io" : {IdentityToken : "TOKEN_asia.gcr.io" },
74
+ "eu.gcr.io" : {IdentityToken : "TOKEN_eu.gcr.io" },
75
+ "gcr.io" : {IdentityToken : "TOKEN_gcr.io" },
76
+ "my.registry" : {IdentityToken : "TOKEN_my.registry" },
77
+ "marketplace.gcr.io" : {IdentityToken : "TOKEN_marketplace.gcr.io" },
78
+ "staging-k8s.gcr.io" : {IdentityToken : "TOKEN_staging-k8s.gcr.io" },
79
+ "us.gcr.io" : {IdentityToken : "TOKEN_us.gcr.io" },
80
+ }, auth )
81
+ })
82
+
83
+ testutil .Run (t , "invalid config.json" , func (t * testutil.T ) {
84
+ tmpDir := t .NewTempDir ().Write ("config.json" , "invalid json" )
85
+ t .Override (& configDir , tmpDir .Root ())
86
+
87
+ auth , err := DefaultAuthHelper .GetAllAuthConfigs (context .Background ())
88
+
89
+ t .CheckError (true , err )
90
+ t .CheckEmpty (auth )
91
+ })
92
+ }
93
+
52
94
func TestGetEncodedRegistryAuth (t * testing.T ) {
53
95
tests := []struct {
54
96
description string
0 commit comments