MCPcopy
hub / github.com/containerd/containerd / newTestInitContext

Function newTestInitContext

plugins/transfer/plugin_test.go:130–171  ·  view source on GitHub ↗
(t *testing.T, snapshotters map[string]snapshots.Snapshotter, candidates []*plugin.Registration)

Source from the content-addressed store, hash-verified

128}
129
130func newTestInitContext(t *testing.T, snapshotters map[string]snapshots.Snapshotter, candidates []*plugin.Registration) (*metadata.DB, *plugin.InitContext) {
131 t.Helper()
132
133 cs, err := contentlocal.NewStore(t.TempDir())
134 if err != nil {
135 t.Fatal(err)
136 }
137
138 bdb, err := bolt.Open(filepath.Join(t.TempDir(), "metadata.db"), 0o644, nil)
139 if err != nil {
140 t.Fatal(err)
141 }
142 t.Cleanup(func() {
143 if err := bdb.Close(); err != nil {
144 t.Fatal(err)
145 }
146 })
147
148 db := metadata.NewDB(bdb, cs, snapshotters)
149 ps := plugin.NewPluginSet()
150 for name, sn := range snapshotters {
151 ic := plugin.NewContext(t.Context(), ps, nil)
152 p := (&plugin.Registration{
153 Type: plugins.SnapshotPlugin,
154 ID: name,
155 InitFn: func(*plugin.InitContext) (any, error) {
156 return sn, nil
157 },
158 }).Init(ic)
159 if err := ps.Add(p); err != nil {
160 t.Fatal(err)
161 }
162 }
163 for _, candidate := range candidates {
164 ic := plugin.NewContext(t.Context(), ps, nil)
165 if err := ps.Add(candidate.Init(ic)); err != nil {
166 t.Fatal(err)
167 }
168 }
169
170 return db, plugin.NewContext(t.Context(), ps, nil)
171}
172
173func newTestDiffPlugin(id string, applier diff.Applier, err error, supported ...ocispec.Platform) *plugin.Registration {
174 return &plugin.Registration{

Calls 8

NewDBFunction · 0.92
FatalMethod · 0.80
InitMethod · 0.80
CleanupMethod · 0.65
CloseMethod · 0.65
AddMethod · 0.65
OpenMethod · 0.45
ContextMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…