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

Function TestWriter

tempodb/backend/raw_test.go:25–95  ·  view source on GitHub ↗

todo: add tests that check the appropriate keypath is passed

(t *testing.T)

Source from the content-addressed store, hash-verified

23
24// todo: add tests that check the appropriate keypath is passed
25func TestWriter(t *testing.T) {
26 m := &MockRawWriter{}
27 w := NewWriter(m)
28 ctx := context.Background()
29
30 expected := []byte{0x01, 0x02, 0x03, 0x04}
31
32 u := uuid.New()
33 err := w.Write(ctx, "test", u, "test", expected, nil)
34 assert.NoError(t, err)
35 assert.Equal(t, expected, m.writeBuffer["test/"+u.String()+"/test"])
36
37 _, err = w.Append(ctx, "test", uuid.New(), "test", nil, expected)
38 assert.NoError(t, err)
39 assert.Equal(t, expected, m.appendBuffer)
40
41 err = w.CloseAppend(ctx, nil)
42 assert.NoError(t, err)
43 assert.True(t, m.closeAppendCalled)
44
45 u = uuid.New()
46 expectedPath := filepath.Join("test", u.String(), MetaName)
47 meta := NewBlockMeta("test", u, "blerg")
48 jsonBytes, err := json.Marshal(meta)
49 assert.NoError(t, err)
50 assert.NoError(t, err)
51
52 // Write the block meta to the backend and validate the payloads.
53 err = w.WriteBlockMeta(ctx, meta)
54 assert.NoError(t, err)
55 assert.Equal(t, jsonBytes, m.writeBuffer[expectedPath])
56
57 tenantIndexPath := filepath.Join("test", TenantIndexName)
58 tenantIndexPathPb := filepath.Join("test", TenantIndexNamePb)
59 // Write the tenant index to the backend and validate the payloads.
60 err = w.WriteTenantIndex(ctx, "test", []*BlockMeta{meta}, nil)
61 assert.NoError(t, err)
62
63 // proto
64 idxP := &TenantIndex{}
65 err = idxP.unmarshalPb(m.writeBuffer[tenantIndexPathPb])
66 assert.NoError(t, err)
67
68 assert.Equal(t, []*BlockMeta{meta}, idxP.Meta)
69 assert.True(t, cmp.Equal([]*BlockMeta{meta}, idxP.Meta)) // using cmp.Equal to compare json datetimes
70 assert.True(t, cmp.Equal([]*CompactedBlockMeta(nil), idxP.CompactedMeta)) // using cmp.Equal to compare json datetimes
71
72 // json
73 idxJ := &TenantIndex{}
74 err = idxJ.unmarshal(m.writeBuffer[tenantIndexPath])
75 assert.NoError(t, err)
76
77 assert.Equal(t, []*BlockMeta{meta}, idxJ.Meta)
78 assert.True(t, cmp.Equal([]*BlockMeta{meta}, idxJ.Meta)) // using cmp.Equal to compare json datetimes
79 assert.True(t, cmp.Equal([]*CompactedBlockMeta(nil), idxJ.CompactedMeta)) // using cmp.Equal to compare json datetimes
80
81 // When there are no blocks, the tenant index should be deleted
82 assert.Equal(t, map[string]map[string]int(nil), w.(*writer).w.(*MockRawWriter).deleteCalls)

Callers

nothing calls this directly

Calls 13

WriteMethod · 0.95
AppendMethod · 0.95
CloseAppendMethod · 0.95
WriteBlockMetaMethod · 0.95
WriteTenantIndexMethod · 0.95
unmarshalPbMethod · 0.95
unmarshalMethod · 0.95
NewWriterFunction · 0.85
NewBlockMetaFunction · 0.85
JoinMethod · 0.65
MarshalMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected