github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/db/v1/flavors/testing/requests_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/vnpaycloud-console/gophercloud/v2"
     8  	"github.com/vnpaycloud-console/gophercloud/v2/openstack/db/v1/flavors"
     9  	"github.com/vnpaycloud-console/gophercloud/v2/pagination"
    10  	th "github.com/vnpaycloud-console/gophercloud/v2/testhelper"
    11  	fake "github.com/vnpaycloud-console/gophercloud/v2/testhelper/client"
    12  )
    13  
    14  func TestListFlavors(t *testing.T) {
    15  	th.SetupHTTP()
    16  	defer th.TeardownHTTP()
    17  	HandleList(t)
    18  
    19  	pages := 0
    20  	err := flavors.List(fake.ServiceClient()).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) {
    21  		pages++
    22  
    23  		actual, err := flavors.ExtractFlavors(page)
    24  		if err != nil {
    25  			return false, err
    26  		}
    27  
    28  		expected := []flavors.Flavor{
    29  			{
    30  				ID:   1,
    31  				Name: "m1.tiny",
    32  				RAM:  512,
    33  				Links: []gophercloud.Link{
    34  					{Href: "https://openstack.example.com/v1.0/1234/flavors/1", Rel: "self"},
    35  					{Href: "https://openstack.example.com/flavors/1", Rel: "bookmark"},
    36  				},
    37  				StrID: "1",
    38  			},
    39  			{
    40  				ID:   2,
    41  				Name: "m1.small",
    42  				RAM:  1024,
    43  				Links: []gophercloud.Link{
    44  					{Href: "https://openstack.example.com/v1.0/1234/flavors/2", Rel: "self"},
    45  					{Href: "https://openstack.example.com/flavors/2", Rel: "bookmark"},
    46  				},
    47  				StrID: "2",
    48  			},
    49  			{
    50  				ID:   3,
    51  				Name: "m1.medium",
    52  				RAM:  2048,
    53  				Links: []gophercloud.Link{
    54  					{Href: "https://openstack.example.com/v1.0/1234/flavors/3", Rel: "self"},
    55  					{Href: "https://openstack.example.com/flavors/3", Rel: "bookmark"},
    56  				},
    57  				StrID: "3",
    58  			},
    59  			{
    60  				ID:   4,
    61  				Name: "m1.large",
    62  				RAM:  4096,
    63  				Links: []gophercloud.Link{
    64  					{Href: "https://openstack.example.com/v1.0/1234/flavors/4", Rel: "self"},
    65  					{Href: "https://openstack.example.com/flavors/4", Rel: "bookmark"},
    66  				},
    67  				StrID: "4",
    68  			},
    69  			{
    70  				ID:   0,
    71  				Name: "ds512M",
    72  				RAM:  512,
    73  				Links: []gophercloud.Link{
    74  					{Href: "https://openstack.example.com/v1.0/1234/flavors/d1", Rel: "self"},
    75  					{Href: "https://openstack.example.com/flavors/d1", Rel: "bookmark"},
    76  				},
    77  				StrID: "d1",
    78  			},
    79  		}
    80  
    81  		th.AssertDeepEquals(t, expected, actual)
    82  		return true, nil
    83  	})
    84  
    85  	th.AssertNoErr(t, err)
    86  	th.AssertEquals(t, 1, pages)
    87  }
    88  
    89  func TestGetFlavor(t *testing.T) {
    90  	th.SetupHTTP()
    91  	defer th.TeardownHTTP()
    92  	HandleGet(t)
    93  
    94  	actual, err := flavors.Get(context.TODO(), fake.ServiceClient(), flavorID).Extract()
    95  	th.AssertNoErr(t, err)
    96  
    97  	expected := &flavors.Flavor{
    98  		ID:   1,
    99  		Name: "m1.tiny",
   100  		RAM:  512,
   101  		Links: []gophercloud.Link{
   102  			{Href: "https://openstack.example.com/v1.0/1234/flavors/1", Rel: "self"},
   103  		},
   104  		StrID: "1",
   105  	}
   106  
   107  	th.AssertDeepEquals(t, expected, actual)
   108  }