From 1eb68162603ad1859be481c27e67dbb23efcd7fa Mon Sep 17 00:00:00 2001 From: Prasad Ghangal Date: Fri, 5 Jul 2024 11:34:34 +0530 Subject: [PATCH] Refactor unit tests Signed-off-by: Prasad Ghangal --- internal/server/server_test.go | 4 +- repo/blob/storage_extend_test.go | 4 +- repo/format/upgrade_lock_test.go | 2 +- repo/maintenance/blob_gc_test.go | 2 +- repo/maintenance/blob_retain_test.go | 4 +- repo/maintenance/content_rewrite_test.go | 4 +- repo/maintenance/maintenance_safety_test.go | 4 +- repo/object/object_manager_test.go | 48 +++++++++---------- repo/repo_benchmarks_test.go | 6 +-- repo/repository_test.go | 14 +++--- .../snapshotmaintenance_test.go | 2 +- 11 files changed, 47 insertions(+), 47 deletions(-) diff --git a/internal/server/server_test.go b/internal/server/server_test.go index 706f60f9b53..ecdee16e903 100644 --- a/internal/server/server_test.go +++ b/internal/server/server_test.go @@ -216,7 +216,7 @@ func remoteRepositoryTest(ctx context.Context, t *testing.T, rep repo.Repository _, err := ow.Write([]byte{2, 3, 4}) require.NoError(t, err) - _, err = ow.Result() + _, err = ow.Result("zstd-fastest") if err == nil { return errors.Errorf("unexpected success writing object with 'm' prefix") } @@ -263,7 +263,7 @@ func mustWriteObject(ctx context.Context, t *testing.T, w repo.RepositoryWriter, _, err := ow.Write(data) require.NoError(t, err) - result, err := ow.Result() + result, err := ow.Result("zstd-fastest") require.NoError(t, err) return result diff --git a/repo/blob/storage_extend_test.go b/repo/blob/storage_extend_test.go index fad91143434..c33f450e62e 100644 --- a/repo/blob/storage_extend_test.go +++ b/repo/blob/storage_extend_test.go @@ -44,7 +44,7 @@ func (s *formatSpecificTestSuite) TestExtendBlobRetention(t *testing.T) { }) w := env.RepositoryWriter.NewObjectWriter(ctx, object.WriterOptions{}) io.WriteString(w, "hello world!") - w.Result() + w.Result("zstd-fastest") w.Close() env.RepositoryWriter.Flush(ctx) @@ -105,7 +105,7 @@ func (s *formatSpecificTestSuite) TestExtendBlobRetentionUnsupported(t *testing. }) w := env.RepositoryWriter.NewObjectWriter(ctx, object.WriterOptions{}) io.WriteString(w, "hello world!") - w.Result() + w.Result("zstd-fastest") w.Close() env.RepositoryWriter.Flush(ctx) diff --git a/repo/format/upgrade_lock_test.go b/repo/format/upgrade_lock_test.go index e1a7017862f..56aa31c95dc 100644 --- a/repo/format/upgrade_lock_test.go +++ b/repo/format/upgrade_lock_test.go @@ -406,6 +406,6 @@ func writeObject(ctx context.Context, t *testing.T, rep repo.RepositoryWriter, d _, err := w.Write(data) require.NoError(t, err, testCaseID) - _, err = w.Result() + _, err = w.Result("zstd-fastest") require.NoError(t, err, testCaseID) } diff --git a/repo/maintenance/blob_gc_test.go b/repo/maintenance/blob_gc_test.go index e5ba92d5bad..af7247ac51f 100644 --- a/repo/maintenance/blob_gc_test.go +++ b/repo/maintenance/blob_gc_test.go @@ -49,7 +49,7 @@ func (s *formatSpecificTestSuite) TestDeleteUnreferencedBlobs(t *testing.T) { }) w := env.RepositoryWriter.NewObjectWriter(ctx, object.WriterOptions{}) io.WriteString(w, "hello world!") - w.Result() + w.Result("zstd-fastest") w.Close() env.RepositoryWriter.Flush(ctx) diff --git a/repo/maintenance/blob_retain_test.go b/repo/maintenance/blob_retain_test.go index d4fe26b1346..7a7bf307fbf 100644 --- a/repo/maintenance/blob_retain_test.go +++ b/repo/maintenance/blob_retain_test.go @@ -45,7 +45,7 @@ func (s *formatSpecificTestSuite) TestExtendBlobRetentionTime(t *testing.T) { }) w := env.RepositoryWriter.NewObjectWriter(ctx, object.WriterOptions{}) io.WriteString(w, "hello world!") - w.Result() + w.Result("zstd-fastest") w.Close() env.RepositoryWriter.Flush(ctx) @@ -100,7 +100,7 @@ func (s *formatSpecificTestSuite) TestExtendBlobRetentionTimeDisabled(t *testing }) w := env.RepositoryWriter.NewObjectWriter(ctx, object.WriterOptions{}) io.WriteString(w, "hello world!") - w.Result() + w.Result("zstd-fastest") w.Close() env.RepositoryWriter.Flush(ctx) diff --git a/repo/maintenance/content_rewrite_test.go b/repo/maintenance/content_rewrite_test.go index 2079279bb3a..4e20de032fd 100644 --- a/repo/maintenance/content_rewrite_test.go +++ b/repo/maintenance/content_rewrite_test.go @@ -81,7 +81,7 @@ func (s *formatSpecificTestSuite) TestContentRewrite(t *testing.T) { require.NoError(t, repo.WriteSession(ctx, env.Repository, repo.WriteSessionOptions{}, func(ctx context.Context, w repo.RepositoryWriter) error { ow := w.NewObjectWriter(ctx, object.WriterOptions{}) fmt.Fprintf(ow, "%v", uuid.NewString()) - _, err := ow.Result() + _, err := ow.Result("zstd-fastest") return err })) } @@ -90,7 +90,7 @@ func (s *formatSpecificTestSuite) TestContentRewrite(t *testing.T) { require.NoError(t, repo.WriteSession(ctx, env.Repository, repo.WriteSessionOptions{}, func(ctx context.Context, w repo.RepositoryWriter) error { ow := w.NewObjectWriter(ctx, object.WriterOptions{Prefix: "k"}) fmt.Fprintf(ow, "%v", uuid.NewString()) - _, err := ow.Result() + _, err := ow.Result("zstd-fastest") return err })) } diff --git a/repo/maintenance/maintenance_safety_test.go b/repo/maintenance/maintenance_safety_test.go index 5a303240129..cc7ee98f008 100644 --- a/repo/maintenance/maintenance_safety_test.go +++ b/repo/maintenance/maintenance_safety_test.go @@ -37,7 +37,7 @@ func (s *formatSpecificTestSuite) TestMaintenanceSafety(t *testing.T) { ow := w.NewObjectWriter(ctx, object.WriterOptions{Prefix: "y"}) fmt.Fprintf(ow, "hello world") var err error - objectID, err = ow.Result() + objectID, err = ow.Result("zstd-fastest") return err })) @@ -45,7 +45,7 @@ func (s *formatSpecificTestSuite) TestMaintenanceSafety(t *testing.T) { require.NoError(t, repo.WriteSession(ctx, env.Repository, repo.WriteSessionOptions{}, func(ctx context.Context, w repo.RepositoryWriter) error { ow := w.NewObjectWriter(ctx, object.WriterOptions{Prefix: "y"}) fmt.Fprintf(ow, "hello universe") - _, err := ow.Result() + _, err := ow.Result("zstd-fastest") return err })) diff --git a/repo/object/object_manager_test.go b/repo/object/object_manager_test.go index 797c44957eb..320d0734c64 100644 --- a/repo/object/object_manager_test.go +++ b/repo/object/object_manager_test.go @@ -141,7 +141,7 @@ func TestWriters(t *testing.T) { t.Errorf("write error: %v", err) } - result, err := writer.Result() + result, err := writer.Result("zstd-fastest") if err != nil { t.Errorf("error getting writer results for %v, expected: %v", c.data, c.objectID.String()) continue @@ -178,7 +178,7 @@ func TestCompression_ContentCompressionEnabled(t *testing.T) { Compressor: "gzip", }) w.Write(bytes.Repeat([]byte{1, 2, 3, 4}, 1000)) - oid, err := w.Result() + oid, err := w.Result("zstd-fastest") require.NoError(t, err) cid, isCompressed, ok := oid.ContentID() @@ -219,7 +219,7 @@ func TestCompression_CustomSplitters(t *testing.T) { w := om.NewWriter(ctx, tc.wo) w.Write(bytes.Repeat([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 128<<10)) - oid, err := w.Result() + oid, err := w.Result("zstd-fastest") require.NoError(t, err) ndx, ok := oid.IndexObjectID() @@ -247,7 +247,7 @@ func TestCompression_ContentCompressionDisabled(t *testing.T) { Compressor: "gzip", }) w.Write(bytes.Repeat([]byte{1, 2, 3, 4}, 1000)) - oid, err := w.Result() + oid, err := w.Result("zstd-fastest") require.NoError(t, err) _, isCompressed, ok := oid.ContentID() @@ -263,7 +263,7 @@ func TestWriterCompleteChunkInTwoWrites(t *testing.T) { writer := om.NewWriter(ctx, WriterOptions{}) writer.Write(b[0:50]) writer.Write(b[0:50]) - result, err := writer.Result() + result, err := writer.Result("zstd-fastest") if !objectIDsEqual(result, mustParseID(t, "cd00e292c5970d3c5e2f0ffa5171e555bc46bfc4faddfb4a418b6840b86e79a3")) { t.Errorf("unexpected result: %v err: %v", result, err) @@ -280,25 +280,25 @@ func TestCheckpointing(t *testing.T) { allZeroes := make([]byte, 1<<20) // empty file, nothing flushed - checkpoint1, err := writer.Checkpoint() + checkpoint1, err := writer.Checkpoint("zstd-fastest") verifyNoError(t, err) // write some bytes, but not enough to flush. writer.Write(allZeroes[0:50]) - checkpoint2, err := writer.Checkpoint() + checkpoint2, err := writer.Checkpoint("zstd-fastest") verifyNoError(t, err) // write enough to flush first content. writer.Write(allZeroes) - checkpoint3, err := writer.Checkpoint() + checkpoint3, err := writer.Checkpoint("zstd-fastest") verifyNoError(t, err) // write enough to flush second content. writer.Write(allZeroes) - checkpoint4, err := writer.Checkpoint() + checkpoint4, err := writer.Checkpoint("zstd-fastest") verifyNoError(t, err) - result, err := writer.Result() + result, err := writer.Result("zstd-fastest") verifyNoError(t, err) if !objectIDsEqual(checkpoint1, EmptyID) { @@ -309,7 +309,7 @@ func TestCheckpointing(t *testing.T) { t.Errorf("unexpected checkpoint2: %v err: %v", checkpoint2, err) } - result2, err := writer.Checkpoint() + result2, err := writer.Checkpoint("zstd-fastest") verifyNoError(t, err) if result2 != result { @@ -354,13 +354,13 @@ func TestObjectWriterRaceBetweenCheckpointAndResult(t *testing.T) { var eg errgroup.Group eg.Go(func() error { - _, rerr := w.Result() + _, rerr := w.Result("zstd-fastest") return rerr }) eg.Go(func() error { - cpID, cperr := w.Checkpoint() + cpID, cperr := w.Checkpoint("zstd-fastest") if cperr == nil && cpID != EmptyID { ids, verr := VerifyObject(ctx, om.contentMgr, cpID) if verr != nil { @@ -467,7 +467,7 @@ func TestIndirection(t *testing.T) { t.Errorf("write error: %v", err) } - result, err := writer.Result() + result, err := writer.Result("zstd-fastest") if err != nil { t.Errorf("error getting writer results: %v", err) } @@ -512,7 +512,7 @@ func TestHMAC(t *testing.T) { w := om.NewWriter(ctx, WriterOptions{}) w.Write(c) - result, err := w.Result() + result, err := w.Result("zstd-fastest") if result.String() != "cad29ff89951a3c085c86cb7ed22b82b51f7bdfda24f932c7f9601f51d5975ba" { t.Errorf("unexpected result: %v err: %v", result.String(), err) @@ -578,7 +578,7 @@ func TestConcatenate(t *testing.T) { } for _, tc := range cases { - concatenatedOID, err := om.Concatenate(ctx, tc.inputs) + concatenatedOID, err := om.Concatenate(ctx, tc.inputs, "zstd-fastest") if err != nil { t.Fatal(err) } @@ -617,7 +617,7 @@ func TestConcatenate(t *testing.T) { } // make sure results of concatenation can be further concatenated. - concatenated3OID, err := om.Concatenate(ctx, []ID{concatenatedOID, concatenatedOID, concatenatedOID}) + concatenated3OID, err := om.Concatenate(ctx, []ID{concatenatedOID, concatenatedOID, concatenatedOID}, "zstd-fastest") if err != nil { t.Fatal(err) } @@ -645,7 +645,7 @@ func mustWriteObject(t *testing.T, om *Manager, data []byte, compressor compress _, err := w.Write(data) require.NoError(t, err) - oid, err := w.Result() + oid, err := w.Result("zstd-fastest") require.NoError(t, err) return oid @@ -728,7 +728,7 @@ func TestEndToEndReadAndSeek(t *testing.T) { t.Errorf("write error: %v", err) } - objectID, err := writer.Result() + objectID, err := writer.Result("zstd-fastest") t.Logf("oid: %v", objectID) writer.Close() @@ -784,7 +784,7 @@ func TestEndToEndReadAndSeekWithCompression(t *testing.T) { totalBytesWritten += size - objectID, err := writer.Result() + objectID, err := writer.Result("zstd-fastest") writer.Close() @@ -876,7 +876,7 @@ func TestSeek(t *testing.T) { t.Errorf("write error: %v", err) } - objectID, err := writer.Result() + objectID, err := writer.Result("zstd-fastest") if err != nil { t.Fatalf("unable to write: %v", err) } @@ -938,7 +938,7 @@ func TestWriterFlushFailure_OnFlush(t *testing.T) { fcm.writeContentError = errSomeError - _, err = w.Result() + _, err = w.Result("zstd-fastest") require.ErrorIs(t, err, errSomeError) } @@ -951,7 +951,7 @@ func TestWriterFlushFailure_OnCheckpoint(t *testing.T) { w.Write(bytes.Repeat([]byte{1, 2, 3, 4}, 1e6)) fcm.writeContentError = errSomeError - _, err := w.Checkpoint() + _, err := w.Checkpoint("zstd-fastest") require.ErrorIs(t, err, errSomeError) } @@ -970,7 +970,7 @@ func TestWriterFlushFailure_OnAsyncWrite(t *testing.T) { require.NotErrorIs(t, err, errSomeError) require.Equal(t, 4000000, n) - _, err = w.Result() + _, err = w.Result("zstd-fastest") require.ErrorIs(t, err, errSomeError) } diff --git a/repo/repo_benchmarks_test.go b/repo/repo_benchmarks_test.go index 13d0105d9d5..e444e62f351 100644 --- a/repo/repo_benchmarks_test.go +++ b/repo/repo_benchmarks_test.go @@ -17,7 +17,7 @@ func BenchmarkWriterDedup1M(b *testing.B) { writer := env.RepositoryWriter.NewObjectWriter(ctx, object.WriterOptions{}) writer.Write(dataBuf) - _, err := writer.Result() + _, err := writer.Result("zstd-fastest") require.NoError(b, err) writer.Close() @@ -27,7 +27,7 @@ func BenchmarkWriterDedup1M(b *testing.B) { // write exactly the same data writer := env.RepositoryWriter.NewObjectWriter(ctx, object.WriterOptions{}) writer.Write(dataBuf) - writer.Result() + writer.Result("zstd-fastest") writer.Close() } } @@ -54,7 +54,7 @@ func BenchmarkWriterNoDedup1M(b *testing.B) { } writer.Write(dataBuf[offset : offset+chunkSize]) - writer.Result() + writer.Result("zstd-fastest") writer.Close() offset++ diff --git a/repo/repository_test.go b/repo/repository_test.go index cf8b17cedd2..23393de1f69 100644 --- a/repo/repository_test.go +++ b/repo/repository_test.go @@ -52,7 +52,7 @@ func (s *formatSpecificTestSuite) TestWriters(t *testing.T) { t.Fatalf("write error: %v", err) } - result, err := writer.Result() + result, err := writer.Result("zstd-fastest") if err != nil { t.Errorf("error getting writer results for %v, expected: %v", c.data, c.objectID.String()) continue @@ -77,7 +77,7 @@ func (s *formatSpecificTestSuite) TestWriterCompleteChunkInTwoWrites(t *testing. writer := env.RepositoryWriter.NewObjectWriter(ctx, object.WriterOptions{}) writer.Write(b[0:50]) writer.Write(b[0:50]) - result, err := writer.Result() + result, err := writer.Result("zstd-fastest") if result != mustParseObjectID(t, "bfa2b4b9421671ab2b5bfa8c90ee33607784a27e452b08556509ef9bd47a37c6") { t.Errorf("unexpected result: %v err: %v", result, err) @@ -161,7 +161,7 @@ func (s *formatSpecificTestSuite) TestHMAC(t *testing.T) { w := env.RepositoryWriter.NewObjectWriter(ctx, object.WriterOptions{}) w.Write(c) - result, err := w.Result() + result, err := w.Result("zstd-fastest") if result.String() != "e37e93ba74e074ad1366ee2f032ee9c3a5b81ec82c140b053c1a4e6673d5d9d9" { t.Errorf("unexpected result: %v err: %v", result.String(), err) @@ -190,7 +190,7 @@ func writeObject(ctx context.Context, t *testing.T, rep repo.RepositoryWriter, d t.Fatalf("can't write object %q - write failed: %v", testCaseID, err) } - oid, err := w.Result() + oid, err := w.Result("zstd-fastest") if err != nil { t.Fatalf("can't write object %q - result failed: %v", testCaseID, err) } @@ -278,7 +278,7 @@ func TestFormats(t *testing.T) { w := env.RepositoryWriter.NewObjectWriter(ctx, object.WriterOptions{}) w.Write(bytesToWrite) - oid, err := w.Result() + oid, err := w.Result("zstd-fastest") if err != nil { t.Errorf("error: %v", err) } @@ -559,7 +559,7 @@ func TestObjectWritesWithRetention(t *testing.T) { _, err := writer.Write([]byte("the quick brown fox jumps over the lazy dog")) require.NoError(t, err) - _, err = writer.Result() + _, err = writer.Result("zstd-fastest") require.NoError(t, err) env.RepositoryWriter.ContentManager().Flush(ctx) @@ -780,7 +780,7 @@ func TestMetrics_CompressibleData(t *testing.T) { var err error - oid, err = w.Result() + oid, err = w.Result("zstd-fastest") require.NoError(t, err) count++ diff --git a/snapshot/snapshotmaintenance/snapshotmaintenance_test.go b/snapshot/snapshotmaintenance/snapshotmaintenance_test.go index bb787fb5888..dff3274dacc 100644 --- a/snapshot/snapshotmaintenance/snapshotmaintenance_test.go +++ b/snapshot/snapshotmaintenance/snapshotmaintenance_test.go @@ -388,7 +388,7 @@ func create4ByteObjects(t *testing.T, r repo.Repository, base, count int) []obje _, err := w.Write(b[:]) require.NoError(t, err) - oid, err := w.Result() + oid, err := w.Result("zstd-fastest") require.NoError(t, err) require.NoError(t, w.Close())