github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/identity/v3/domains/testing/requests_test.go (about)

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