2015-08-31 20:23:17 +00:00
|
|
|
package nodes
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/docker/pkg/discovery"
|
2015-10-02 00:02:38 +00:00
|
|
|
|
|
|
|
"github.com/go-check/check"
|
2015-08-31 20:23:17 +00:00
|
|
|
)
|
|
|
|
|
2015-10-02 00:02:38 +00:00
|
|
|
// Hook up gocheck into the "go test" runner.
|
|
|
|
func Test(t *testing.T) { check.TestingT(t) }
|
|
|
|
|
|
|
|
type DiscoverySuite struct{}
|
|
|
|
|
|
|
|
var _ = check.Suite(&DiscoverySuite{})
|
|
|
|
|
|
|
|
func (s *DiscoverySuite) TestInitialize(c *check.C) {
|
2015-08-31 20:23:17 +00:00
|
|
|
d := &Discovery{}
|
|
|
|
d.Initialize("1.1.1.1:1111,2.2.2.2:2222", 0, 0)
|
2015-10-02 00:02:38 +00:00
|
|
|
c.Assert(len(d.entries), check.Equals, 2)
|
|
|
|
c.Assert(d.entries[0].String(), check.Equals, "1.1.1.1:1111")
|
|
|
|
c.Assert(d.entries[1].String(), check.Equals, "2.2.2.2:2222")
|
2015-08-31 20:23:17 +00:00
|
|
|
}
|
|
|
|
|
2015-10-02 00:02:38 +00:00
|
|
|
func (s *DiscoverySuite) TestInitializeWithPattern(c *check.C) {
|
2015-08-31 20:23:17 +00:00
|
|
|
d := &Discovery{}
|
|
|
|
d.Initialize("1.1.1.[1:2]:1111,2.2.2.[2:4]:2222", 0, 0)
|
2015-10-02 00:02:38 +00:00
|
|
|
c.Assert(len(d.entries), check.Equals, 5)
|
|
|
|
c.Assert(d.entries[0].String(), check.Equals, "1.1.1.1:1111")
|
|
|
|
c.Assert(d.entries[1].String(), check.Equals, "1.1.1.2:1111")
|
|
|
|
c.Assert(d.entries[2].String(), check.Equals, "2.2.2.2:2222")
|
|
|
|
c.Assert(d.entries[3].String(), check.Equals, "2.2.2.3:2222")
|
|
|
|
c.Assert(d.entries[4].String(), check.Equals, "2.2.2.4:2222")
|
2015-08-31 20:23:17 +00:00
|
|
|
}
|
|
|
|
|
2015-10-02 00:02:38 +00:00
|
|
|
func (s *DiscoverySuite) TestWatch(c *check.C) {
|
2015-08-31 20:23:17 +00:00
|
|
|
d := &Discovery{}
|
|
|
|
d.Initialize("1.1.1.1:1111,2.2.2.2:2222", 0, 0)
|
|
|
|
expected := discovery.Entries{
|
|
|
|
&discovery.Entry{Host: "1.1.1.1", Port: "1111"},
|
|
|
|
&discovery.Entry{Host: "2.2.2.2", Port: "2222"},
|
|
|
|
}
|
|
|
|
ch, _ := d.Watch(nil)
|
2015-10-02 00:02:38 +00:00
|
|
|
c.Assert(expected.Equals(<-ch), check.Equals, true)
|
2015-08-31 20:23:17 +00:00
|
|
|
}
|
|
|
|
|
2015-10-02 00:02:38 +00:00
|
|
|
func (s *DiscoverySuite) TestRegister(c *check.C) {
|
2015-08-31 20:23:17 +00:00
|
|
|
d := &Discovery{}
|
2015-10-02 00:02:38 +00:00
|
|
|
c.Assert(d.Register("0.0.0.0"), check.NotNil)
|
2015-08-31 20:23:17 +00:00
|
|
|
}
|