github.com/brahmaroutu/docker@v1.2.1-0.20160809185609-eb28dde01f16/pkg/discovery/generator_test.go (about)

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