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" |
| 10 | "github.com/rackspace/gophercloud/rackspace/cdn/v1/services" |
| 11 | th "github.com/rackspace/gophercloud/testhelper" |
| 12 | ) |
| 13 | |
| 14 | func TestService(t *testing.T) { |
| 15 | client := newClient(t) |
| 16 | |
| 17 | t.Log("Creating Service") |
| 18 | loc := testServiceCreate(t, client) |
| 19 | t.Logf("Created service at location: %s", loc) |
| 20 | |
| 21 | defer testServiceDelete(t, client, loc) |
| 22 | |
| 23 | t.Log("Updating Service") |
| 24 | testServiceUpdate(t, client, loc) |
| 25 | |
| 26 | t.Log("Retrieving Service") |
| 27 | testServiceGet(t, client, loc) |
| 28 | |
| 29 | /* |
| 30 | t.Log("Listing Services") |
| 31 | testServiceList(t, client) |
| 32 | */ |
| 33 | } |
| 34 | |
| 35 | func testServiceCreate(t *testing.T, client *gophercloud.ServiceClient) string { |
| 36 | createOpts := os.CreateOpts{ |
| 37 | Name: "gophercloud-test-service", |
| 38 | Domains: []os.Domain{ |
| 39 | os.Domain{ |
| 40 | Domain: "www.gophercloud-test-service.com", |
| 41 | }, |
| 42 | }, |
| 43 | Origins: []os.Origin{ |
| 44 | os.Origin{ |
| 45 | Origin: "gophercloud-test-service.com", |
| 46 | Port: 80, |
| 47 | SSL: false, |
| 48 | }, |
| 49 | }, |
| 50 | FlavorID: "cdn", |
| 51 | } |
| 52 | l, err := services.Create(client, createOpts).Extract() |
| 53 | th.AssertNoErr(t, err) |
| 54 | return l |
| 55 | } |
| 56 | |
| 57 | func testServiceGet(t *testing.T, client *gophercloud.ServiceClient, id string) { |
| 58 | s, err := services.Get(client, id).Extract() |
| 59 | th.AssertNoErr(t, err) |
| 60 | t.Logf("Retrieved service: %+v", *s) |
| 61 | } |
| 62 | |
| 63 | func testServiceUpdate(t *testing.T, client *gophercloud.ServiceClient, id string) { |
| 64 | updateOpts := os.UpdateOpts{ |
| 65 | os.UpdateOpt{ |
| 66 | Op: os.Add, |
| 67 | Path: "/domains/-", |
| 68 | Value: map[string]interface{}{ |
| 69 | "domain": "newDomain.com", |
| 70 | "protocol": "http", |
| 71 | }, |
| 72 | }, |
| 73 | } |
| 74 | loc, err := services.Update(client, id, updateOpts).Extract() |
| 75 | th.AssertNoErr(t, err) |
| 76 | t.Logf("Successfully updated service at location: %s", loc) |
| 77 | } |
| 78 | |
| 79 | /* |
| 80 | func testServiceList(t *testing.T, client *gophercloud.ServiceClient) { |
| 81 | err := service.List(client).ExtractErr() |
| 82 | th.AssertNoErr(t, err) |
| 83 | t.Logf("Successfully pinged root URL") |
| 84 | } |
| 85 | */ |
| 86 | |
| 87 | func testServiceDelete(t *testing.T, client *gophercloud.ServiceClient, id string) { |
| 88 | err := services.Delete(client, id).ExtractErr() |
| 89 | th.AssertNoErr(t, err) |
| 90 | t.Logf("Successfully deleted service (%s)", id) |
| 91 | } |