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

     1  package testing
     2  
     3  import (
     4  	"context"
     5  	"sort"
     6  	"testing"
     7  
     8  	"github.com/vnpaycloud-console/gophercloud/v2/openstack/orchestration/v1/stackresources"
     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 TestFindResources(t *testing.T) {
    15  	th.SetupHTTP()
    16  	defer th.TeardownHTTP()
    17  	HandleFindSuccessfully(t, FindOutput)
    18  
    19  	actual, err := stackresources.Find(context.TODO(), fake.ServiceClient(), "hello_world").Extract()
    20  	th.AssertNoErr(t, err)
    21  
    22  	expected := FindExpected
    23  	th.AssertDeepEquals(t, expected, actual)
    24  }
    25  
    26  func TestListResources(t *testing.T) {
    27  	th.SetupHTTP()
    28  	defer th.TeardownHTTP()
    29  	HandleListSuccessfully(t, ListOutput)
    30  
    31  	count := 0
    32  	err := stackresources.List(fake.ServiceClient(), "hello_world", "49181cd6-169a-4130-9455-31185bbfc5bf", nil).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) {
    33  		count++
    34  		actual, err := stackresources.ExtractResources(page)
    35  		th.AssertNoErr(t, err)
    36  
    37  		th.CheckDeepEquals(t, ListExpected, actual)
    38  
    39  		return true, nil
    40  	})
    41  	th.AssertNoErr(t, err)
    42  	th.CheckEquals(t, count, 1)
    43  }
    44  
    45  func TestGetResource(t *testing.T) {
    46  	th.SetupHTTP()
    47  	defer th.TeardownHTTP()
    48  	HandleGetSuccessfully(t, GetOutput)
    49  
    50  	actual, err := stackresources.Get(context.TODO(), fake.ServiceClient(), "teststack", "0b1771bd-9336-4f2b-ae86-a80f971faf1e", "wordpress_instance").Extract()
    51  	th.AssertNoErr(t, err)
    52  
    53  	expected := GetExpected
    54  	th.AssertDeepEquals(t, expected, actual)
    55  }
    56  
    57  func TestResourceMetadata(t *testing.T) {
    58  	th.SetupHTTP()
    59  	defer th.TeardownHTTP()
    60  	HandleMetadataSuccessfully(t, MetadataOutput)
    61  
    62  	actual, err := stackresources.Metadata(context.TODO(), fake.ServiceClient(), "teststack", "0b1771bd-9336-4f2b-ae86-a80f971faf1e", "wordpress_instance").Extract()
    63  	th.AssertNoErr(t, err)
    64  
    65  	expected := MetadataExpected
    66  	th.AssertDeepEquals(t, expected, actual)
    67  }
    68  
    69  func TestListResourceTypes(t *testing.T) {
    70  	th.SetupHTTP()
    71  	defer th.TeardownHTTP()
    72  	HandleListTypesSuccessfully(t, ListTypesOutput)
    73  
    74  	count := 0
    75  	err := stackresources.ListTypes(fake.ServiceClient()).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) {
    76  		count++
    77  		actual, err := stackresources.ExtractResourceTypes(page)
    78  		th.AssertNoErr(t, err)
    79  
    80  		th.CheckDeepEquals(t, ListTypesExpected, actual)
    81  		// test if sorting works
    82  		sort.Sort(actual)
    83  		th.CheckDeepEquals(t, SortedListTypesExpected, actual)
    84  
    85  		return true, nil
    86  	})
    87  	th.AssertNoErr(t, err)
    88  	th.CheckEquals(t, 1, count)
    89  }
    90  
    91  func TestGetResourceSchema(t *testing.T) {
    92  	th.SetupHTTP()
    93  	defer th.TeardownHTTP()
    94  	HandleGetSchemaSuccessfully(t, GetSchemaOutput)
    95  
    96  	actual, err := stackresources.Schema(context.TODO(), fake.ServiceClient(), "OS::Heat::AResourceName").Extract()
    97  	th.AssertNoErr(t, err)
    98  
    99  	expected := GetSchemaExpected
   100  	th.AssertDeepEquals(t, expected, actual)
   101  }
   102  
   103  func TestGetResourceTemplate(t *testing.T) {
   104  	th.SetupHTTP()
   105  	defer th.TeardownHTTP()
   106  	HandleGetTemplateSuccessfully(t, GetTemplateOutput)
   107  
   108  	actual, err := stackresources.Template(context.TODO(), fake.ServiceClient(), "OS::Heat::AResourceName").Extract()
   109  	th.AssertNoErr(t, err)
   110  
   111  	expected := GetTemplateExpected
   112  	th.AssertDeepEquals(t, expected, string(actual))
   113  }
   114  
   115  func TestMarkUnhealthyResource(t *testing.T) {
   116  	th.SetupHTTP()
   117  	defer th.TeardownHTTP()
   118  	HandleMarkUnhealthySuccessfully(t)
   119  
   120  	markUnhealthyOpts := &stackresources.MarkUnhealthyOpts{
   121  		MarkUnhealthy:        true,
   122  		ResourceStatusReason: "Kubelet.Ready is Unknown more than 10 mins.",
   123  	}
   124  	err := stackresources.MarkUnhealthy(context.TODO(), fake.ServiceClient(), "teststack", "0b1771bd-9336-4f2b-ae86-a80f971faf1e", "wordpress_instance", markUnhealthyOpts).ExtractErr()
   125  	th.AssertNoErr(t, err)
   126  }