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

     1  package testing
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/vnpaycloud-console/gophercloud/v2/openstack/compute/v2/instanceactions"
     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  	HandleInstanceActionListSuccessfully(t)
    17  
    18  	expected := ListExpected
    19  	pages := 0
    20  	err := instanceactions.List(client.ServiceClient(), "asdfasdfasdf", nil).EachPage(context.TODO(), func(_ context.Context, page pagination.Page) (bool, error) {
    21  		pages++
    22  
    23  		actual, err := instanceactions.ExtractInstanceActions(page)
    24  		th.AssertNoErr(t, err)
    25  
    26  		if len(actual) != 2 {
    27  			t.Fatalf("Expected 2 instance actions, got %d", len(actual))
    28  		}
    29  		th.CheckDeepEquals(t, expected, actual)
    30  
    31  		return true, nil
    32  	})
    33  	th.AssertNoErr(t, err)
    34  	th.CheckEquals(t, 1, pages)
    35  }
    36  
    37  func TestGet(t *testing.T) {
    38  	th.SetupHTTP()
    39  	defer th.TeardownHTTP()
    40  	HandleInstanceActionGetSuccessfully(t)
    41  
    42  	client := client.ServiceClient()
    43  	actual, err := instanceactions.Get(context.TODO(), client, "asdfasdfasdf", "okzeorkmkfs").Extract()
    44  	if err != nil {
    45  		t.Fatalf("Unexpected Get error: %v", err)
    46  	}
    47  
    48  	th.CheckDeepEquals(t, GetExpected, actual)
    49  }