github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/provider/joyent/environ_firewall_test.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 package joyent_test 4 5 import ( 6 "github.com/joyent/gosdc/cloudapi" 7 gc "gopkg.in/check.v1" 8 9 "github.com/juju/juju/network" 10 "github.com/juju/juju/provider/joyent" 11 ) 12 13 type FirewallSuite struct{} 14 15 var _ = gc.Suite(&FirewallSuite{}) 16 17 func (s *FirewallSuite) TestGetPorts(c *gc.C) { 18 testCases := []struct { 19 about string 20 envName string 21 rules []cloudapi.FirewallRule 22 expected []network.PortRange 23 }{ 24 { 25 "single port model rule", 26 "switch", 27 []cloudapi.FirewallRule{{ 28 "", 29 true, 30 "FROM tag switch TO tag juju ALLOW tcp PORT 80", 31 }}, 32 []network.PortRange{{ 33 FromPort: 80, 34 ToPort: 80, 35 Protocol: "tcp", 36 }}, 37 }, 38 { 39 "port range model rule", 40 "switch", 41 []cloudapi.FirewallRule{{ 42 "", 43 true, 44 "FROM tag switch TO tag juju ALLOW tcp (PORT 80 AND PORT 81 AND PORT 82 AND PORT 83)", 45 }}, 46 []network.PortRange{{ 47 FromPort: 80, 48 ToPort: 83, 49 Protocol: "tcp", 50 }}, 51 }, 52 } 53 for i, t := range testCases { 54 c.Logf("test %d: %s", i, t.about) 55 c.Assert(joyent.GetPorts(t.envName, t.rules), gc.DeepEquals, t.expected) 56 } 57 58 } 59 60 func (s *FirewallSuite) TestRuleCreation(c *gc.C) { 61 testCases := []struct { 62 about string 63 ports network.PortRange 64 expected string 65 }{{ 66 "single port firewall rule", 67 network.PortRange{80, 80, "tcp"}, 68 "FROM tag switch TO tag juju ALLOW tcp PORT 80", 69 }, { 70 "multiple port firewall rule", 71 network.PortRange{80, 81, "tcp"}, 72 "FROM tag switch TO tag juju ALLOW tcp ( PORT 80 AND PORT 81 )", 73 }} 74 75 for i, t := range testCases { 76 c.Logf("test case %d: %s", i, t.about) 77 rule := joyent.CreateFirewallRuleAll("switch", t.ports) 78 c.Check(rule, gc.Equals, t.expected) 79 } 80 }