blob: ddec66719479c2e066d4ecad0913f88bc611a47a [file] [log] [blame]
Jon Perritt9600eb42015-01-21 15:04:14 -07001// +build acceptance
2
3package v1
4
5import (
6 "testing"
7
8 "github.com/rackspace/gophercloud"
9 os "github.com/rackspace/gophercloud/openstack/cdn/v1/services"
Jon Perrittea764ef2015-01-23 10:59:32 -070010 "github.com/rackspace/gophercloud/pagination"
Jon Perritt9600eb42015-01-21 15:04:14 -070011 "github.com/rackspace/gophercloud/rackspace/cdn/v1/services"
12 th "github.com/rackspace/gophercloud/testhelper"
13)
14
15func 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 Perrittea764ef2015-01-23 10:59:32 -070030 t.Log("Listing Services")
31 testServiceList(t, client)
Jon Perritt9600eb42015-01-21 15:04:14 -070032}
33
34func 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
56func 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
62func testServiceUpdate(t *testing.T, client *gophercloud.ServiceClient, id string) {
Ash Wilson39552bd2015-01-29 12:05:21 -050063 opts := []os.Patch{
64 os.Append{
65 Value: os.Domain{Domain: "newDomain.com", Protocol: "http"},
Jon Perritt9600eb42015-01-21 15:04:14 -070066 },
67 }
Ash Wilson39552bd2015-01-29 12:05:21 -050068
69 loc, err := services.Update(client, id, opts).Extract()
Jon Perritt9600eb42015-01-21 15:04:14 -070070 th.AssertNoErr(t, err)
71 t.Logf("Successfully updated service at location: %s", loc)
72}
73
Jon Perritt9600eb42015-01-21 15:04:14 -070074func testServiceList(t *testing.T, client *gophercloud.ServiceClient) {
Jon Perrittea764ef2015-01-23 10:59:32 -070075 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 Perritt9600eb42015-01-21 15:04:14 -070086 th.AssertNoErr(t, err)
Jon Perritt9600eb42015-01-21 15:04:14 -070087}
Jon Perritt9600eb42015-01-21 15:04:14 -070088
89func 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}