Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

test: add unit test case for static_locator.go #1374

Merged
merged 1 commit into from
Jun 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions dfget/locator/static_locator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,45 @@ func (s *StaticLocatorTestSuite) Test_Refresh(c *check.C) {
c.Assert(l.load(), check.Equals, -1)
}

func (s *StaticLocatorTestSuite) Test_String(c *check.C) {
cases := []struct {
locator *StaticLocator
isGroupNil bool
increments int
expected string
}{
{
locator: createLocator("a:80=1"),
isGroupNil: true,
increments: 0,
expected: "empty",
},
{
locator: createLocator("a:80=1"),
isGroupNil: false,
increments: 2,
expected: "empty",
},
{
locator: createLocator("a:80=1"),
isGroupNil: false,
increments: 0,
expected: "test-group:[a:80=1]",
},
}

for _, v := range cases {
if v.isGroupNil {
v.locator.Group = nil
}
for i := 0; i < v.increments; i++ {
v.locator.inc()
}

c.Assert(v.locator.String(), check.Equals, v.expected)
}
}

func create(ip string, port, weight int) *Supernode {
return &Supernode{
Schema: config.DefaultSupernodeSchema,
Expand Down