| 1 | package cloudapi_test |
| 2 | |
| 3 | import ( |
| 4 | "github.com/joyent/gosdc/cloudapi" |
| 5 | gc "launchpad.net/gocheck" |
| 6 | ) |
| 7 | |
| 8 | func (s *LocalTests) createFabricVLAN(c *gc.C) (vlan *cloudapi.FabricVLAN, cleanup func()) { |
| 9 | vlan, err := s.testClient.CreateFabricVLAN(cloudapi.FabricVLAN{ |
| 10 | Name: "test VLAN", |
| 11 | Description: "VLAN for test purposes", |
| 12 | }) |
| 13 | c.Assert(err, gc.IsNil) |
| 14 | |
| 15 | return vlan, func() { |
| 16 | err := s.testClient.DeleteFabricVLAN(vlan.Id) |
| 17 | c.Assert(err, gc.IsNil) |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | func (s *LocalTests) createFabricNetwork(c *gc.C) (vlan *cloudapi.FabricVLAN, network *cloudapi.FabricNetwork, cleanup func()) { |
| 22 | vlan, vlanCleanup := s.createFabricVLAN(c) |
| 23 | network, err := s.testClient.CreateFabricNetwork(vlan.Id, cloudapi.CreateFabricNetworkOpts{ |
| 24 | Name: "test network", |
| 25 | Subnet: "10.0.0.0/16", |
| 26 | ProvisionStartIp: "10.0.0.0", |
| 27 | ProvisionEndIp: "10.0.255.255", |
| 28 | InternetNAT: true, |
| 29 | }) |
| 30 | c.Assert(err, gc.IsNil) |
| 31 | |
| 32 | return vlan, network, func() { |
| 33 | err := s.testClient.DeleteFabricNetwork(vlan.Id, network.Id) |
| 34 | c.Assert(err, gc.IsNil) |
| 35 | |
| 36 | vlanCleanup() |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | func (s *LocalTests) TestCreateFabricVLAN(c *gc.C) { |
| 41 | vlan, cleanup := s.createFabricVLAN(c) |
| 42 | defer cleanup() |
| 43 | |
| 44 | c.Assert(vlan.Id, gc.Not(gc.Equals), 0) |
| 45 | } |
| 46 | |
| 47 | func (s *LocalTests) TestListFabricVLANs(c *gc.C) { |
| 48 | vlan, cleanup := s.createFabricVLAN(c) |
| 49 | defer cleanup() |
| 50 | |
| 51 | vlans, err := s.testClient.ListFabricVLANs() |
| 52 | c.Assert(err, gc.IsNil) |
| 53 | c.Assert(vlans, gc.HasLen, 1) |
| 54 | c.Assert(vlans[0].Id, gc.Equals, vlan.Id) |
| 55 | } |
| 56 | |
| 57 | func (s *LocalTests) TestGetFabricVLAN(c *gc.C) { |
| 58 | vlan, cleanup := s.createFabricVLAN(c) |
| 59 | defer cleanup() |
| 60 | |
| 61 | vlan2, err := s.testClient.GetFabricVLAN(vlan.Id) |
| 62 | c.Assert(err, gc.IsNil) |
| 63 | |
| 64 | c.Assert(vlan.Id, gc.Equals, vlan2.Id) |
| 65 | c.Assert(vlan.Name, gc.Equals, vlan2.Name) |
| 66 | c.Assert(vlan.Description, gc.Equals, vlan2.Description) |
| 67 | } |
| 68 | |
| 69 | func (s *LocalTests) TestUpdateFabricVLAN(c *gc.C) { |
| 70 | vlan, cleanup := s.createFabricVLAN(c) |
| 71 | defer cleanup() |
| 72 | |
| 73 | vlan.Description = "test change" |
| 74 | updated, err := s.testClient.UpdateFabricVLAN(*vlan) |
| 75 | c.Assert(err, gc.IsNil) |
| 76 | c.Assert(updated.Description, gc.Equals, vlan.Description) |
| 77 | } |
| 78 | |
| 79 | func (s *LocalTests) TestDeleteFabricVLAN(c *gc.C) { |
| 80 | vlan, _ := s.createFabricVLAN(c) |
| 81 | |
| 82 | err := s.testClient.DeleteFabricVLAN(vlan.Id) |
| 83 | c.Assert(err, gc.IsNil) |
| 84 | |
| 85 | _, err = s.testClient.GetFabricVLAN(vlan.Id) |
| 86 | c.Assert(err, gc.Not(gc.IsNil)) |
| 87 | } |
| 88 | |
| 89 | func (s *LocalTests) TestCreateFabricNetwork(c *gc.C) { |
| 90 | vlan, network, cleanup := s.createFabricNetwork(c) |
| 91 | defer cleanup() |
| 92 | |
| 93 | c.Assert(network.Id, gc.Not(gc.Equals), "") |
| 94 | c.Assert(vlan.Id, gc.Equals, network.VLANId) |
| 95 | } |
| 96 | |
| 97 | func (s *LocalTests) TestListFabricNetworks(c *gc.C) { |
| 98 | vlan, network, cleanup := s.createFabricNetwork(c) |
| 99 | defer cleanup() |
| 100 | |
| 101 | networks, err := s.testClient.ListFabricNetworks(vlan.Id) |
| 102 | c.Assert(err, gc.IsNil) |
| 103 | c.Assert(networks, gc.HasLen, 1) |
| 104 | c.Assert(networks[0].Id, gc.Equals, network.Id) |
| 105 | } |
| 106 | |
| 107 | func (s *LocalTests) TestGetFabricNetwork(c *gc.C) { |
| 108 | vlan, network, cleanup := s.createFabricNetwork(c) |
| 109 | defer cleanup() |
| 110 | |
| 111 | network2, err := s.testClient.GetFabricNetwork(vlan.Id, network.Id) |
| 112 | c.Assert(err, gc.IsNil) |
| 113 | c.Assert(network2.Id, gc.Equals, network.Id) |
| 114 | } |
| 115 | |
| 116 | func (s *LocalTests) TestDeleteFabricNetwork(c *gc.C) { |
| 117 | vlan, cleanup := s.createFabricVLAN(c) |
| 118 | defer cleanup() |
| 119 | |
| 120 | network, err := s.testClient.CreateFabricNetwork(vlan.Id, cloudapi.CreateFabricNetworkOpts{ |
| 121 | Name: "test network", |
| 122 | Subnet: "10.0.0.0/16", |
| 123 | ProvisionStartIp: "10.0.0.0", |
| 124 | ProvisionEndIp: "10.0.255.255", |
| 125 | InternetNAT: true, |
| 126 | }) |
| 127 | c.Assert(err, gc.IsNil) |
| 128 | |
| 129 | err = s.testClient.DeleteFabricNetwork(vlan.Id, network.Id) |
| 130 | c.Assert(err, gc.IsNil) |
| 131 | |
| 132 | _, err = s.testClient.GetFabricNetwork(vlan.Id, network.Id) |
| 133 | c.Assert(err, gc.Not(gc.IsNil)) |
| 134 | } |