MCPcopy
hub / github.com/containerd/containerd / testDB

Function testDB

core/metadata/db_test.go:69–111  ·  view source on GitHub ↗
(t *testing.T, opt ...testOpt)

Source from the content-addressed store, hash-verified

67}
68
69func testDB(t *testing.T, opt ...testOpt) (context.Context, *DB) {
70 ctx := t.Context()
71 ctx = namespaces.WithNamespace(ctx, "testing")
72 ctx = logtest.WithT(ctx, t)
73
74 var topts testOptions
75
76 for _, o := range opt {
77 o(&topts)
78 }
79
80 dirname := t.TempDir()
81
82 snapshotter, err := native.NewSnapshotter(filepath.Join(dirname, "native"))
83 require.NoError(t, err)
84
85 snapshotters := map[string]snapshots.Snapshotter{
86 "native": snapshotter,
87 }
88
89 for name, fn := range topts.extraSnapshots {
90 snapshotter, err := fn(filepath.Join(dirname, name))
91 if err != nil {
92 t.Fatal(err)
93 }
94 snapshotters[name] = snapshotter
95 }
96
97 cs, err := local.NewStore(filepath.Join(dirname, "content"))
98 require.NoError(t, err)
99
100 bdb, err := bolt.Open(filepath.Join(dirname, "metadata.db"), 0644, nil)
101 require.NoError(t, err)
102
103 db := NewDB(bdb, cs, snapshotters)
104 require.NoError(t, db.Init(ctx))
105
106 t.Cleanup(func() {
107 assert.NoError(t, db.Close())
108 })
109
110 return ctx, db
111}
112
113func TestInit(t *testing.T) {
114 ctx, db := testEnv(t)

Callers 11

TestCreateDeleteFunction · 0.70
TestSandboxCreateFunction · 0.70
TestSandboxCreateDupFunction · 0.70
TestSandboxUpdateFunction · 0.70
TestSandboxGetInvalidFunction · 0.70
TestSandboxListFunction · 0.70
TestSandboxDeleteFunction · 0.70
TestSnapshotterWithRefFunction · 0.70
TestContentLeasedFunction · 0.70
TestIngestLeasedFunction · 0.70

Calls 10

InitMethod · 0.95
CloseMethod · 0.95
WithNamespaceFunction · 0.92
NewSnapshotterFunction · 0.92
NewStoreFunction · 0.92
NewDBFunction · 0.85
FatalMethod · 0.80
CleanupMethod · 0.65
ContextMethod · 0.45
OpenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…