Jon Perritt | 9600eb4 | 2015-01-21 15:04:14 -0700 | [diff] [blame] | 1 | // +build acceptance |
| 2 | |
| 3 | package v1 |
| 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/rackspace/gophercloud" |
| 9 | os "github.com/rackspace/gophercloud/openstack/cdn/v1/services" |
Jon Perritt | ea764ef | 2015-01-23 10:59:32 -0700 | [diff] [blame] | 10 | "github.com/rackspace/gophercloud/pagination" |
Jon Perritt | 9600eb4 | 2015-01-21 15:04:14 -0700 | [diff] [blame] | 11 | "github.com/rackspace/gophercloud/rackspace/cdn/v1/services" |
| 12 | th "github.com/rackspace/gophercloud/testhelper" |
| 13 | ) |
| 14 | |
| 15 | func TestService(t *testing.T) { |
| 16 | client := newClient(t) |
| 17 | |
| 18 | t.Log("Creating Service") |
| 19 | loc := testServiceCreate(t, client) |
| 20 | t.Logf("Created service at location: %s", loc) |
| 21 | |
| 22 | defer testServiceDelete(t, client, loc) |
| 23 | |
| 24 | t.Log("Updating Service") |
| 25 | testServiceUpdate(t, client, loc) |
| 26 | |
| 27 | t.Log("Retrieving Service") |
| 28 | testServiceGet(t, client, loc) |
| 29 | |
Jon Perritt | ea764ef | 2015-01-23 10:59:32 -0700 | [diff] [blame] | 30 | t.Log("Listing Services") |
| 31 | testServiceList(t, client) |
Jon Perritt | 9600eb4 | 2015-01-21 15:04:14 -0700 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | func testServiceCreate(t *testing.T, client *gophercloud.ServiceClient) string { |
| 35 | createOpts := os.CreateOpts{ |
| 36 | Name: "gophercloud-test-service", |
| 37 | Domains: []os.Domain{ |
| 38 | os.Domain{ |
| 39 | Domain: "www.gophercloud-test-service.com", |
| 40 | }, |
| 41 | }, |
| 42 | Origins: []os.Origin{ |
| 43 | os.Origin{ |
| 44 | Origin: "gophercloud-test-service.com", |
| 45 | Port: 80, |
| 46 | SSL: false, |
| 47 | }, |
| 48 | }, |
| 49 | FlavorID: "cdn", |
| 50 | } |
| 51 | l, err := services.Create(client, createOpts).Extract() |
| 52 | th.AssertNoErr(t, err) |
| 53 | return l |
| 54 | } |
| 55 | |
| 56 | func testServiceGet(t *testing.T, client *gophercloud.ServiceClient, id string) { |
| 57 | s, err := services.Get(client, id).Extract() |
| 58 | th.AssertNoErr(t, err) |
| 59 | t.Logf("Retrieved service: %+v", *s) |
| 60 | } |
| 61 | |
| 62 | func testServiceUpdate(t *testing.T, client *gophercloud.ServiceClient, id string) { |
Ash Wilson | 39552bd | 2015-01-29 12:05:21 -0500 | [diff] [blame] | 63 | opts := []os.Patch{ |
| 64 | os.Append{ |
| 65 | Value: os.Domain{Domain: "newDomain.com", Protocol: "http"}, |
Jon Perritt | 9600eb4 | 2015-01-21 15:04:14 -0700 | [diff] [blame] | 66 | }, |
| 67 | } |
Ash Wilson | 39552bd | 2015-01-29 12:05:21 -0500 | [diff] [blame] | 68 | |
| 69 | loc, err := services.Update(client, id, opts).Extract() |
Jon Perritt | 9600eb4 | 2015-01-21 15:04:14 -0700 | [diff] [blame] | 70 | th.AssertNoErr(t, err) |
| 71 | t.Logf("Successfully updated service at location: %s", loc) |
| 72 | } |
| 73 | |
Jon Perritt | 9600eb4 | 2015-01-21 15:04:14 -0700 | [diff] [blame] | 74 | func testServiceList(t *testing.T, client *gophercloud.ServiceClient) { |
Jon Perritt | ea764ef | 2015-01-23 10:59:32 -0700 | [diff] [blame] | 75 | err := services.List(client, nil).EachPage(func(page pagination.Page) (bool, error) { |
| 76 | serviceList, err := os.ExtractServices(page) |
| 77 | th.AssertNoErr(t, err) |
| 78 | |
| 79 | for _, service := range serviceList { |
| 80 | t.Logf("Listing service: %+v", service) |
| 81 | } |
| 82 | |
| 83 | return true, nil |
| 84 | }) |
| 85 | |
Jon Perritt | 9600eb4 | 2015-01-21 15:04:14 -0700 | [diff] [blame] | 86 | th.AssertNoErr(t, err) |
Jon Perritt | 9600eb4 | 2015-01-21 15:04:14 -0700 | [diff] [blame] | 87 | } |
Jon Perritt | 9600eb4 | 2015-01-21 15:04:14 -0700 | [diff] [blame] | 88 | |
| 89 | func testServiceDelete(t *testing.T, client *gophercloud.ServiceClient, id string) { |
| 90 | err := services.Delete(client, id).ExtractErr() |
| 91 | th.AssertNoErr(t, err) |
| 92 | t.Logf("Successfully deleted service (%s)", id) |
| 93 | } |