blob: 51e03f733de58c17f8e49bebb3406c9161567d21 [file] [log] [blame]
// +build acceptance
package v1
import (
"testing"
"github.com/rackspace/gophercloud"
os "github.com/rackspace/gophercloud/openstack/cdn/v1/services"
"github.com/rackspace/gophercloud/rackspace/cdn/v1/services"
th "github.com/rackspace/gophercloud/testhelper"
)
func TestService(t *testing.T) {
client := newClient(t)
t.Log("Creating Service")
loc := testServiceCreate(t, client)
t.Logf("Created service at location: %s", loc)
defer testServiceDelete(t, client, loc)
t.Log("Updating Service")
testServiceUpdate(t, client, loc)
t.Log("Retrieving Service")
testServiceGet(t, client, loc)
/*
t.Log("Listing Services")
testServiceList(t, client)
*/
}
func testServiceCreate(t *testing.T, client *gophercloud.ServiceClient) string {
createOpts := os.CreateOpts{
Name: "gophercloud-test-service",
Domains: []os.Domain{
os.Domain{
Domain: "www.gophercloud-test-service.com",
},
},
Origins: []os.Origin{
os.Origin{
Origin: "gophercloud-test-service.com",
Port: 80,
SSL: false,
},
},
FlavorID: "cdn",
}
l, err := services.Create(client, createOpts).Extract()
th.AssertNoErr(t, err)
return l
}
func testServiceGet(t *testing.T, client *gophercloud.ServiceClient, id string) {
s, err := services.Get(client, id).Extract()
th.AssertNoErr(t, err)
t.Logf("Retrieved service: %+v", *s)
}
func testServiceUpdate(t *testing.T, client *gophercloud.ServiceClient, id string) {
updateOpts := os.UpdateOpts{
os.UpdateOpt{
Op: os.Add,
Path: "/domains/-",
Value: map[string]interface{}{
"domain": "newDomain.com",
"protocol": "http",
},
},
}
loc, err := services.Update(client, id, updateOpts).Extract()
th.AssertNoErr(t, err)
t.Logf("Successfully updated service at location: %s", loc)
}
/*
func testServiceList(t *testing.T, client *gophercloud.ServiceClient) {
err := service.List(client).ExtractErr()
th.AssertNoErr(t, err)
t.Logf("Successfully pinged root URL")
}
*/
func testServiceDelete(t *testing.T, client *gophercloud.ServiceClient, id string) {
err := services.Delete(client, id).ExtractErr()
th.AssertNoErr(t, err)
t.Logf("Successfully deleted service (%s)", id)
}