github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/pkg/discovery/generator_test.go (about) 1 package discovery // import "github.com/demonoid81/moby/pkg/discovery" 2 import ( 3 "testing" 4 5 "gotest.tools/v3/assert" 6 ) 7 8 func (s *DiscoverySuite) TestGeneratorNotGenerate(c *testing.T) { 9 ips := Generate("127.0.0.1") 10 assert.Equal(c, len(ips), 1) 11 assert.Equal(c, ips[0], "127.0.0.1") 12 } 13 14 func (s *DiscoverySuite) TestGeneratorWithPortNotGenerate(c *testing.T) { 15 ips := Generate("127.0.0.1:8080") 16 assert.Equal(c, len(ips), 1) 17 assert.Equal(c, ips[0], "127.0.0.1:8080") 18 } 19 20 func (s *DiscoverySuite) TestGeneratorMatchFailedNotGenerate(c *testing.T) { 21 ips := Generate("127.0.0.[1]") 22 assert.Equal(c, len(ips), 1) 23 assert.Equal(c, ips[0], "127.0.0.[1]") 24 } 25 26 func (s *DiscoverySuite) TestGeneratorWithPort(c *testing.T) { 27 ips := Generate("127.0.0.[1:11]:2375") 28 assert.Equal(c, len(ips), 11) 29 assert.Equal(c, ips[0], "127.0.0.1:2375") 30 assert.Equal(c, ips[1], "127.0.0.2:2375") 31 assert.Equal(c, ips[2], "127.0.0.3:2375") 32 assert.Equal(c, ips[3], "127.0.0.4:2375") 33 assert.Equal(c, ips[4], "127.0.0.5:2375") 34 assert.Equal(c, ips[5], "127.0.0.6:2375") 35 assert.Equal(c, ips[6], "127.0.0.7:2375") 36 assert.Equal(c, ips[7], "127.0.0.8:2375") 37 assert.Equal(c, ips[8], "127.0.0.9:2375") 38 assert.Equal(c, ips[9], "127.0.0.10:2375") 39 assert.Equal(c, ips[10], "127.0.0.11:2375") 40 } 41 42 func (s *DiscoverySuite) TestGenerateWithMalformedInputAtRangeStart(c *testing.T) { 43 malformedInput := "127.0.0.[x:11]:2375" 44 ips := Generate(malformedInput) 45 assert.Equal(c, len(ips), 1) 46 assert.Equal(c, ips[0], malformedInput) 47 } 48 49 func (s *DiscoverySuite) TestGenerateWithMalformedInputAtRangeEnd(c *testing.T) { 50 malformedInput := "127.0.0.[1:x]:2375" 51 ips := Generate(malformedInput) 52 assert.Equal(c, len(ips), 1) 53 assert.Equal(c, ips[0], malformedInput) 54 }