Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/pkg/cluster/cluster_test.go
4093 views
1
package cluster
2
3
import (
4
"testing"
5
6
"github.com/rfratto/ckit/peer"
7
"github.com/rfratto/ckit/shard"
8
"github.com/stretchr/testify/require"
9
)
10
11
func TestLocalNode_Lookup(t *testing.T) {
12
t.Run("replicationFactor 0 returns nothing", func(t *testing.T) {
13
ln := NewLocalNode("localhost:8888")
14
res, err := ln.Lookup(0, 0, shard.OpReadWrite)
15
require.NoError(t, err)
16
require.Len(t, res, 0)
17
})
18
19
t.Run("replicationFactor 1 returns self", func(t *testing.T) {
20
ln := NewLocalNode("localhost:8888")
21
res, err := ln.Lookup(0, 1, shard.OpReadWrite)
22
23
require.NoError(t, err)
24
25
expect := []peer.Peer{{
26
Name: "local",
27
Addr: "localhost:8888",
28
Self: true,
29
State: peer.StateParticipant,
30
}}
31
require.Equal(t, expect, res)
32
})
33
34
t.Run("replicationFactor >1 returns error", func(t *testing.T) {
35
ln := NewLocalNode("localhost:8888")
36
res, err := ln.Lookup(0, 2, shard.OpReadWrite)
37
require.EqualError(t, err, "need 2 nodes; only 1 available")
38
require.Nil(t, res)
39
})
40
}
41
42
func TestLocalNode_Peers(t *testing.T) {
43
t.Run("always returns self", func(t *testing.T) {
44
ln := NewLocalNode("localhost:8888")
45
46
expect := []peer.Peer{{
47
Name: "local",
48
Addr: "localhost:8888",
49
Self: true,
50
State: peer.StateParticipant,
51
}}
52
require.Equal(t, expect, ln.Peers())
53
})
54
}
55
56