1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
package testing
import (
"testing"
"github.com/gophercloud/gophercloud/openstack/identity/v3/domains"
"github.com/gophercloud/gophercloud/pagination"
th "github.com/gophercloud/gophercloud/testhelper"
"github.com/gophercloud/gophercloud/testhelper/client"
)
func TestListDomains(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleListDomainsSuccessfully(t)
count := 0
err := domains.List(client.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) {
count++
actual, err := domains.ExtractDomains(page)
th.AssertNoErr(t, err)
th.CheckDeepEquals(t, ExpectedDomainsSlice, actual)
return true, nil
})
th.AssertNoErr(t, err)
th.CheckEquals(t, count, 1)
}
func TestListDomainsAllPages(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleListDomainsSuccessfully(t)
allPages, err := domains.List(client.ServiceClient(), nil).AllPages()
th.AssertNoErr(t, err)
actual, err := domains.ExtractDomains(allPages)
th.AssertNoErr(t, err)
th.CheckDeepEquals(t, ExpectedDomainsSlice, actual)
}
func TestGetDomain(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleGetDomainSuccessfully(t)
actual, err := domains.Get(client.ServiceClient(), "9fe1d3").Extract()
th.AssertNoErr(t, err)
th.CheckDeepEquals(t, SecondDomain, *actual)
}
func TestCreateDomain(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleCreateDomainSuccessfully(t)
createOpts := domains.CreateOpts{
Name: "domain two",
}
actual, err := domains.Create(client.ServiceClient(), createOpts).Extract()
th.AssertNoErr(t, err)
th.CheckDeepEquals(t, SecondDomain, *actual)
}
func TestDeleteDomain(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleDeleteDomainSuccessfully(t)
res := domains.Delete(client.ServiceClient(), "9fe1d3")
th.AssertNoErr(t, res.Err)
}
func TestUpdateDomain(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleUpdateDomainSuccessfully(t)
var description = "Staging Domain"
updateOpts := domains.UpdateOpts{
Description: &description,
}
actual, err := domains.Update(client.ServiceClient(), "9fe1d3", updateOpts).Extract()
th.AssertNoErr(t, err)
th.CheckDeepEquals(t, SecondDomainUpdated, *actual)
}
|