Skip to content

Commit 3c53779

Browse files
authored
Merge pull request #4535 from yankay/fix-namestore
Fix: namestore directory regression - restore 'names' subdirectory in path
2 parents 8bc867e + 65c395c commit 3c53779

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

pkg/namestore/namestore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func New(stateDir, namespace string) (NameStore, error) {
4040
return nil, errors.Join(ErrNameStore, store.ErrInvalidArgument)
4141
}
4242

43-
st, err := store.New(filepath.Join(stateDir, namespace), 0, 0)
43+
st, err := store.New(filepath.Join(stateDir, "names", namespace), 0, 0)
4444
if err != nil {
4545
return nil, errors.Join(ErrNameStore, err)
4646
}

pkg/namestore/namestore_test.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package namestore
18+
19+
import (
20+
"os"
21+
"path/filepath"
22+
"testing"
23+
24+
"gotest.tools/v3/assert"
25+
26+
"github.com/containerd/nerdctl/v2/pkg/store"
27+
)
28+
29+
func TestNamestoreNew(t *testing.T) {
30+
tempDir := t.TempDir()
31+
32+
tests := []struct {
33+
name string
34+
namespace string
35+
wantErr bool
36+
errChecks []error
37+
}{
38+
{
39+
name: "empty namespace",
40+
namespace: "",
41+
wantErr: true,
42+
errChecks: []error{ErrNameStore, store.ErrInvalidArgument},
43+
},
44+
{
45+
name: "valid namespace",
46+
namespace: "testnamespace",
47+
wantErr: false,
48+
},
49+
}
50+
51+
for _, tt := range tests {
52+
t.Run(tt.name, func(t *testing.T) {
53+
ns, err := New(tempDir, tt.namespace)
54+
if tt.wantErr {
55+
assert.Assert(t, err != nil, "New should return an error for %s", tt.name)
56+
for _, errCheck := range tt.errChecks {
57+
assert.ErrorIs(t, err, errCheck, "Error should contain %v for %s", errCheck, tt.name)
58+
}
59+
} else {
60+
assert.NilError(t, err, "New should succeed for %s", tt.name)
61+
assert.Assert(t, ns != nil, "New should return a non-nil NameStore for %s", tt.name)
62+
63+
// Check that the directory is created in the correct path
64+
expectedDir := filepath.Join(tempDir, "names", tt.namespace)
65+
_, err = os.Stat(expectedDir)
66+
assert.NilError(t, err, "Directory should be created at the correct path for %s", tt.name)
67+
}
68+
})
69+
}
70+
}

0 commit comments

Comments
 (0)