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

Function TestFixtures

pkg/drain/testdata/update-fixtures/fixtures_test.go:14–61  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestFixtures(t *testing.T) {
15 files, err := os.ReadDir("..")
16 if err != nil {
17 t.Fatalf("failed to read testdata directory: %v", err)
18 }
19
20 for _, file := range files {
21 if file.IsDir() {
22 continue
23 }
24 if !strings.HasSuffix(file.Name(), ".json") {
25 continue
26 }
27
28 t.Run(file.Name(), func(t *testing.T) {
29 linesJSON, err := os.ReadFile(filepath.Join("..", file.Name()))
30 if err != nil {
31 t.Fatalf("failed to read file: %v", err)
32 }
33 var lines []string
34 err = json.Unmarshal(linesJSON, &lines)
35 if err != nil {
36 t.Fatalf("failed to unmarshal file: %v", err)
37 }
38 drain := drain.New("test-tenant", drain.DefaultConfig())
39 patternMapping := make(map[string]string)
40 for _, line := range lines {
41 cluster := drain.Train(line)
42 if cluster == nil {
43 patternMapping[line] = "<nil> (possibly too many tokens)"
44 } else {
45 patternMapping[line] = cluster.String()
46 }
47 }
48
49 expectedBytes, err := os.ReadFile(filepath.Join("..", strings.TrimSuffix(file.Name(), ".json")+".drain"))
50 if err != nil {
51 t.Fatalf("failed to read file: %v", err)
52 }
53 var expected TestData
54 err = json.Unmarshal(expectedBytes, &expected)
55 if err != nil {
56 t.Fatalf("failed to unmarshal file: %v", err)
57 }
58 require.Equal(t, expected.PatternMapping, patternMapping)
59 })
60 }
61}

Callers

nothing calls this directly

Calls 9

NewFunction · 0.92
DefaultConfigFunction · 0.92
TrainMethod · 0.80
NameMethod · 0.65
JoinMethod · 0.65
UnmarshalMethod · 0.65
RunMethod · 0.45
StringMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected