github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/evs/v1/volumes/testing/requests_test.go (about) 1 package testing 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/opentelekomcloud/gophertelekomcloud/openstack/evs/v1/volumes" 8 9 th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" 10 "github.com/opentelekomcloud/gophertelekomcloud/testhelper/client" 11 ) 12 13 func TestList(t *testing.T) { 14 th.SetupHTTP() 15 defer th.TeardownHTTP() 16 17 MockListResponse(t) 18 19 actual, err := volumes.List(client.ServiceClient(), volumes.ListOpts{}) 20 if err != nil { 21 t.Errorf("Failed to extract volumes: %v", err) 22 } 23 24 expected := []volumes.Volume{ 25 { 26 ID: "289da7f8-6440-407c-9fb4-7db01ec49164", 27 Name: "vol-001", 28 }, 29 { 30 ID: "96c3bda7-c82a-4f50-be73-ca7621794835", 31 Name: "vol-002", 32 }, 33 } 34 35 th.CheckDeepEquals(t, expected, actual) 36 } 37 38 func TestListAll(t *testing.T) { 39 th.SetupHTTP() 40 defer th.TeardownHTTP() 41 42 MockListResponse(t) 43 44 actual, err := volumes.List(client.ServiceClient(), volumes.ListOpts{}) 45 th.AssertNoErr(t, err) 46 47 expected := []volumes.Volume{ 48 { 49 ID: "289da7f8-6440-407c-9fb4-7db01ec49164", 50 Name: "vol-001", 51 }, 52 { 53 ID: "96c3bda7-c82a-4f50-be73-ca7621794835", 54 Name: "vol-002", 55 }, 56 } 57 58 th.CheckDeepEquals(t, expected, actual) 59 60 } 61 62 func TestGet(t *testing.T) { 63 th.SetupHTTP() 64 defer th.TeardownHTTP() 65 66 MockGetResponse(t) 67 68 actual, err := volumes.Get(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22") 69 th.AssertNoErr(t, err) 70 71 expected := &volumes.Volume{ 72 Status: "active", 73 Name: "vol-001", 74 Attachments: []map[string]interface{}{ 75 { 76 "attachment_id": "03987cd1-0ad5-40d1-9b2a-7cc48295d4fa", 77 "id": "47e9ecc5-4045-4ee3-9a4b-d859d546a0cf", 78 "volume_id": "6c80f8ac-e3e2-480c-8e6e-f1db92fe4bfe", 79 "server_id": "d1c4788b-9435-42e2-9b81-29f3be1cd01f", 80 "host_name": "mitaka", 81 "device": "/", 82 }, 83 }, 84 AvailabilityZone: "us-east1", 85 Bootable: "false", 86 CreatedAt: time.Date(2012, 2, 14, 20, 53, 07, 0, time.UTC), 87 Description: "Another volume.", 88 VolumeType: "289da7f8-6440-407c-9fb4-7db01ec49164", 89 SnapshotID: "", 90 SourceVolID: "", 91 Metadata: map[string]string{ 92 "contents": "junk", 93 }, 94 ID: "521752a6-acf6-4b2d-bc7a-119f9148cd8c", 95 Size: 30, 96 } 97 98 th.AssertDeepEquals(t, expected, actual) 99 } 100 101 func TestCreate(t *testing.T) { 102 th.SetupHTTP() 103 defer th.TeardownHTTP() 104 105 MockCreateResponse(t) 106 107 options := volumes.CreateOpts{ 108 Size: 75, 109 AvailabilityZone: "us-east1", 110 } 111 n, err := volumes.Create(client.ServiceClient(), options) 112 th.AssertNoErr(t, err) 113 114 th.AssertEquals(t, n.Size, 4) 115 th.AssertEquals(t, n.ID, "d32019d3-bc6e-4319-9c1d-6722fc136a22") 116 } 117 118 func TestDelete(t *testing.T) { 119 th.SetupHTTP() 120 defer th.TeardownHTTP() 121 122 MockDeleteResponse(t) 123 124 res := volumes.Delete(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22") 125 th.AssertNoErr(t, res) 126 } 127 128 func TestUpdate(t *testing.T) { 129 th.SetupHTTP() 130 defer th.TeardownHTTP() 131 132 MockUpdateResponse(t) 133 134 options := volumes.UpdateOpts{Name: "vol-002"} 135 v, err := volumes.Update(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22", options) 136 th.AssertNoErr(t, err) 137 th.CheckEquals(t, "vol-002", v.Name) 138 }