1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/pkg/discovery/nodes/nodes_test.go
2020-02-11 00:06:42 +01:00

51 lines
1.5 KiB
Go

package nodes // import "github.com/docker/docker/pkg/discovery/nodes"
import (
"testing"
"github.com/docker/docker/internal/test/suite"
"github.com/docker/docker/pkg/discovery"
"gotest.tools/v3/assert"
)
// Hook up gocheck into the "go test" runner.
func Test(t *testing.T) {
suite.Run(t, &DiscoverySuite{})
}
type DiscoverySuite struct{}
func (s *DiscoverySuite) TestInitialize(c *testing.T) {
d := &Discovery{}
d.Initialize("1.1.1.1:1111,2.2.2.2:2222", 0, 0, nil)
assert.Equal(c, len(d.entries), 2)
assert.Equal(c, d.entries[0].String(), "1.1.1.1:1111")
assert.Equal(c, d.entries[1].String(), "2.2.2.2:2222")
}
func (s *DiscoverySuite) TestInitializeWithPattern(c *testing.T) {
d := &Discovery{}
d.Initialize("1.1.1.[1:2]:1111,2.2.2.[2:4]:2222", 0, 0, nil)
assert.Equal(c, len(d.entries), 5)
assert.Equal(c, d.entries[0].String(), "1.1.1.1:1111")
assert.Equal(c, d.entries[1].String(), "1.1.1.2:1111")
assert.Equal(c, d.entries[2].String(), "2.2.2.2:2222")
assert.Equal(c, d.entries[3].String(), "2.2.2.3:2222")
assert.Equal(c, d.entries[4].String(), "2.2.2.4:2222")
}
func (s *DiscoverySuite) TestWatch(c *testing.T) {
d := &Discovery{}
d.Initialize("1.1.1.1:1111,2.2.2.2:2222", 0, 0, nil)
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)
assert.Equal(c, expected.Equals(<-ch), true)
}
func (s *DiscoverySuite) TestRegister(c *testing.T) {
d := &Discovery{}
assert.Assert(c, d.Register("0.0.0.0") != nil)
}