MCPcopy
hub / github.com/containerd/containerd / TestCreateDelete

Function TestCreateDelete

core/metadata/namespaces_test.go:31–96  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

29)
30
31func TestCreateDelete(t *testing.T) {
32 ctx, db := testDB(t)
33
34 subtests := []struct {
35 name string
36 create func(t *testing.T, ctx context.Context)
37 validate func(t *testing.T, err error)
38 }{
39 {
40 name: "empty",
41 create: func(t *testing.T, ctx context.Context) {},
42 validate: func(t *testing.T, err error) {
43 require.NoError(t, err)
44 },
45 },
46 {
47 name: "not-empty",
48 create: func(t *testing.T, ctx context.Context) {
49 store := NewContainerStore(db)
50 _, err := store.Create(ctx, containers.Container{
51 ID: "c1",
52 Runtime: containers.RuntimeInfo{Name: "rt"},
53 Spec: &types.Any{},
54 })
55 require.NoError(t, err)
56
57 db.Update(func(tx *bbolt.Tx) error {
58 ns, err := namespaces.NamespaceRequired(ctx)
59 if err != nil {
60 return err
61 }
62 bucket, err := createSnapshotterBucket(tx, ns, "testss")
63 if err != nil {
64 return err
65 }
66 return bucket.Put([]byte("key"), []byte("value"))
67 })
68 },
69 validate: func(t *testing.T, err error) {
70 require.Error(t, err)
71 assert.Contains(t, err.Error(), `still has containers, snapshots on "testss" snapshotter`)
72 },
73 },
74 }
75
76 for _, subtest := range subtests {
77 ns := subtest.name
78 ctx = namespaces.WithNamespace(ctx, ns)
79
80 t.Run(subtest.name, func(t *testing.T) {
81 err := db.Update(func(tx *bbolt.Tx) error {
82 store := NewNamespaceStore(tx)
83 return store.Create(ctx, ns, nil)
84 })
85 require.NoError(t, err)
86
87 subtest.create(t, ctx)
88

Callers

nothing calls this directly

Calls 14

NamespaceRequiredFunction · 0.92
WithNamespaceFunction · 0.92
NewContainerStoreFunction · 0.85
createSnapshotterBucketFunction · 0.85
NewNamespaceStoreFunction · 0.85
PutMethod · 0.80
createMethod · 0.80
validateMethod · 0.80
testDBFunction · 0.70
CreateMethod · 0.65
UpdateMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…