github.com/gophercloud/gophercloud@v1.11.0/openstack/sharedfilesystems/v2/messages/testing/requests_test.go (about) 1 package testing 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/messages" 8 th "github.com/gophercloud/gophercloud/testhelper" 9 "github.com/gophercloud/gophercloud/testhelper/client" 10 ) 11 12 // Verifies that message deletion works 13 func TestDelete(t *testing.T) { 14 th.SetupHTTP() 15 defer th.TeardownHTTP() 16 17 MockDeleteResponse(t) 18 19 res := messages.Delete(client.ServiceClient(), "messageID") 20 th.AssertNoErr(t, res.Err) 21 } 22 23 // Verifies that messages can be listed correctly 24 func TestList(t *testing.T) { 25 th.SetupHTTP() 26 defer th.TeardownHTTP() 27 28 MockListResponse(t) 29 30 allPages, err := messages.List(client.ServiceClient(), &messages.ListOpts{}).AllPages() 31 th.AssertNoErr(t, err) 32 actual, err := messages.ExtractMessages(allPages) 33 th.AssertNoErr(t, err) 34 expected := []messages.Message{ 35 { 36 ResourceID: "0d0b883f-95ef-406c-b930-55612ee48a6d", 37 MessageLevel: "ERROR", 38 UserMessage: "create: Could not find an existing share server or allocate one on the share network provided. You may use a different share network, or verify the network details in the share network and retry your request. If this doesn't work, contact your administrator to troubleshoot issues with your network.", 39 ExpiresAt: time.Date(2019, 1, 6, 8, 53, 38, 0, time.UTC), 40 ID: "143a6cc2-1998-44d0-8356-22070b0ebdaa", 41 CreatedAt: time.Date(2018, 12, 7, 8, 53, 38, 0, time.UTC), 42 DetailID: "004", 43 RequestID: "req-21767eee-22ca-40a4-b6c0-ae7d35cd434f", 44 ProjectID: "a5e9d48232dc4aa59a716b5ced963584", 45 ResourceType: "SHARE", 46 ActionID: "002", 47 }, 48 { 49 ResourceID: "4336d74f-3bdc-4f27-9657-c01ec63680bf", 50 MessageLevel: "ERROR", 51 UserMessage: "create: Could not find an existing share server or allocate one on the share network provided. You may use a different share network, or verify the network details in the share network and retry your request. If this doesn't work, contact your administrator to troubleshoot issues with your network.", 52 ExpiresAt: time.Date(2019, 1, 6, 8, 53, 34, 0, time.UTC), 53 ID: "2076373e-13a7-4b84-9e67-15ce8cceaff8", 54 CreatedAt: time.Date(2018, 12, 7, 8, 53, 34, 0, time.UTC), 55 DetailID: "004", 56 RequestID: "req-957792ed-f38b-42db-a86a-850f815cbbe9", 57 ProjectID: "a5e9d48232dc4aa59a716b5ced963584", 58 ResourceType: "SHARE", 59 ActionID: "002", 60 }, 61 } 62 63 th.CheckDeepEquals(t, expected, actual) 64 } 65 66 // Verifies that messages list can be called with query parameters 67 func TestFilteredList(t *testing.T) { 68 th.SetupHTTP() 69 defer th.TeardownHTTP() 70 71 MockFilteredListResponse(t) 72 73 options := &messages.ListOpts{ 74 RequestID: "req-21767eee-22ca-40a4-b6c0-ae7d35cd434f", 75 } 76 77 allPages, err := messages.List(client.ServiceClient(), options).AllPages() 78 th.AssertNoErr(t, err) 79 actual, err := messages.ExtractMessages(allPages) 80 th.AssertNoErr(t, err) 81 expected := []messages.Message{ 82 { 83 ResourceID: "4336d74f-3bdc-4f27-9657-c01ec63680bf", 84 MessageLevel: "ERROR", 85 UserMessage: "create: Could not find an existing share server or allocate one on the share network provided. You may use a different share network, or verify the network details in the share network and retry your request. If this doesn't work, contact your administrator to troubleshoot issues with your network.", 86 ExpiresAt: time.Date(2019, 1, 6, 8, 53, 34, 0, time.UTC), 87 ID: "2076373e-13a7-4b84-9e67-15ce8cceaff8", 88 CreatedAt: time.Date(2018, 12, 7, 8, 53, 34, 0, time.UTC), 89 DetailID: "004", 90 RequestID: "req-957792ed-f38b-42db-a86a-850f815cbbe9", 91 ProjectID: "a5e9d48232dc4aa59a716b5ced963584", 92 ResourceType: "SHARE", 93 ActionID: "002", 94 }, 95 } 96 97 th.CheckDeepEquals(t, expected, actual) 98 } 99 100 // Verifies that it is possible to get a message 101 func TestGet(t *testing.T) { 102 th.SetupHTTP() 103 defer th.TeardownHTTP() 104 105 MockGetResponse(t) 106 107 expected := messages.Message{ 108 ResourceID: "4336d74f-3bdc-4f27-9657-c01ec63680bf", 109 MessageLevel: "ERROR", 110 UserMessage: "create: Could not find an existing share server or allocate one on the share network provided. You may use a different share network, or verify the network details in the share network and retry your request. If this doesn't work, contact your administrator to troubleshoot issues with your network.", 111 ExpiresAt: time.Date(2019, 1, 6, 8, 53, 34, 0, time.UTC), 112 ID: "2076373e-13a7-4b84-9e67-15ce8cceaff8", 113 CreatedAt: time.Date(2018, 12, 7, 8, 53, 34, 0, time.UTC), 114 DetailID: "004", 115 RequestID: "req-957792ed-f38b-42db-a86a-850f815cbbe9", 116 ProjectID: "a5e9d48232dc4aa59a716b5ced963584", 117 ResourceType: "SHARE", 118 ActionID: "002", 119 } 120 121 n, err := messages.Get(client.ServiceClient(), "2076373e-13a7-4b84-9e67-15ce8cceaff8").Extract() 122 th.AssertNoErr(t, err) 123 124 th.CheckDeepEquals(t, &expected, n) 125 }