github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/sharedfilesystems/v2/shareaccessrules/testing/requests_test.go (about) 1 package testing 2 3 import ( 4 "context" 5 "fmt" 6 "net/http" 7 "testing" 8 "time" 9 10 "github.com/vnpaycloud-console/gophercloud/v2/openstack/sharedfilesystems/v2/shareaccessrules" 11 th "github.com/vnpaycloud-console/gophercloud/v2/testhelper" 12 "github.com/vnpaycloud-console/gophercloud/v2/testhelper/client" 13 fake "github.com/vnpaycloud-console/gophercloud/v2/testhelper/client" 14 ) 15 16 func TestGet(t *testing.T) { 17 th.SetupHTTP() 18 defer th.TeardownHTTP() 19 20 MockGetResponse(t) 21 22 resp := shareaccessrules.Get(context.TODO(), client.ServiceClient(), "507bf114-36f2-4f56-8cf4-857985ca87c1") 23 th.AssertNoErr(t, resp.Err) 24 25 accessRule, err := resp.Extract() 26 th.AssertNoErr(t, err) 27 28 th.AssertDeepEquals(t, &shareaccessrules.ShareAccess{ 29 ShareID: "fb213952-2352-41b4-ad7b-2c4c69d13eef", 30 CreatedAt: time.Date(2018, 7, 17, 2, 1, 4, 0, time.UTC), 31 UpdatedAt: time.Date(2018, 7, 17, 2, 1, 4, 0, time.UTC), 32 AccessType: "cert", 33 AccessTo: "example.com", 34 AccessKey: "", 35 State: "error", 36 AccessLevel: "rw", 37 ID: "507bf114-36f2-4f56-8cf4-857985ca87c1", 38 Metadata: map[string]any{ 39 "key1": "value1", 40 "key2": "value2", 41 }, 42 }, accessRule) 43 } 44 45 func MockListResponse(t *testing.T) { 46 th.Mux.HandleFunc(shareAccessRulesEndpoint, func(w http.ResponseWriter, r *http.Request) { 47 th.TestMethod(t, r, "GET") 48 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 49 th.TestHeader(t, r, "Accept", "application/json") 50 w.Header().Add("Content-Type", "application/json") 51 w.WriteHeader(http.StatusOK) 52 fmt.Fprint(w, listResponse) 53 }) 54 }