MCPcopy Index your code
hub / github.com/redpanda-data/console / TestTopicsSetWithLogDirs

Function TestTopicsSetWithLogDirs

backend/pkg/console/log_dir_topic_test.go:30–100  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

28)
29
30func TestTopicsSetWithLogDirs(t *testing.T) {
31 t.Run("lookup on empty set", func(t *testing.T) {
32 topicsSet := topicsSetWithLogDirs{}
33 info, exists := topicsSet.Lookup("test", 0)
34 assert.Empty(t, info)
35 assert.False(t, exists)
36 })
37
38 t.Run("set on empty set", func(t *testing.T) {
39 topicsSet := topicsSetWithLogDirs{}
40 info := partitionInfo{
41 PartitionID: 0,
42 Replicas: []int32{0, 1, 2},
43 Leader: 0,
44 }
45 topicsSet.Set("test", info)
46 partition, exists := topicsSet.Lookup("test", 0)
47 assert.True(t, exists)
48 require.NotNil(t, partition)
49 assert.Equal(t, info, partition)
50 })
51
52 t.Run("update set", func(t *testing.T) {
53 // 1. Set partition
54 topic := "test"
55 topicsSet := topicsSetWithLogDirs{}
56 info := partitionInfo{
57 PartitionID: 0,
58 Replicas: []int32{0, 1, 2},
59 Leader: 0,
60 }
61 topicsSet.Set(topic, info)
62
63 // 2. Retrieve partition and change leader
64 info, exists := topicsSet.Lookup("test", 0)
65 require.True(t, exists)
66 require.NotNil(t, info)
67
68 // 3. Set updated info
69 info.Leader = 1
70 topicsSet.Set(topic, info)
71
72 // 4. Retrieve updated partition and ensure the leader is updated
73 info, exists = topicsSet.Lookup(topic, 0)
74 require.True(t, exists)
75 require.NotNil(t, info)
76 assert.Equal(t, int32(1), info.Leader)
77 })
78
79 t.Run("each partition", func(t *testing.T) {
80 topic := "test"
81 info := partitionInfo{
82 PartitionID: 0,
83 Replicas: []int32{0, 1, 2},
84 Leader: 0,
85 }
86
87 topicsSet := topicsSetWithLogDirs{}

Callers

nothing calls this directly

Calls 3

LookupMethod · 0.95
SetMethod · 0.95
EachPartitionMethod · 0.95

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…