Jamie Hannaford | 6e3d566 | 2014-09-11 10:24:49 +0200 | [diff] [blame^] | 1 | // +build acceptance networking |
| 2 | |
| 3 | package networking |
| 4 | |
| 5 | import ( |
| 6 | "fmt" |
| 7 | "os" |
| 8 | "testing" |
| 9 | |
| 10 | networking "github.com/rackspace/gophercloud/openstack/networking/v2" |
| 11 | "github.com/rackspace/gophercloud/openstack/networking/v2/networks" |
| 12 | "github.com/rackspace/gophercloud/openstack/utils" |
| 13 | ) |
| 14 | |
| 15 | var Client *networking.Client |
| 16 | |
| 17 | func NewClient() (*networking.Client, error) { |
| 18 | opts, err := utils.AuthOptions() |
| 19 | if err != nil { |
| 20 | return nil, err |
| 21 | } |
| 22 | |
| 23 | res, err := identity.Authenticate(opts) |
| 24 | if err != nil { |
| 25 | return nil, err |
| 26 | } |
| 27 | |
| 28 | catalog, err := identity.GetServiceCatalog(res) |
| 29 | if err != nil { |
| 30 | return nil, err |
| 31 | } |
| 32 | |
| 33 | entries, err := catalog.CatalogEntries() |
| 34 | if err != nil { |
| 35 | return nil, err |
| 36 | } |
| 37 | |
| 38 | var endpoints []identity.Endpoint |
| 39 | for _, entry := range entries { |
| 40 | if entry.Type == "network" { |
| 41 | endpoints = entry.Endpoints |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | region := os.Getenv("OS_REGION_NAME") |
| 46 | |
| 47 | url := "" |
| 48 | for _, endpoint := range endpoints { |
| 49 | if endpoint.Region == "region" { |
| 50 | url = endpoint.PublicURL |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | client := networking.NewClient(url, res, opts) |
| 55 | return client, nil |
| 56 | } |
| 57 | |
| 58 | type SuiteTester struct { |
| 59 | suite.Suite |
| 60 | Client *networking.Client |
| 61 | } |
| 62 | |
| 63 | func Setup() { |
| 64 | client, err = NewClient() |
| 65 | if err != nil { |
| 66 | fmt.Println("Client failed to load") |
| 67 | return |
| 68 | } |
| 69 | |
| 70 | Client = client |
| 71 | } |
| 72 | |
| 73 | func Teardown() { |
| 74 | Client = nil |
| 75 | } |
| 76 | |
| 77 | func TestListApiVersions(t *testing.T) { |
| 78 | networks.ApiVersions() |
| 79 | } |
| 80 | |
| 81 | func TestGetApiInfo(t *testing.T) { |
| 82 | networks.ApiInfo() |
| 83 | } |
| 84 | |
| 85 | func TestListExts(t *testing.T) { |
| 86 | networks.Extensions() |
| 87 | } |
| 88 | |
| 89 | func TestGetExt(t *testing.T) { |
| 90 | networks.Extension() |
| 91 | } |
| 92 | |
| 93 | func TestListNetworks(t *testing.T) { |
| 94 | networks.List() |
| 95 | } |
| 96 | |
| 97 | func TestGetNetwork(t *testing.T) { |
| 98 | networks.Get() |
| 99 | } |
| 100 | |
| 101 | func TestCreateNetwork(t *testing.T) { |
| 102 | networks.Create() |
| 103 | } |
| 104 | |
| 105 | func TestCreateMultipleNetworks(t *testing.T) { |
| 106 | networks.CreateMany() |
| 107 | } |
| 108 | |
| 109 | func TestUpdateNetwork(t *testing.T) { |
| 110 | networks.Update() |
| 111 | } |
| 112 | |
| 113 | func TestDeleteNetwork(t *testing.T) { |
| 114 | networks.Delete() |
| 115 | } |