github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/pkg/discovery/nodes/nodes_test.go (about) 1 package nodes // import "github.com/demonoid81/moby/pkg/discovery/nodes" 2 3 import ( 4 "testing" 5 6 "github.com/demonoid81/moby/internal/test/suite" 7 "github.com/demonoid81/moby/pkg/discovery" 8 "gotest.tools/v3/assert" 9 ) 10 11 // Hook up gocheck into the "go test" runner. 12 func Test(t *testing.T) { 13 suite.Run(t, &DiscoverySuite{}) 14 } 15 16 type DiscoverySuite struct{} 17 18 func (s *DiscoverySuite) TestInitialize(c *testing.T) { 19 d := &Discovery{} 20 d.Initialize("1.1.1.1:1111,2.2.2.2:2222", 0, 0, nil) 21 assert.Equal(c, len(d.entries), 2) 22 assert.Equal(c, d.entries[0].String(), "1.1.1.1:1111") 23 assert.Equal(c, d.entries[1].String(), "2.2.2.2:2222") 24 } 25 26 func (s *DiscoverySuite) TestInitializeWithPattern(c *testing.T) { 27 d := &Discovery{} 28 d.Initialize("1.1.1.[1:2]:1111,2.2.2.[2:4]:2222", 0, 0, nil) 29 assert.Equal(c, len(d.entries), 5) 30 assert.Equal(c, d.entries[0].String(), "1.1.1.1:1111") 31 assert.Equal(c, d.entries[1].String(), "1.1.1.2:1111") 32 assert.Equal(c, d.entries[2].String(), "2.2.2.2:2222") 33 assert.Equal(c, d.entries[3].String(), "2.2.2.3:2222") 34 assert.Equal(c, d.entries[4].String(), "2.2.2.4:2222") 35 } 36 37 func (s *DiscoverySuite) TestWatch(c *testing.T) { 38 d := &Discovery{} 39 d.Initialize("1.1.1.1:1111,2.2.2.2:2222", 0, 0, nil) 40 expected := discovery.Entries{ 41 &discovery.Entry{Host: "1.1.1.1", Port: "1111"}, 42 &discovery.Entry{Host: "2.2.2.2", Port: "2222"}, 43 } 44 ch, _ := d.Watch(nil) 45 assert.Equal(c, expected.Equals(<-ch), true) 46 } 47 48 func (s *DiscoverySuite) TestRegister(c *testing.T) { 49 d := &Discovery{} 50 assert.Assert(c, d.Register("0.0.0.0") != nil) 51 }