github.com/brahmaroutu/docker@v1.2.1-0.20160809185609-eb28dde01f16/pkg/discovery/nodes/nodes_test.go (about) 1 package nodes 2 3 import ( 4 "testing" 5 6 "github.com/docker/docker/pkg/discovery" 7 8 "github.com/go-check/check" 9 ) 10 11 // Hook up gocheck into the "go test" runner. 12 func Test(t *testing.T) { check.TestingT(t) } 13 14 type DiscoverySuite struct{} 15 16 var _ = check.Suite(&DiscoverySuite{}) 17 18 func (s *DiscoverySuite) TestInitialize(c *check.C) { 19 d := &Discovery{} 20 d.Initialize("1.1.1.1:1111,2.2.2.2:2222", 0, 0, nil) 21 c.Assert(len(d.entries), check.Equals, 2) 22 c.Assert(d.entries[0].String(), check.Equals, "1.1.1.1:1111") 23 c.Assert(d.entries[1].String(), check.Equals, "2.2.2.2:2222") 24 } 25 26 func (s *DiscoverySuite) TestInitializeWithPattern(c *check.C) { 27 d := &Discovery{} 28 d.Initialize("1.1.1.[1:2]:1111,2.2.2.[2:4]:2222", 0, 0, nil) 29 c.Assert(len(d.entries), check.Equals, 5) 30 c.Assert(d.entries[0].String(), check.Equals, "1.1.1.1:1111") 31 c.Assert(d.entries[1].String(), check.Equals, "1.1.1.2:1111") 32 c.Assert(d.entries[2].String(), check.Equals, "2.2.2.2:2222") 33 c.Assert(d.entries[3].String(), check.Equals, "2.2.2.3:2222") 34 c.Assert(d.entries[4].String(), check.Equals, "2.2.2.4:2222") 35 } 36 37 func (s *DiscoverySuite) TestWatch(c *check.C) { 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 c.Assert(expected.Equals(<-ch), check.Equals, true) 46 } 47 48 func (s *DiscoverySuite) TestRegister(c *check.C) { 49 d := &Discovery{} 50 c.Assert(d.Register("0.0.0.0"), check.NotNil) 51 }