Skip to content

Commit 7b14eae

Browse files
committed
test(client): replace hardcoded strings with constants in tests
1 parent 94cd6ed commit 7b14eae

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

client_messaging_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"github.com/stretchr/testify/require"
1010
)
1111

12+
const testData = "test data"
13+
1214
func TestClientSubscribeMultipleTopicsConcurrently(t *testing.T) {
1315
privKey, err := GeneratePrivateKey()
1416
require.NoError(t, err)
@@ -66,7 +68,7 @@ func TestClientPublishToUnsubscribedTopic(t *testing.T) {
6668
ctx := context.Background()
6769

6870
// Publish to a topic we haven't subscribed to
69-
err = cl.Publish(ctx, "new-topic", []byte("test data"))
71+
err = cl.Publish(ctx, "new-topic", []byte(testData))
7072
require.NoError(t, err)
7173
}
7274

@@ -274,14 +276,14 @@ func TestMessageStructFields(t *testing.T) {
274276
Topic: "test-topic",
275277
From: "test-peer",
276278
FromID: "12D3KooTest",
277-
Data: []byte("test data"),
279+
Data: []byte(testData),
278280
Timestamp: time.Now(),
279281
}
280282

281283
assert.Equal(t, "test-topic", msg.Topic)
282284
assert.Equal(t, "test-peer", msg.From)
283285
assert.Equal(t, "12D3KooTest", msg.FromID)
284-
assert.Equal(t, []byte("test data"), msg.Data)
286+
assert.Equal(t, []byte(testData), msg.Data)
285287
assert.False(t, msg.Timestamp.IsZero())
286288
}
287289

client_peers_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestClientGetPeersWithTopicPeers(t *testing.T) {
3232
assert.Empty(t, peers)
3333

3434
// Subscribe to a topic
35-
_ = client1.Subscribe("test-topic")
35+
_ = client1.Subscribe(testTopicName)
3636

3737
// Give subscription time to initialize
3838
time.Sleep(100 * time.Millisecond)
@@ -110,7 +110,7 @@ func TestClientSavePeerCacheEnabled(t *testing.T) {
110110
c := cl.(*client)
111111

112112
// Subscribe to a topic to initialize topics map
113-
_ = c.Subscribe("test-topic")
113+
_ = c.Subscribe(testTopicName)
114114
time.Sleep(100 * time.Millisecond)
115115

116116
// Call savePeerCache
@@ -143,7 +143,7 @@ func TestClientSavePeerCacheWithInvalidPath(t *testing.T) {
143143
c := cl.(*client)
144144

145145
// Subscribe to a topic
146-
_ = c.Subscribe("test-topic")
146+
_ = c.Subscribe(testTopicName)
147147
time.Sleep(50 * time.Millisecond)
148148

149149
// Should not panic even with invalid path
@@ -231,7 +231,7 @@ func TestClientSavePeerCacheMergesExistingData(t *testing.T) {
231231
c := cl.(*client)
232232

233233
// Subscribe to trigger topic creation
234-
_ = c.Subscribe("test-topic")
234+
_ = c.Subscribe(testTopicName)
235235
time.Sleep(50 * time.Millisecond)
236236

237237
// Save cache

client_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,9 @@ func TestBuildHostOptionsWithAnnounceAddrs(t *testing.T) {
603603
logger := &DefaultLogger{}
604604
// noop cancel function for testing - buildHostOptions requires a cancel function
605605
// but we don't need actual cancellation logic in this unit test
606-
cancel := func() {}
606+
cancel := func() {
607+
// Intentionally empty - this is a test fixture that satisfies the function signature
608+
}
607609

608610
tests := []struct {
609611
name string

0 commit comments

Comments
 (0)