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