Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 1 | // +build acceptance compute servers |
| 2 | |
| 3 | package v2 |
| 4 | |
| 5 | import ( |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 6 | "testing" |
| 7 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame^] | 8 | "github.com/gophercloud/gophercloud/acceptance/clients" |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 9 | "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/networks" |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 10 | ) |
| 11 | |
Joe Topjian | 924f701 | 2016-07-25 18:19:17 +0000 | [diff] [blame] | 12 | func TestNetworksList(t *testing.T) { |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame^] | 13 | client, err := clients.NewComputeV2Client() |
Joe Topjian | 924f701 | 2016-07-25 18:19:17 +0000 | [diff] [blame] | 14 | if err != nil { |
| 15 | t.Fatalf("Unable to create a compute client: %v", err) |
| 16 | } |
| 17 | |
| 18 | allPages, err := networks.List(client).AllPages() |
| 19 | if err != nil { |
| 20 | t.Fatalf("Unable to list networks: %v", err) |
| 21 | } |
| 22 | |
| 23 | allNetworks, err := networks.ExtractNetworks(allPages) |
| 24 | if err != nil { |
| 25 | t.Fatalf("Unable to list networks: %v", err) |
| 26 | } |
| 27 | |
| 28 | for _, network := range allNetworks { |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame^] | 29 | PrintNetwork(t, &network) |
Joe Topjian | 924f701 | 2016-07-25 18:19:17 +0000 | [diff] [blame] | 30 | } |
| 31 | } |
| 32 | |
| 33 | func TestNetworksGet(t *testing.T) { |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame^] | 34 | choices, err := clients.AcceptanceTestChoicesFromEnv() |
Joe Topjian | 924f701 | 2016-07-25 18:19:17 +0000 | [diff] [blame] | 35 | if err != nil { |
| 36 | t.Fatal(err) |
| 37 | } |
| 38 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame^] | 39 | client, err := clients.NewComputeV2Client() |
Joe Topjian | 924f701 | 2016-07-25 18:19:17 +0000 | [diff] [blame] | 40 | if err != nil { |
| 41 | t.Fatalf("Unable to create a compute client: %v", err) |
| 42 | } |
| 43 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame^] | 44 | networkID, err := GetNetworkIDFromNetworks(t, client, choices.NetworkName) |
Joe Topjian | 924f701 | 2016-07-25 18:19:17 +0000 | [diff] [blame] | 45 | if err != nil { |
| 46 | t.Fatal(err) |
| 47 | } |
| 48 | |
| 49 | network, err := networks.Get(client, networkID).Extract() |
| 50 | if err != nil { |
| 51 | t.Fatalf("Unable to get network %s: %v", networkID, err) |
| 52 | } |
| 53 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame^] | 54 | PrintNetwork(t, network) |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 55 | } |