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