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