MCPcopy
hub / github.com/containerd/containerd / FuzzContainerStore

Function FuzzContainerStore

contrib/fuzz/metadata_fuzz_test.go:203–269  ·  view source on GitHub ↗
(f *testing.F)

Source from the content-addressed store, hash-verified

201}
202
203func FuzzContainerStore(f *testing.F) {
204 f.Fuzz(func(t *testing.T, data []byte) {
205 const (
206 opCreate = "Create"
207 opList = "List"
208 opDelete = "Delete"
209 opUpdate = "Update"
210 opGet = "Get"
211 )
212 containerStoreOptions := []string{opCreate, opList, opDelete, opUpdate, opGet}
213 ctx, db, cancel, err := testEnv(t)
214 if err != nil {
215 return
216 }
217 defer cancel()
218
219 store := metadata.NewContainerStore(metadata.NewDB(db, nil, nil))
220 c := containers.Container{}
221 f := fuzz.NewConsumer(data)
222 noOfOperations, err := f.GetInt()
223 if err != nil {
224 return
225 }
226 maxOperations := 50
227 for i := 0; i < noOfOperations%maxOperations; i++ {
228 opType, err := f.GetInt()
229 if err != nil {
230 return
231 }
232 switch containerStoreOptions[opType%len(containerStoreOptions)] {
233 case opCreate:
234 err := f.GenerateStruct(&c)
235 if err != nil {
236 return
237 }
238 db.Update(func(tx *bolt.Tx) error {
239 _, _ = store.Create(boltutil.WithTransaction(ctx, tx), c)
240 return nil
241 })
242 case opList:
243 filt, err := f.GetString()
244 if err != nil {
245 return
246 }
247 _, _ = store.List(ctx, filt)
248 case opDelete:
249 id, err := f.GetString()
250 if err != nil {
251 return
252 }
253 _ = store.Delete(ctx, id)
254 case opUpdate:
255 fieldpaths, err := f.GetString()
256 if err != nil {
257 return
258 }
259 _, _ = store.Update(ctx, c, fieldpaths)
260 case opGet:

Callers

nothing calls this directly

Calls 9

NewContainerStoreFunction · 0.92
NewDBFunction · 0.92
WithTransactionFunction · 0.92
testEnvFunction · 0.70
UpdateMethod · 0.65
CreateMethod · 0.65
ListMethod · 0.65
DeleteMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…