MCPcopy Create free account
hub / github.com/containerd/nerdctl / TestFileStoreBasics

Function TestFileStoreBasics

pkg/store/filestore_test.go:28–107  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

26)
27
28func TestFileStoreBasics(t *testing.T) {
29 tempDir := t.TempDir()
30
31 // Creation
32 tempStore, err := New(tempDir, 0, 0)
33 assert.NilError(t, err, "temporary store creation should succeed")
34
35 // Lock acquisition
36 err = tempStore.Lock()
37 assert.NilError(t, err, "acquiring a lock should succeed")
38 err = tempStore.Release()
39 assert.NilError(t, err, "releasing a lock should succeed")
40
41 // Non-existent keys
42 _ = tempStore.Lock()
43 defer tempStore.Release()
44
45 _, err = tempStore.Get("nonexistent")
46 assert.ErrorIs(t, err, ErrNotFound, "getting a non existent key should ErrNotFound")
47
48 err = tempStore.Delete("nonexistent")
49 assert.ErrorIs(t, err, ErrNotFound, "deleting a non existent key should ErrNotFound")
50
51 _, err = tempStore.List("nonexistent")
52 assert.ErrorIs(t, err, ErrNotFound, "listing a non existent key should ErrNotFound")
53
54 doesExist, err := tempStore.Exists("nonexistent")
55 assert.NilError(t, err, "exist should not error")
56 assert.Assert(t, !doesExist, "should not exist")
57
58 // Listing empty store
59 result, err := tempStore.List()
60 assert.NilError(t, err, "listing store root should succeed")
61 assert.Assert(t, len(result) == 0, "list empty store return zero length slice")
62
63 // Invalid keys
64 _, err = tempStore.Get("..")
65 assert.ErrorIs(t, err, filesystem.ErrInvalidPath, "unsupported characters or patterns should return filesystem.ErrInvalidPath")
66
67 err = tempStore.Set([]byte("foo"), "..")
68 assert.ErrorIs(t, err, filesystem.ErrInvalidPath, "unsupported characters or patterns should return filesystem.ErrInvalidPath")
69
70 err = tempStore.Delete("..")
71 assert.ErrorIs(t, err, filesystem.ErrInvalidPath, "unsupported characters or patterns should return filesystem.ErrInvalidPath")
72
73 _, err = tempStore.List("..")
74 assert.ErrorIs(t, err, filesystem.ErrInvalidPath, "unsupported characters or patterns should return filesystem.ErrInvalidPath")
75
76 // Writing, reading, listing, deleting
77 err = tempStore.Set([]byte("foo"), "something")
78 assert.NilError(t, err, "write should be successful")
79
80 doesExist, err = tempStore.Exists("something")
81 assert.NilError(t, err, "exist should not error")
82 assert.Assert(t, doesExist, "should exist")
83
84 data, err := tempStore.Get("something")
85 assert.NilError(t, err, "read should be successful")

Callers

nothing calls this directly

Calls 10

AssertMethod · 0.80
NewFunction · 0.70
TempDirMethod · 0.65
LockMethod · 0.65
ReleaseMethod · 0.65
GetMethod · 0.65
DeleteMethod · 0.65
ListMethod · 0.65
ExistsMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…