func (s *networkSuite) TestFirewallSpec(c *gc.C) { ports := network.NewPortSet( network.MustParsePortRange("80-81/tcp"), network.MustParsePortRange("8888/tcp"), network.MustParsePortRange("1234/udp"), ) fw := google.FirewallSpec("spam", ports) allowed := []*compute.FirewallAllowed{{ IPProtocol: "tcp", Ports: []string{"80", "81", "8888"}, }, { IPProtocol: "udp", Ports: []string{"1234"}, }} sort.Sort(ByIPProtocol(fw.Allowed)) for i := range fw.Allowed { sort.Strings(fw.Allowed[i].Ports) } c.Check(fw, jc.DeepEquals, &compute.Firewall{ Name: "spam", TargetTags: []string{"spam"}, SourceRanges: []string{"0.0.0.0/0"}, Allowed: allowed, }) }
func (*PortRangeSuite) TestMustParsePortRangeInvalid(c *gc.C) { f := func() { network.MustParsePortRange("10-55-100") } c.Check(f, gc.PanicMatches, `invalid port range "10-55-100".*`) }
func (*PortRangeSuite) TestMustParsePortRange(c *gc.C) { portRange := network.MustParsePortRange("8000-8099/tcp") c.Check(portRange.Protocol, gc.Equals, "tcp") c.Check(portRange.FromPort, gc.Equals, 8000) c.Check(portRange.ToPort, gc.Equals, 8099) }