blob: 7a5de62b5c181a2e9e9c8a5d39616081ba9c73f7 [file] [log] [blame]
Jamie Hannaford6e3d5662014-09-11 10:24:49 +02001// +build acceptance networking
2
3package networking
4
5import (
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
15var Client *networking.Client
16
17func 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
58type SuiteTester struct {
59 suite.Suite
60 Client *networking.Client
61}
62
63func 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
73func Teardown() {
74 Client = nil
75}
76
77func TestListApiVersions(t *testing.T) {
78 networks.ApiVersions()
79}
80
81func TestGetApiInfo(t *testing.T) {
82 networks.ApiInfo()
83}
84
85func TestListExts(t *testing.T) {
86 networks.Extensions()
87}
88
89func TestGetExt(t *testing.T) {
90 networks.Extension()
91}
92
93func TestListNetworks(t *testing.T) {
94 networks.List()
95}
96
97func TestGetNetwork(t *testing.T) {
98 networks.Get()
99}
100
101func TestCreateNetwork(t *testing.T) {
102 networks.Create()
103}
104
105func TestCreateMultipleNetworks(t *testing.T) {
106 networks.CreateMany()
107}
108
109func TestUpdateNetwork(t *testing.T) {
110 networks.Update()
111}
112
113func TestDeleteNetwork(t *testing.T) {
114 networks.Delete()
115}