mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
9f0b3f5609
full diff: https://github.com/gotestyourself/gotest.tools/compare/v2.3.0...v3.0.1 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
51 lines
1.5 KiB
Go
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)
|
|
}
|