github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/apigw/v2/authorizers/testing/fixtures.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 "github.com/huaweicloud/golangsdk" 9 "github.com/huaweicloud/golangsdk/openstack/apigw/v2/authorizers" 10 th "github.com/huaweicloud/golangsdk/testhelper" 11 "github.com/huaweicloud/golangsdk/testhelper/client" 12 ) 13 14 const ( 15 expectedGetResponse = ` 16 { 17 "authorizer_type": "FUNC", 18 "authorizer_uri": "urn:fss:ae-ad-1:0c22dd73f6005a032f3ec0061de74dbf:function:default:terraform_test", 19 "create_time": "2021-07-17T08:33:35Z", 20 "id": "3b9a3dda163f4ebb8fdcbbf786bffa20", 21 "name": "terraform_test", 22 "need_body": false, 23 "ttl": 60, 24 "type": "BACKEND", 25 "user_data": "" 26 } 27 ` 28 29 expectedListResponse = ` 30 { 31 "authorizer_list": [ 32 { 33 "authorizer_type": "FUNC", 34 "authorizer_uri": "urn:fss:ae-ad-1:0c22dd73f6005a032f3ec0061de74dbf:function:default:terraform_test", 35 "create_time": "2021-07-17T08:33:35Z", 36 "id": "3b9a3dda163f4ebb8fdcbbf786bffa20", 37 "name": "terraform_test", 38 "need_body": false, 39 "ttl": 60, 40 "type": "BACKEND", 41 "user_data": "" 42 } 43 ], 44 "size": 1, 45 "total": 1 46 }` 47 ) 48 49 var ( 50 createOpts = authorizers.CustomAuthOpts{ 51 Name: "terraform_test", 52 Type: "BACKEND", 53 AuthorizerType: "FUNC", 54 AuthorizerURI: "urn:fss:ae-ad-1\\:0c22dd73f6005a032f3ec0061de74dbf:function:default:terraform_test", 55 IsBodySend: golangsdk.Disabled, 56 TTL: golangsdk.IntToPointer(60), 57 UserData: golangsdk.MaybeString(""), 58 } 59 60 expectedGetResponseData = &authorizers.CustomAuthorizer{ 61 Name: "terraform_test", 62 Type: "BACKEND", 63 AuthorizerType: "FUNC", 64 AuthorizerURI: "urn:fss:ae-ad-1:0c22dd73f6005a032f3ec0061de74dbf:function:default:terraform_test", 65 CreateTime: "2021-07-17T08:33:35Z", 66 ID: "3b9a3dda163f4ebb8fdcbbf786bffa20", 67 IsBodySend: false, 68 TTL: 60, 69 UserData: "", 70 } 71 72 listOpts = &authorizers.ListOpts{ 73 Name: "terraform_test", 74 } 75 76 expectedListResponseData = []authorizers.CustomAuthorizer{ 77 { 78 Name: "terraform_test", 79 Type: "BACKEND", 80 AuthorizerType: "FUNC", 81 AuthorizerURI: "urn:fss:ae-ad-1:0c22dd73f6005a032f3ec0061de74dbf:function:default:terraform_test", 82 CreateTime: "2021-07-17T08:33:35Z", 83 ID: "3b9a3dda163f4ebb8fdcbbf786bffa20", 84 IsBodySend: false, 85 TTL: 60, 86 UserData: "", 87 }, 88 } 89 ) 90 91 func handleV2CustomAuthorizerCreate(t *testing.T) { 92 th.Mux.HandleFunc("/instances/6da953fe33d44650a067e43a4593368b/authorizers", 93 func(w http.ResponseWriter, r *http.Request) { 94 th.TestMethod(t, r, "POST") 95 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 96 w.Header().Add("Content-Type", "application/json") 97 w.WriteHeader(http.StatusCreated) 98 _, _ = fmt.Fprint(w, expectedGetResponse) 99 }) 100 } 101 102 func handleV2CustomAuthorizerGet(t *testing.T) { 103 th.Mux.HandleFunc("/instances/6da953fe33d44650a067e43a4593368b/authorizers/0d2a523974a14fe1a25c1bc2f61b2d9d", 104 func(w http.ResponseWriter, r *http.Request) { 105 th.TestMethod(t, r, "GET") 106 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 107 w.Header().Add("Content-Type", "application/json") 108 w.WriteHeader(http.StatusOK) 109 _, _ = fmt.Fprint(w, expectedGetResponse) 110 }) 111 } 112 113 func handleV2CustomAuthorizerList(t *testing.T) { 114 th.Mux.HandleFunc("/instances/6da953fe33d44650a067e43a4593368b/authorizers", 115 func(w http.ResponseWriter, r *http.Request) { 116 th.TestMethod(t, r, "GET") 117 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 118 w.Header().Add("Content-Type", "application/json") 119 w.WriteHeader(http.StatusOK) 120 _, _ = fmt.Fprint(w, expectedListResponse) 121 }) 122 } 123 124 func handleV2CustomAuthorizerUpdate(t *testing.T) { 125 th.Mux.HandleFunc("/instances/6da953fe33d44650a067e43a4593368b/authorizers/0d2a523974a14fe1a25c1bc2f61b2d9d", 126 func(w http.ResponseWriter, r *http.Request) { 127 th.TestMethod(t, r, "PUT") 128 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 129 w.Header().Add("Content-Type", "application/json") 130 w.WriteHeader(http.StatusOK) 131 _, _ = fmt.Fprint(w, expectedGetResponse) 132 }) 133 } 134 135 func handleV2CustomAuthorizerDelete(t *testing.T) { 136 th.Mux.HandleFunc("/instances/6da953fe33d44650a067e43a4593368b/authorizers/0d2a523974a14fe1a25c1bc2f61b2d9d", 137 func(w http.ResponseWriter, r *http.Request) { 138 th.TestMethod(t, r, "DELETE") 139 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 140 w.Header().Add("Content-Type", "application/json") 141 w.WriteHeader(http.StatusNoContent) 142 }) 143 }