Skip to content

Commit

Permalink
Fix test to workaround docker credstore symlink fault
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
apostasie committed Sep 10, 2024
1 parent 53d898d commit 2cd63cc
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/imgutil/dockerconfigresolver/credentialsstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ func TestBrokenCredentialsStore(t *testing.T) {
},
}

t.Run("Broken Docker Config testing", func(t *testing.T) {
t.Run("Docker Config testing with a variety of filesystem situations", func(t *testing.T) {
// Do NOT parallelize this test, as it relies on Chdir, which would have side effects for other tests.
registryURL, err := Parse("registry")
if err != nil {
t.Fatal(err)
Expand All @@ -177,6 +178,16 @@ func TestBrokenCredentialsStore(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
directory := tc.setup()
// See https://github.com/containerd/nerdctl/issues/3413
oldpwd, err := os.Getwd()
assert.NilError(t, err)
// Ignore the error, as the destination may not be a directory
_ = os.Chdir(directory)
t.Cleanup(func() {
err = os.Chdir(oldpwd)
assert.NilError(t, err)
})

cs, err := NewCredentialsStore(directory)
assert.ErrorIs(t, err, tc.errorNew)
if err != nil {
Expand All @@ -189,6 +200,7 @@ func TestBrokenCredentialsStore(t *testing.T) {

err = cs.Store(registryURL, af)
assert.ErrorIs(t, err, tc.errorWrite)

})
}
})
Expand Down

0 comments on commit 2cd63cc

Please sign in to comment.