github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/compute/v2/servergroups/testing/requests_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/vnpaycloud-console/gophercloud/v2/openstack/compute/v2/servergroups"
     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 TestList(t *testing.T) {
    14  	th.SetupHTTP()
    15  	defer th.TeardownHTTP()
    16  	HandleListSuccessfully(t)
    17  
    18  	count := 0
    19  	err := servergroups.List(client.ServiceClient(), &servergroups.ListOpts{}).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) {
    20  		count++
    21  		actual, err := servergroups.ExtractServerGroups(page)
    22  		th.AssertNoErr(t, err)
    23  		th.CheckDeepEquals(t, ExpectedServerGroupSlice, actual)
    24  
    25  		return true, nil
    26  	})
    27  	th.AssertNoErr(t, err)
    28  	th.CheckEquals(t, 1, count)
    29  }
    30  
    31  func TestCreate(t *testing.T) {
    32  	th.SetupHTTP()
    33  	defer th.TeardownHTTP()
    34  	HandleCreateSuccessfully(t)
    35  
    36  	actual, err := servergroups.Create(context.TODO(), client.ServiceClient(), servergroups.CreateOpts{
    37  		Name:     "test",
    38  		Policies: []string{"anti-affinity"},
    39  	}).Extract()
    40  	th.AssertNoErr(t, err)
    41  	th.CheckDeepEquals(t, &CreatedServerGroup, actual)
    42  }
    43  
    44  func TestCreateMicroversion(t *testing.T) {
    45  	th.SetupHTTP()
    46  	defer th.TeardownHTTP()
    47  	HandleCreateMicroversionSuccessfully(t)
    48  
    49  	policy := "anti-affinity"
    50  	rules := servergroups.Rules{
    51  		MaxServerPerHost: 3,
    52  	}
    53  	CreatedServerGroup.Policy = &policy
    54  	CreatedServerGroup.Rules = &rules
    55  
    56  	result := servergroups.Create(context.TODO(), client.ServiceClient(), servergroups.CreateOpts{
    57  		Name:     "test",
    58  		Policies: []string{"anti-affinity"},
    59  		Policy:   policy,
    60  		Rules:    &rules,
    61  	})
    62  
    63  	actual, err := result.Extract()
    64  	th.AssertNoErr(t, err)
    65  	th.CheckDeepEquals(t, &CreatedServerGroup, actual)
    66  }
    67  
    68  func TestGet(t *testing.T) {
    69  	th.SetupHTTP()
    70  	defer th.TeardownHTTP()
    71  	HandleGetSuccessfully(t)
    72  
    73  	actual, err := servergroups.Get(context.TODO(), client.ServiceClient(), "4d8c3732-a248-40ed-bebc-539a6ffd25c0").Extract()
    74  	th.AssertNoErr(t, err)
    75  	th.CheckDeepEquals(t, &FirstServerGroup, actual)
    76  }
    77  
    78  func TestGetMicroversion(t *testing.T) {
    79  	th.SetupHTTP()
    80  	defer th.TeardownHTTP()
    81  	HandleGetMicroversionSuccessfully(t)
    82  
    83  	policy := "anti-affinity"
    84  	rules := servergroups.Rules{
    85  		MaxServerPerHost: 3,
    86  	}
    87  	FirstServerGroup.Policy = &policy
    88  	FirstServerGroup.Rules = &rules
    89  
    90  	result := servergroups.Get(context.TODO(), client.ServiceClient(), "4d8c3732-a248-40ed-bebc-539a6ffd25c0")
    91  
    92  	// Extract basic fields.
    93  	actual, err := result.Extract()
    94  	th.AssertNoErr(t, err)
    95  	th.CheckDeepEquals(t, &FirstServerGroup, actual)
    96  }
    97  
    98  func TestDelete(t *testing.T) {
    99  	th.SetupHTTP()
   100  	defer th.TeardownHTTP()
   101  	HandleDeleteSuccessfully(t)
   102  
   103  	err := servergroups.Delete(context.TODO(), client.ServiceClient(), "616fb98f-46ca-475e-917e-2563e5a8cd19").ExtractErr()
   104  	th.AssertNoErr(t, err)
   105  }