2018-02-05 16:05:59 -05:00
|
|
|
package nodes // import "github.com/docker/docker/pkg/discovery/nodes"
|
2015-08-31 16:23:17 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-08-08 20:38:35 -04:00
|
|
|
"github.com/docker/docker/internal/test/suite"
|
2015-08-31 16:23:17 -04:00
|
|
|
"github.com/docker/docker/pkg/discovery"
|
2020-02-07 08:39:24 -05:00
|
|
|
"gotest.tools/v3/assert"
|
2015-08-31 16:23:17 -04:00
|
|
|
)
|
|
|
|
|
2015-10-01 20:02:38 -04:00
|
|
|
// Hook up gocheck into the "go test" runner.
|
2019-08-08 20:38:35 -04:00
|
|
|
func Test(t *testing.T) {
|
|
|
|
suite.Run(t, &DiscoverySuite{})
|
|
|
|
}
|
2015-10-01 20:02:38 -04:00
|
|
|
|
|
|
|
type DiscoverySuite struct{}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DiscoverySuite) TestInitialize(c *testing.T) {
|
2015-08-31 16:23:17 -04:00
|
|
|
d := &Discovery{}
|
2015-09-28 19:22:57 -04:00
|
|
|
d.Initialize("1.1.1.1:1111,2.2.2.2:2222", 0, 0, nil)
|
2019-09-09 17:05:56 -04:00
|
|
|
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")
|
2015-08-31 16:23:17 -04:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DiscoverySuite) TestInitializeWithPattern(c *testing.T) {
|
2015-08-31 16:23:17 -04:00
|
|
|
d := &Discovery{}
|
2015-09-28 19:22:57 -04:00
|
|
|
d.Initialize("1.1.1.[1:2]:1111,2.2.2.[2:4]:2222", 0, 0, nil)
|
2019-09-09 17:05:56 -04:00
|
|
|
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")
|
2015-08-31 16:23:17 -04:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DiscoverySuite) TestWatch(c *testing.T) {
|
2015-08-31 16:23:17 -04:00
|
|
|
d := &Discovery{}
|
2015-09-28 19:22:57 -04:00
|
|
|
d.Initialize("1.1.1.1:1111,2.2.2.2:2222", 0, 0, nil)
|
2015-08-31 16:23:17 -04:00
|
|
|
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)
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, expected.Equals(<-ch), true)
|
2015-08-31 16:23:17 -04:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DiscoverySuite) TestRegister(c *testing.T) {
|
2015-08-31 16:23:17 -04:00
|
|
|
d := &Discovery{}
|
2019-09-09 17:05:57 -04:00
|
|
|
assert.Assert(c, d.Register("0.0.0.0") != nil)
|
2015-08-31 16:23:17 -04:00
|
|
|
}
|