@@ -109,6 +109,7 @@ func TestAttachedServiceAccount(t *testing.T) {
109
109
110
110
func TestImagePullSecrets (t * testing.T ) {
111
111
username , password := "foo" , "bar"
112
+ specificUser , specificPass := "very" , "specific"
112
113
client := fakeclient .NewSimpleClientset (& corev1.ServiceAccount {
113
114
ObjectMeta : metav1.ObjectMeta {
114
115
Name : "default" ,
@@ -122,8 +123,9 @@ func TestImagePullSecrets(t *testing.T) {
122
123
Type : corev1 .SecretTypeDockercfg ,
123
124
Data : map [string ][]byte {
124
125
corev1 .DockerConfigKey : []byte (
125
- fmt .Sprintf (`{"fake.registry.io": {"auth": "%s"}}` ,
126
- base64 .StdEncoding .EncodeToString ([]byte (username + ":" + password ))),
126
+ fmt .Sprintf (`{"fake.registry.io": {"auth": %q}, "fake.registry.io/more/specific": {"auth": %q}}` ,
127
+ base64 .StdEncoding .EncodeToString ([]byte (username + ":" + password )),
128
+ base64 .StdEncoding .EncodeToString ([]byte (specificUser + ":" + specificPass ))),
127
129
),
128
130
},
129
131
})
@@ -136,24 +138,41 @@ func TestImagePullSecrets(t *testing.T) {
136
138
t .Fatalf ("New() = %v" , err )
137
139
}
138
140
139
- reg , err := name .NewRegistry ("fake.registry.io" , name .WeakValidation )
141
+ repo , err := name .NewRepository ("fake.registry.io/more/specific " , name .WeakValidation )
140
142
if err != nil {
141
143
t .Errorf ("NewRegistry() = %v" , err )
142
144
}
143
145
144
- auth , err := kc .Resolve (reg )
145
- if err != nil {
146
- t .Errorf ("Resolve(%v) = %v" , reg , err )
147
- }
148
- got , err := auth .Authorization ()
149
- if err != nil {
150
- t .Errorf ("Authorization() = %v" , err )
151
- }
152
- want , err := (& authn.Basic {Username : username , Password : password }).Authorization ()
153
- if err != nil {
154
- t .Errorf ("Authorization() = %v" , err )
155
- }
156
- if got != want {
157
- t .Errorf ("Resolve() = %v, want %v" , got , want )
146
+ for _ , tc := range []struct {
147
+ name string
148
+ auth authn.Authenticator
149
+ target authn.Resource
150
+ }{{
151
+ name : "registry" ,
152
+ auth : & authn.Basic {Username : username , Password : password },
153
+ target : repo .Registry ,
154
+ }, {
155
+ name : "repo" ,
156
+ auth : & authn.Basic {Username : specificUser , Password : specificPass },
157
+ target : repo ,
158
+ }} {
159
+ t .Run (tc .name , func (t * testing.T ) {
160
+ tc := tc
161
+ auth , err := kc .Resolve (tc .target )
162
+ if err != nil {
163
+ t .Errorf ("Resolve(%v) = %v" , tc .target , err )
164
+ }
165
+ got , err := auth .Authorization ()
166
+ if err != nil {
167
+ t .Errorf ("Authorization() = %v" , err )
168
+ }
169
+ want , err := tc .auth .Authorization ()
170
+ if err != nil {
171
+ t .Errorf ("Authorization() = %v" , err )
172
+ }
173
+ if got != want {
174
+ t .Errorf ("Resolve() = %v, want %v" , got , want )
175
+ }
176
+ })
158
177
}
159
178
}
0 commit comments