2018-02-05 16:05:59 -05:00
|
|
|
package discovery // import "github.com/docker/docker/pkg/discovery"
|
2015-08-31 16:23:17 -04:00
|
|
|
import (
|
2019-09-09 17:06:12 -04:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"gotest.tools/assert"
|
2015-08-31 16:23:17 -04:00
|
|
|
)
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DiscoverySuite) TestGeneratorNotGenerate(c *testing.T) {
|
2015-08-31 16:23:17 -04:00
|
|
|
ips := Generate("127.0.0.1")
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, len(ips), 1)
|
|
|
|
assert.Equal(c, ips[0], "127.0.0.1")
|
2015-08-31 16:23:17 -04:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DiscoverySuite) TestGeneratorWithPortNotGenerate(c *testing.T) {
|
2015-08-31 16:23:17 -04:00
|
|
|
ips := Generate("127.0.0.1:8080")
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, len(ips), 1)
|
|
|
|
assert.Equal(c, ips[0], "127.0.0.1:8080")
|
2015-08-31 16:23:17 -04:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DiscoverySuite) TestGeneratorMatchFailedNotGenerate(c *testing.T) {
|
2015-08-31 16:23:17 -04:00
|
|
|
ips := Generate("127.0.0.[1]")
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, len(ips), 1)
|
|
|
|
assert.Equal(c, ips[0], "127.0.0.[1]")
|
2015-08-31 16:23:17 -04:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DiscoverySuite) TestGeneratorWithPort(c *testing.T) {
|
2015-08-31 16:23:17 -04:00
|
|
|
ips := Generate("127.0.0.[1:11]:2375")
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, len(ips), 11)
|
|
|
|
assert.Equal(c, ips[0], "127.0.0.1:2375")
|
|
|
|
assert.Equal(c, ips[1], "127.0.0.2:2375")
|
|
|
|
assert.Equal(c, ips[2], "127.0.0.3:2375")
|
|
|
|
assert.Equal(c, ips[3], "127.0.0.4:2375")
|
|
|
|
assert.Equal(c, ips[4], "127.0.0.5:2375")
|
|
|
|
assert.Equal(c, ips[5], "127.0.0.6:2375")
|
|
|
|
assert.Equal(c, ips[6], "127.0.0.7:2375")
|
|
|
|
assert.Equal(c, ips[7], "127.0.0.8:2375")
|
|
|
|
assert.Equal(c, ips[8], "127.0.0.9:2375")
|
|
|
|
assert.Equal(c, ips[9], "127.0.0.10:2375")
|
|
|
|
assert.Equal(c, ips[10], "127.0.0.11:2375")
|
2015-08-31 16:23:17 -04:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DiscoverySuite) TestGenerateWithMalformedInputAtRangeStart(c *testing.T) {
|
2015-08-31 16:23:17 -04:00
|
|
|
malformedInput := "127.0.0.[x:11]:2375"
|
|
|
|
ips := Generate(malformedInput)
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, len(ips), 1)
|
|
|
|
assert.Equal(c, ips[0], malformedInput)
|
2015-08-31 16:23:17 -04:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DiscoverySuite) TestGenerateWithMalformedInputAtRangeEnd(c *testing.T) {
|
2015-08-31 16:23:17 -04:00
|
|
|
malformedInput := "127.0.0.[1:x]:2375"
|
|
|
|
ips := Generate(malformedInput)
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, len(ips), 1)
|
|
|
|
assert.Equal(c, ips[0], malformedInput)
|
2015-08-31 16:23:17 -04:00
|
|
|
}
|