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