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

Commit

Permalink
test: add unit test case for static_locator.go
Browse files Browse the repository at this point in the history
Signed-off-by: Guangwen Feng <[email protected]>
  • Loading branch information
Guangwen Feng committed Jun 9, 2020
1 parent 5981693 commit b23a54f
Showing 1 changed file with 39 additions and 0 deletions.
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

0 comments on commit b23a54f

Please sign in to comment.