github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/compute/v2/extensions/volumeattach/testing/requests_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/huaweicloud/golangsdk/openstack/compute/v2/extensions/volumeattach"
     7  	"github.com/huaweicloud/golangsdk/pagination"
     8  	th "github.com/huaweicloud/golangsdk/testhelper"
     9  	"github.com/huaweicloud/golangsdk/testhelper/client"
    10  )
    11  
    12  // FirstVolumeAttachment is the first result in ListOutput.
    13  var FirstVolumeAttachment = volumeattach.VolumeAttachment{
    14  	Device:   "/dev/vdd",
    15  	ID:       "a26887c6-c47b-4654-abb5-dfadf7d3f803",
    16  	ServerID: "4d8c3732-a248-40ed-bebc-539a6ffd25c0",
    17  	VolumeID: "a26887c6-c47b-4654-abb5-dfadf7d3f803",
    18  }
    19  
    20  // SecondVolumeAttachment is the first result in ListOutput.
    21  var SecondVolumeAttachment = volumeattach.VolumeAttachment{
    22  	Device:   "/dev/vdc",
    23  	ID:       "a26887c6-c47b-4654-abb5-dfadf7d3f804",
    24  	ServerID: "4d8c3732-a248-40ed-bebc-539a6ffd25c0",
    25  	VolumeID: "a26887c6-c47b-4654-abb5-dfadf7d3f804",
    26  }
    27  
    28  // ExpectedVolumeAttachmentSlide is the slice of results that should be parsed
    29  // from ListOutput, in the expected order.
    30  var ExpectedVolumeAttachmentSlice = []volumeattach.VolumeAttachment{FirstVolumeAttachment, SecondVolumeAttachment}
    31  
    32  //CreatedVolumeAttachment is the parsed result from CreatedOutput.
    33  var CreatedVolumeAttachment = volumeattach.VolumeAttachment{
    34  	Device:   "/dev/vdc",
    35  	ID:       "a26887c6-c47b-4654-abb5-dfadf7d3f804",
    36  	ServerID: "4d8c3732-a248-40ed-bebc-539a6ffd25c0",
    37  	VolumeID: "a26887c6-c47b-4654-abb5-dfadf7d3f804",
    38  }
    39  
    40  func TestList(t *testing.T) {
    41  	th.SetupHTTP()
    42  	defer th.TeardownHTTP()
    43  
    44  	HandleListSuccessfully(t)
    45  
    46  	serverID := "4d8c3732-a248-40ed-bebc-539a6ffd25c0"
    47  
    48  	count := 0
    49  	err := volumeattach.List(client.ServiceClient(), serverID).EachPage(func(page pagination.Page) (bool, error) {
    50  		count++
    51  		actual, err := volumeattach.ExtractVolumeAttachments(page)
    52  		th.AssertNoErr(t, err)
    53  		th.CheckDeepEquals(t, ExpectedVolumeAttachmentSlice, actual)
    54  
    55  		return true, nil
    56  	})
    57  	th.AssertNoErr(t, err)
    58  	th.CheckEquals(t, 1, count)
    59  }
    60  
    61  func TestCreate(t *testing.T) {
    62  	th.SetupHTTP()
    63  	defer th.TeardownHTTP()
    64  
    65  	HandleCreateSuccessfully(t)
    66  
    67  	serverID := "4d8c3732-a248-40ed-bebc-539a6ffd25c0"
    68  
    69  	actual, err := volumeattach.Create(client.ServiceClient(), serverID, volumeattach.CreateOpts{
    70  		Device:   "/dev/vdc",
    71  		VolumeID: "a26887c6-c47b-4654-abb5-dfadf7d3f804",
    72  	}).Extract()
    73  	th.AssertNoErr(t, err)
    74  	th.CheckDeepEquals(t, &CreatedVolumeAttachment, actual)
    75  }
    76  
    77  func TestGet(t *testing.T) {
    78  	th.SetupHTTP()
    79  	defer th.TeardownHTTP()
    80  
    81  	HandleGetSuccessfully(t)
    82  
    83  	aID := "a26887c6-c47b-4654-abb5-dfadf7d3f804"
    84  	serverID := "4d8c3732-a248-40ed-bebc-539a6ffd25c0"
    85  
    86  	actual, err := volumeattach.Get(client.ServiceClient(), serverID, aID).Extract()
    87  	th.AssertNoErr(t, err)
    88  	th.CheckDeepEquals(t, &SecondVolumeAttachment, actual)
    89  }
    90  
    91  func TestDelete(t *testing.T) {
    92  	th.SetupHTTP()
    93  	defer th.TeardownHTTP()
    94  
    95  	HandleDeleteSuccessfully(t)
    96  
    97  	aID := "a26887c6-c47b-4654-abb5-dfadf7d3f804"
    98  	serverID := "4d8c3732-a248-40ed-bebc-539a6ffd25c0"
    99  
   100  	err := volumeattach.Delete(client.ServiceClient(), serverID, aID).ExtractErr()
   101  	th.AssertNoErr(t, err)
   102  }