Jon Perritt | 26ff5b7 | 2014-10-23 11:54:39 -0500 | [diff] [blame] | 1 | // +build acceptance rackspace |
Jon Perritt | 857b312 | 2014-10-22 18:17:44 -0500 | [diff] [blame] | 2 | |
| 3 | package v2 |
| 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/rackspace/gophercloud/pagination" |
Jon Perritt | 26ff5b7 | 2014-10-23 11:54:39 -0500 | [diff] [blame] | 9 | "github.com/rackspace/gophercloud/rackspace/compute/v2/networks" |
Jon Perritt | 857b312 | 2014-10-22 18:17:44 -0500 | [diff] [blame] | 10 | th "github.com/rackspace/gophercloud/testhelper" |
| 11 | ) |
| 12 | |
| 13 | func TestNetworks(t *testing.T) { |
Jon Perritt | 26ff5b7 | 2014-10-23 11:54:39 -0500 | [diff] [blame] | 14 | client, err := newClient() |
| 15 | th.AssertNoErr(t, err) |
Jon Perritt | 857b312 | 2014-10-22 18:17:44 -0500 | [diff] [blame] | 16 | |
| 17 | // Create a network |
Jon Perritt | 26ff5b7 | 2014-10-23 11:54:39 -0500 | [diff] [blame] | 18 | n, err := networks.Create(client, networks.CreateOpts{Label: "sample_network", CIDR: "172.20.0.0/24"}).Extract() |
Jon Perritt | 857b312 | 2014-10-22 18:17:44 -0500 | [diff] [blame] | 19 | th.AssertNoErr(t, err) |
Jon Perritt | 26ff5b7 | 2014-10-23 11:54:39 -0500 | [diff] [blame] | 20 | t.Logf("Created network: %+v\n", n) |
| 21 | defer networks.Delete(client, n.ID) |
Jon Perritt | 857b312 | 2014-10-22 18:17:44 -0500 | [diff] [blame] | 22 | th.AssertEquals(t, n.Label, "sample_network") |
| 23 | th.AssertEquals(t, n.CIDR, "172.20.0.0/24") |
| 24 | networkID := n.ID |
| 25 | |
| 26 | // List networks |
Jon Perritt | 26ff5b7 | 2014-10-23 11:54:39 -0500 | [diff] [blame] | 27 | pager := networks.List(client) |
Jon Perritt | 857b312 | 2014-10-22 18:17:44 -0500 | [diff] [blame] | 28 | err = pager.EachPage(func(page pagination.Page) (bool, error) { |
| 29 | t.Logf("--- Page ---") |
| 30 | |
| 31 | networkList, err := networks.ExtractNetworks(page) |
| 32 | th.AssertNoErr(t, err) |
| 33 | |
| 34 | for _, n := range networkList { |
| 35 | t.Logf("Network: ID [%s] Label [%s] CIDR [%s]", |
| 36 | n.ID, n.Label, n.CIDR) |
| 37 | } |
| 38 | |
| 39 | return true, nil |
| 40 | }) |
| 41 | th.CheckNoErr(t, err) |
| 42 | |
| 43 | // Get a network |
| 44 | if networkID == "" { |
| 45 | t.Fatalf("In order to retrieve a network, the NetworkID must be set") |
| 46 | } |
Jon Perritt | 26ff5b7 | 2014-10-23 11:54:39 -0500 | [diff] [blame] | 47 | n, err = networks.Get(client, networkID).Extract() |
| 48 | t.Logf("Retrieved Network: %+v\n", n) |
Jon Perritt | 857b312 | 2014-10-22 18:17:44 -0500 | [diff] [blame] | 49 | th.AssertNoErr(t, err) |
Jon Perritt | 26ff5b7 | 2014-10-23 11:54:39 -0500 | [diff] [blame] | 50 | th.AssertEquals(t, n.CIDR, "172.20.0.0/24") |
Jon Perritt | 857b312 | 2014-10-22 18:17:44 -0500 | [diff] [blame] | 51 | th.AssertEquals(t, n.Label, "sample_network") |
| 52 | th.AssertEquals(t, n.ID, networkID) |
| 53 | } |