github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/blockstorage/v3/attachments/testing/requests_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/vnpaycloud-console/gophercloud/v2/openstack/blockstorage/v3/attachments"
     8  	th "github.com/vnpaycloud-console/gophercloud/v2/testhelper"
     9  	"github.com/vnpaycloud-console/gophercloud/v2/testhelper/client"
    10  )
    11  
    12  func TestListAll(t *testing.T) {
    13  	th.SetupHTTP()
    14  	defer th.TeardownHTTP()
    15  
    16  	MockListResponse(t)
    17  
    18  	allPages, err := attachments.List(client.ServiceClient(), &attachments.ListOpts{}).AllPages(context.TODO())
    19  	th.AssertNoErr(t, err)
    20  	actual, err := attachments.ExtractAttachments(allPages)
    21  	th.AssertNoErr(t, err)
    22  
    23  	expected := []attachments.Attachment{*expectedAttachment}
    24  
    25  	th.CheckDeepEquals(t, expected, actual)
    26  
    27  }
    28  
    29  func TestGet(t *testing.T) {
    30  	th.SetupHTTP()
    31  	defer th.TeardownHTTP()
    32  
    33  	MockGetResponse(t)
    34  
    35  	attachment, err := attachments.Get(context.TODO(), client.ServiceClient(), "05551600-a936-4d4a-ba42-79a037c1-c91a").Extract()
    36  	th.AssertNoErr(t, err)
    37  
    38  	th.AssertDeepEquals(t, expectedAttachment, attachment)
    39  }
    40  
    41  func TestCreate(t *testing.T) {
    42  	th.SetupHTTP()
    43  	defer th.TeardownHTTP()
    44  
    45  	MockCreateResponse(t)
    46  
    47  	options := &attachments.CreateOpts{
    48  		InstanceUUID: "83ec2e3b-4321-422b-8706-a84185f52a0a",
    49  		Connector: map[string]any{
    50  			"initiator":  "iqn.1993-08.org.debian: 01: cad181614cec",
    51  			"ip":         "192.168.1.20",
    52  			"platform":   "x86_64",
    53  			"host":       "tempest-1",
    54  			"os_type":    "linux2",
    55  			"multipath":  false,
    56  			"mountpoint": "/dev/vdb",
    57  			"mode":       "rw",
    58  		},
    59  		VolumeUUID: "289da7f8-6440-407c-9fb4-7db01ec49164",
    60  	}
    61  	attachment, err := attachments.Create(context.TODO(), client.ServiceClient(), options).Extract()
    62  	th.AssertNoErr(t, err)
    63  
    64  	th.AssertDeepEquals(t, expectedAttachment, attachment)
    65  }
    66  
    67  func TestDelete(t *testing.T) {
    68  	th.SetupHTTP()
    69  	defer th.TeardownHTTP()
    70  
    71  	MockDeleteResponse(t)
    72  
    73  	res := attachments.Delete(context.TODO(), client.ServiceClient(), "05551600-a936-4d4a-ba42-79a037c1-c91a")
    74  	th.AssertNoErr(t, res.Err)
    75  }
    76  
    77  func TestUpdate(t *testing.T) {
    78  	th.SetupHTTP()
    79  	defer th.TeardownHTTP()
    80  
    81  	MockUpdateResponse(t)
    82  
    83  	options := &attachments.UpdateOpts{
    84  		Connector: map[string]any{
    85  			"initiator":  "iqn.1993-08.org.debian: 01: cad181614cec",
    86  			"ip":         "192.168.1.20",
    87  			"platform":   "x86_64",
    88  			"host":       "tempest-1",
    89  			"os_type":    "linux2",
    90  			"multipath":  false,
    91  			"mountpoint": "/dev/vdb",
    92  			"mode":       "rw",
    93  		},
    94  	}
    95  	attachment, err := attachments.Update(context.TODO(), client.ServiceClient(), "05551600-a936-4d4a-ba42-79a037c1-c91a", options).Extract()
    96  	th.AssertNoErr(t, err)
    97  	th.AssertDeepEquals(t, expectedAttachment, attachment)
    98  }
    99  
   100  func TestUpdateEmpty(t *testing.T) {
   101  	th.SetupHTTP()
   102  	defer th.TeardownHTTP()
   103  
   104  	MockUpdateEmptyResponse(t)
   105  
   106  	options := attachments.UpdateOpts{}
   107  	attachment, err := attachments.Update(context.TODO(), client.ServiceClient(), "05551600-a936-4d4a-ba42-79a037c1-c91a", options).Extract()
   108  	th.AssertNoErr(t, err)
   109  	th.AssertDeepEquals(t, expectedAttachment, attachment)
   110  }
   111  
   112  func TestComplete(t *testing.T) {
   113  	th.SetupHTTP()
   114  	defer th.TeardownHTTP()
   115  
   116  	MockCompleteResponse(t)
   117  
   118  	err := attachments.Complete(context.TODO(), client.ServiceClient(), "05551600-a936-4d4a-ba42-79a037c1-c91a").ExtractErr()
   119  	th.AssertNoErr(t, err)
   120  }