Skip to content

Commit 1bdcebb

Browse files
authored
Merge pull request containerd#3414 from apostasie/bugfix-3413-docker-misbehave
Fix test to workaround docker credstore symlink fault
2 parents 2a388a7 + b2174cb commit 1bdcebb

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

pkg/imgutil/dockerconfigresolver/credentialsstore_test.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,27 +168,41 @@ func TestBrokenCredentialsStore(t *testing.T) {
168168
},
169169
}
170170

171-
t.Run("Broken Docker Config testing", func(t *testing.T) {
171+
t.Run("Docker Config testing with a variety of filesystem situations", func(t *testing.T) {
172+
// Do NOT parallelize this test, as it relies on Chdir, which would have side effects for other tests.
172173
registryURL, err := Parse("registry")
173174
if err != nil {
174175
t.Fatal(err)
175176
}
176177

177-
for _, tc := range testCases {
178-
t.Run(tc.description, func(t *testing.T) {
178+
for _, testCase := range testCases {
179+
tc := testCase
180+
t.Run(tc.description, func(tt *testing.T) {
181+
// See https://github.com/containerd/nerdctl/issues/3413
182+
var oldpwd string
179183
directory := tc.setup()
180-
cs, err := NewCredentialsStore(directory)
181-
assert.ErrorIs(t, err, tc.errorNew)
184+
oldpwd, err = os.Getwd()
185+
assert.NilError(tt, err)
186+
// Ignore the error, as the destination may not be a directory
187+
_ = os.Chdir(directory)
188+
tt.Cleanup(func() {
189+
err = os.Chdir(oldpwd)
190+
assert.NilError(tt, err)
191+
})
192+
193+
var cs *CredentialsStore
194+
cs, err = NewCredentialsStore(directory)
195+
assert.ErrorIs(tt, err, tc.errorNew)
182196
if err != nil {
183197
return
184198
}
185199

186200
var af *Credentials
187201
af, err = cs.Retrieve(registryURL, true)
188-
assert.ErrorIs(t, err, tc.errorRead)
202+
assert.ErrorIs(tt, err, tc.errorRead)
189203

190204
err = cs.Store(registryURL, af)
191-
assert.ErrorIs(t, err, tc.errorWrite)
205+
assert.ErrorIs(tt, err, tc.errorWrite)
192206
})
193207
}
194208
})

0 commit comments

Comments
 (0)