requests_test.go 2.2 KB

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