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