Jamie Hannaford | 5e45ccb | 2014-09-22 15:41:10 +0200 | [diff] [blame] | 1 | package v2 |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "testing" |
| 6 | |
| 7 | "github.com/rackspace/gophercloud" |
| 8 | "github.com/rackspace/gophercloud/openstack" |
Jamie Hannaford | 5e45ccb | 2014-09-22 15:41:10 +0200 | [diff] [blame] | 9 | th "github.com/rackspace/gophercloud/testhelper" |
| 10 | ) |
| 11 | |
| 12 | var Client *gophercloud.ServiceClient |
| 13 | |
| 14 | func NewClient() (*gophercloud.ServiceClient, error) { |
Jamie Hannaford | 390555a | 2014-10-22 17:04:03 +0200 | [diff] [blame] | 15 | opts, err := openstack.AuthOptionsFromEnv() |
Jamie Hannaford | 5e45ccb | 2014-09-22 15:41:10 +0200 | [diff] [blame] | 16 | if err != nil { |
| 17 | return nil, err |
| 18 | } |
| 19 | |
| 20 | provider, err := openstack.AuthenticatedClient(opts) |
| 21 | if err != nil { |
| 22 | return nil, err |
| 23 | } |
| 24 | |
| 25 | return openstack.NewNetworkV2(provider, gophercloud.EndpointOpts{ |
| 26 | Name: "neutron", |
| 27 | Region: os.Getenv("OS_REGION_NAME"), |
| 28 | }) |
| 29 | } |
| 30 | |
| 31 | func Setup(t *testing.T) { |
| 32 | client, err := NewClient() |
| 33 | th.AssertNoErr(t, err) |
| 34 | Client = client |
| 35 | } |
| 36 | |
| 37 | func Teardown() { |
| 38 | Client = nil |
| 39 | } |