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

     1  package testing
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/vnpaycloud-console/gophercloud/v2/openstack/orchestration/v1/stackevents"
     8  	"github.com/vnpaycloud-console/gophercloud/v2/pagination"
     9  	th "github.com/vnpaycloud-console/gophercloud/v2/testhelper"
    10  	fake "github.com/vnpaycloud-console/gophercloud/v2/testhelper/client"
    11  )
    12  
    13  func TestFindEvents(t *testing.T) {
    14  	th.SetupHTTP()
    15  	defer th.TeardownHTTP()
    16  	HandleFindSuccessfully(t, FindOutput)
    17  
    18  	actual, err := stackevents.Find(context.TODO(), fake.ServiceClient(), "postman_stack").Extract()
    19  	th.AssertNoErr(t, err)
    20  
    21  	expected := FindExpected
    22  	th.AssertDeepEquals(t, expected, actual)
    23  }
    24  
    25  func TestList(t *testing.T) {
    26  	th.SetupHTTP()
    27  	defer th.TeardownHTTP()
    28  	HandleListSuccessfully(t, ListOutput)
    29  
    30  	count := 0
    31  	err := stackevents.List(fake.ServiceClient(), "hello_world", "49181cd6-169a-4130-9455-31185bbfc5bf", nil).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) {
    32  		count++
    33  		actual, err := stackevents.ExtractEvents(page)
    34  		th.AssertNoErr(t, err)
    35  
    36  		th.CheckDeepEquals(t, ListExpected, actual)
    37  
    38  		return true, nil
    39  	})
    40  	th.AssertNoErr(t, err)
    41  	th.CheckEquals(t, count, 1)
    42  }
    43  
    44  func TestListResourceEvents(t *testing.T) {
    45  	th.SetupHTTP()
    46  	defer th.TeardownHTTP()
    47  	HandleListResourceEventsSuccessfully(t, ListResourceEventsOutput)
    48  
    49  	count := 0
    50  	err := stackevents.ListResourceEvents(fake.ServiceClient(), "hello_world", "49181cd6-169a-4130-9455-31185bbfc5bf", "my_resource", nil).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) {
    51  		count++
    52  		actual, err := stackevents.ExtractResourceEvents(page)
    53  		th.AssertNoErr(t, err)
    54  
    55  		th.CheckDeepEquals(t, ListResourceEventsExpected, actual)
    56  
    57  		return true, nil
    58  	})
    59  	th.AssertNoErr(t, err)
    60  	th.CheckEquals(t, count, 1)
    61  }
    62  
    63  func TestGetEvent(t *testing.T) {
    64  	th.SetupHTTP()
    65  	defer th.TeardownHTTP()
    66  	HandleGetSuccessfully(t, GetOutput)
    67  
    68  	actual, err := stackevents.Get(context.TODO(), fake.ServiceClient(), "hello_world", "49181cd6-169a-4130-9455-31185bbfc5bf", "my_resource", "93940999-7d40-44ae-8de4-19624e7b8d18").Extract()
    69  	th.AssertNoErr(t, err)
    70  
    71  	expected := GetExpected
    72  	th.AssertDeepEquals(t, expected, actual)
    73  }