(t *testing.T)
| 468 | } |
| 469 | |
| 470 | func TestIndirection(t *testing.T) { |
| 471 | ctx := testlogging.Context(t) |
| 472 | |
| 473 | splitterFactory := splitter.Fixed(1000) |
| 474 | cases := []struct { |
| 475 | dataLength int |
| 476 | expectedBlobCount int |
| 477 | expectedIndirection int |
| 478 | metadataCompressor compression.Name |
| 479 | }{ |
| 480 | {dataLength: 200, expectedBlobCount: 1, expectedIndirection: 0}, |
| 481 | {dataLength: 1000, expectedBlobCount: 1, expectedIndirection: 0}, |
| 482 | {dataLength: 1001, expectedBlobCount: 3, expectedIndirection: 1}, |
| 483 | // 1 blob of 1000 zeros, 1 blob of 5 zeros + 1 index blob |
| 484 | {dataLength: 3005, expectedBlobCount: 3, expectedIndirection: 1}, |
| 485 | // 1 blob of 1000 zeros + 1 index blob |
| 486 | {dataLength: 4000, expectedBlobCount: 2, expectedIndirection: 1}, |
| 487 | // 1 blob of 1000 zeros + 1 index blob |
| 488 | {dataLength: 10000, expectedBlobCount: 2, expectedIndirection: 1, metadataCompressor: "none"}, |
| 489 | // 1 blob of 1000 zeros + 1 index blob, enabled metadata compression |
| 490 | {dataLength: 10000, expectedBlobCount: 2, expectedIndirection: 1, metadataCompressor: "zstd-fastest"}, |
| 491 | } |
| 492 | |
| 493 | for _, c := range cases { |
| 494 | cmap := map[content.ID]compression.HeaderID{} |
| 495 | data, _, om := setupTest(t, cmap) |
| 496 | |
| 497 | contentBytes := make([]byte, c.dataLength) |
| 498 | |
| 499 | writer := om.NewWriter(ctx, WriterOptions{MetadataCompressor: c.metadataCompressor}) |
| 500 | testutil.EnsureType[*objectWriter](t, writer).splitter = splitterFactory() |
| 501 | |
| 502 | if _, err := writer.Write(contentBytes); err != nil { |
| 503 | t.Errorf("write error: %v", err) |
| 504 | } |
| 505 | |
| 506 | result, err := writer.Result() |
| 507 | if err != nil { |
| 508 | t.Errorf("error getting writer results: %v", err) |
| 509 | } |
| 510 | |
| 511 | t.Logf("len %v got %v", len(contentBytes), result) |
| 512 | |
| 513 | if indirectionLevel(result) != c.expectedIndirection { |
| 514 | t.Errorf("incorrect indirection level for size: %v: %v, expected %v", c.dataLength, indirectionLevel(result), c.expectedIndirection) |
| 515 | } |
| 516 | |
| 517 | if got, want := len(data), c.expectedBlobCount; got != want { |
| 518 | t.Errorf("unexpected blob count for %v: %v, expected %v", c.dataLength, got, want) |
| 519 | } |
| 520 | |
| 521 | b, err := VerifyObject(ctx, om.contentMgr, result) |
| 522 | if err != nil { |
| 523 | t.Errorf("error verifying %q: %v", result, err) |
| 524 | } |
| 525 | |
| 526 | if got, want := len(b), c.expectedBlobCount; got != want { |
| 527 | t.Errorf("invalid blob count for %v, got %v, wanted %v", result, got, want) |
nothing calls this directly
no test coverage detected