(f *testing.F)
| 325 | } |
| 326 | |
| 327 | func FuzzContentStore(f *testing.F) { |
| 328 | f.Fuzz(func(t *testing.T, data []byte) { |
| 329 | const ( |
| 330 | opInfo = "Info" |
| 331 | opUpdate = "Update" |
| 332 | opWalk = "Walk" |
| 333 | opDelete = "Delete" |
| 334 | opListStatuses = "ListStatuses" |
| 335 | opStatus = "Status" |
| 336 | opAbort = "Abort" |
| 337 | opCommit = "Commit" |
| 338 | ) |
| 339 | contentStoreOptions := []string{opInfo, opUpdate, opWalk, opDelete, opListStatuses, opStatus, opAbort, opCommit} |
| 340 | ctx, db, cancel, err := testDB(t) |
| 341 | defer cancel() |
| 342 | if err != nil { |
| 343 | return |
| 344 | } |
| 345 | |
| 346 | cs := db.ContentStore() |
| 347 | f := fuzz.NewConsumer(data) |
| 348 | noOfOperations, err := f.GetInt() |
| 349 | if err != nil { |
| 350 | return |
| 351 | } |
| 352 | maxOperations := 50 |
| 353 | for i := 0; i < noOfOperations%maxOperations; i++ { |
| 354 | opType, err := f.GetInt() |
| 355 | if err != nil { |
| 356 | return |
| 357 | } |
| 358 | switch contentStoreOptions[opType%len(contentStoreOptions)] { |
| 359 | case opInfo: |
| 360 | blob, err := f.GetBytes() |
| 361 | if err != nil { |
| 362 | return |
| 363 | } |
| 364 | dgst := digest.FromBytes(blob) |
| 365 | err = dgst.Validate() |
| 366 | if err != nil { |
| 367 | return |
| 368 | } |
| 369 | _, _ = cs.Info(ctx, dgst) |
| 370 | case opUpdate: |
| 371 | info := content.Info{} |
| 372 | err = f.GenerateStruct(&info) |
| 373 | if err != nil { |
| 374 | return |
| 375 | } |
| 376 | _, _ = cs.Update(ctx, info) |
| 377 | case opWalk: |
| 378 | walkFn := func(info content.Info) error { |
| 379 | return nil |
| 380 | } |
| 381 | _ = cs.Walk(ctx, walkFn) |
| 382 | case opDelete: |
| 383 | blob, err := f.GetBytes() |
| 384 | if err != nil { |
nothing calls this directly
no test coverage detected
searching dependent graphs…