MCPcopy
hub / github.com/grafana/tempo / TestDropTraceCmd

Function TestDropTraceCmd

cmd/tempo-cli/cmd-rewrite-blocks_test.go:27–62  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25)
26
27func TestDropTraceCmd(t *testing.T) {
28 testCase := func(t *testing.T, blocksNum int, tracesNum int, deleteEvery int) {
29 cmd := dropTracesCmd{
30 backendOptions: backendOptions{
31 Backend: "local",
32 Bucket: t.TempDir(),
33 },
34 TenantID: "single-tenant",
35 DropTrace: true,
36 }
37 generateTestBlocks(t, cmd.Bucket, cmd.TenantID, blocksNum, tracesNum)
38
39 before := getAllTraceIDs(t, cmd.Bucket, cmd.TenantID)
40
41 var expectedAfter, toRemove []string
42 for i, traceID := range before {
43 if i%deleteEvery == 0 {
44 toRemove = append(toRemove, traceID)
45 } else {
46 expectedAfter = append(expectedAfter, traceID)
47 }
48 }
49 cmd.TraceIDs = strings.Join(toRemove, ",")
50
51 err := cmd.Run(&globalOptions{})
52 require.NoError(t, err)
53
54 after := getAllTraceIDs(t, cmd.Bucket, cmd.TenantID)
55
56 require.ElementsMatch(t, after, expectedAfter)
57 }
58
59 testCase(t, 1, 10, 3)
60 testCase(t, 2, 5, 3)
61 testCase(t, 2, 5, 1)
62}
63
64func generateTestBlocks(t *testing.T, tempDir string, tenantID string, blockCount int, traceCount int) {
65 t.Helper()

Callers

nothing calls this directly

Calls 5

RunMethod · 0.95
generateTestBlocksFunction · 0.85
getAllTraceIDsFunction · 0.85
JoinMethod · 0.65
testCaseStruct · 0.50

Tested by

no test coverage detected