From 8058fd379fc6b4a43f2b7003b36668c926632750 Mon Sep 17 00:00:00 2001 From: Devan Date: Mon, 16 Dec 2024 12:33:06 -0600 Subject: [PATCH] feat: rewrite tests to use testify --- tsdb/engine/tsm1/compact_test.go | 57 +++++++++----------------------- 1 file changed, 16 insertions(+), 41 deletions(-) diff --git a/tsdb/engine/tsm1/compact_test.go b/tsdb/engine/tsm1/compact_test.go index c6ee65716cc..a24d1405b8e 100644 --- a/tsdb/engine/tsm1/compact_test.go +++ b/tsdb/engine/tsm1/compact_test.go @@ -12,6 +12,7 @@ import ( "github.com/influxdata/influxdb/tsdb" "github.com/influxdata/influxdb/tsdb/engine/tsm1" + "github.com/stretchr/testify/require" "go.uber.org/zap" ) @@ -2329,15 +2330,9 @@ func TestDefaultPlanner_PlanOptimize_LargeMultiGeneration(t *testing.T) { } tsm, pLen, _ := cp.PlanOptimize() - if exp, got := 1, len(tsm); exp != got { - t.Fatalf("group length mismatch: got %v, exp %v", got, exp) - } else if pLen != int64(len(tsm)) { - t.Fatalf("tsm file plan length mismatch: got %v, exp %v", pLen, exp) - } - - if exp, got := len(expFiles), len(tsm[0]); got != exp { - t.Fatalf("tsm file length mismatch: got %v, exp %v", got, exp) - } + require.Equal(t, 1, len(tsm), "group length mismatch: got %d, exp %d", len(tsm), 1) + require.Equal(t, int64(len(tsm)), pLen, "tsm file plan length mismatch: got %d, exp %d", pLen, int64(len(tsm))) + require.Equal(t, len(expFiles), len(tsm[0]), "tsm file length mismatch: got %d, exp %d", len(tsm[0]), len(expFiles)) } // This test is added to account for a single generation that has a group size @@ -2378,17 +2373,10 @@ func TestDefaultPlanner_PlanOptimize_SmallSingleGeneration(t *testing.T) { } tsm, pLen, gLen := cp.PlanOptimize() - if exp, got := 1, len(tsm); exp != got { - t.Fatalf("group length mismatch: got %v, exp %v", got, exp) - } else if pLen != int64(len(tsm)) { - t.Fatalf("tsm file plan length mismatch: got %v, exp %v", pLen, exp) - } else if gLen != int64(1) { - t.Fatalf("generation length mismatch: got %v, exp %v", gLen, 1) - } - - if exp, got := len(expFiles), len(tsm[0]); got != exp { - t.Fatalf("tsm file length mismatch: got %v, exp %v", got, exp) - } + require.Equal(t, 1, len(tsm), "group length mismatch: got %d, exp %d", len(tsm), 1) + require.Equal(t, int64(len(tsm)), pLen, "tsm file plan length mismatch: got %d, exp %d", pLen, int64(len(expFiles))) + require.Equal(t, int64(1), gLen, "generation length mismatch: got %d, exp %d", gLen, 1) + require.Equal(t, len(expFiles), len(tsm[0]), "tsm file length mismatch: got %d, exp %d", len(tsm[0]), expFiles) } // This test is added to account for a single generation that has a group size @@ -2426,17 +2414,10 @@ func TestDefaultPlanner_PlanOptimize_SmallSingleGenerationUnderLevel4(t *testing } tsm, pLen, gLen := cp.PlanOptimize() - if exp, got := 1, len(tsm); exp != got { - t.Fatalf("group length mismatch: got %v, exp %v", got, exp) - } else if pLen != int64(len(tsm)) { - t.Fatalf("tsm file plan length mismatch: got %v, exp %v", pLen, exp) - } else if gLen != int64(1) { - t.Fatalf("generation length mismatch: got %v, exp %v", gLen, 1) - } - - if exp, got := len(expFiles), len(tsm[0]); got != exp { - t.Fatalf("tsm file length mismatch: got %v, exp %v", got, exp) - } + require.Equal(t, 1, len(tsm), "group length mismatch: got %d, exp %d", len(tsm), 1) + require.Equal(t, int64(len(tsm)), pLen, "tsm file plan length mismatch: got %d, exp %d", pLen, int64(len(expFiles))) + require.Equal(t, int64(1), gLen, "generation length mismatch: got %d, exp %d", gLen, 1) + require.Equal(t, len(expFiles), len(tsm[0]), "tsm file length mismatch: got %d, exp %d", len(tsm[0]), expFiles) } // This test is added to account for a single generation that has a group size @@ -2474,11 +2455,8 @@ func TestDefaultPlanner_FullyCompacted_SmallSingleGeneration(t *testing.T) { compacted, reason := cp.FullyCompacted() reasonExp := "not fully compacted and not idle because group size under 2 GB and more then single file" - if exp, got := false, compacted; exp != got { - t.Fatalf("group length mismatch: got %v, exp %v", got, exp) - } else if reason != reasonExp { - t.Fatalf("tsm file plan length mismatch: got %v, exp %v", reason, reasonExp) - } + require.Equal(t, reason, reasonExp) + require.Equal(t, false, compacted) } // This test is added to account for halting state after @@ -2504,11 +2482,8 @@ func TestDefaultPlanner_FullyCompacted_SmallSingleGeneration_Halt(t *testing.T) compacted, reason := cp.FullyCompacted() reasonExp := "" - if exp, got := true, compacted; exp != got { - t.Fatalf("group length mismatch: got %v, exp %v", got, exp) - } else if reason != reasonExp { - t.Fatalf("tsm file plan length mismatch: got %v, exp %v", reason, reasonExp) - } + require.Equal(t, reason, reasonExp) + require.Equal(t, true, compacted) } func TestDefaultPlanner_PlanOptimize_Multiple(t *testing.T) {