Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1374 from fenggw-fnst/work
Browse files Browse the repository at this point in the history
test: add unit test case for static_locator.go
  • Loading branch information
zhouhaibing089 authored Jun 9, 2020
2 parents 2f07b25 + b23a54f commit 862a6a7
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 862a6a7

Please sign in to comment.