Skip to content

Commit b2174cb

Browse files
committed
Fix test to workaround docker credstore symlink fault
As described in containerd#3413 there seems to be a fault in docker credentials store that makes relative symlinks resolve to pwd instead of where they are. This in turn will break our test if the current working directory is read-only (typical with Lima). This changeset does Chdir to the parent temp directory so we can workaround that problem. Signed-off-by: apostasie <[email protected]>
1 parent 53d898d commit b2174cb

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)