github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/apigw/v2/applications/testing/fixtures.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 "github.com/huaweicloud/golangsdk/openstack/apigw/v2/applications" 9 th "github.com/huaweicloud/golangsdk/testhelper" 10 "github.com/huaweicloud/golangsdk/testhelper/client" 11 ) 12 13 const ( 14 expectedCreateResponse = ` 15 { 16 "app_key": "6a4b1efab9374f599059ff3fe4382089", 17 "app_secret": "44e380875cf046feb29ab14694566239", 18 "app_type": "apig", 19 "creator": "USER", 20 "id": "50f768cf1c1f4389965aa58d255b2a65", 21 "name": "terraform_test", 22 "register_time": "2021-06-19T03:15:23.181079903Z", 23 "remark": "Created by script", 24 "status": 1, 25 "update_time": "2021-06-19T03:15:23.181080043Z" 26 }` 27 expectedGetResponse = ` 28 { 29 "app_key": "6a4b1efab9374f599059ff3fe4382089", 30 "app_secret": "44e380875cf046feb29ab14694566239", 31 "app_type": "apig", 32 "creator": "USER", 33 "id": "50f768cf1c1f4389965aa58d255b2a65", 34 "name": "terraform_test", 35 "register_time": "2021-06-19T03:15:23.181079903Z", 36 "remark": "Created by script", 37 "status": 1, 38 "update_time": "2021-06-19T03:15:23.181080043Z" 39 }` 40 expectedListResponse = ` 41 { 42 "apps": [ 43 { 44 "app_key": "6a4b1efab9374f599059ff3fe4382089", 45 "app_secret": "44e380875cf046feb29ab14694566239", 46 "app_type": "apig", 47 "bind_num": 0, 48 "creator": "USER", 49 "id": "50f768cf1c1f4389965aa58d255b2a65", 50 "name": "terraform_test", 51 "register_time": "2021-06-19T03:15:23.181079903Z", 52 "remark": "Created by script", 53 "status": 1, 54 "update_time": "2021-06-19T03:15:23.181080043Z" 55 } 56 ] 57 }` 58 expectedAddCodeResponse = ` 59 { 60 "app_code": "dGVzdEFQSUNvZGVPZlRoZUFQSUdBcHBsaWNhdGlvbjEyMzQ1Njc4OTAhQCMkJSstLz10b0Jhc2U2NA==", 61 "app_id": "5b9ac7b0b2434860a264e05d8c31470e", 62 "create_time": "2021-06-19T06:21:36.446251055Z", 63 "id": "5103639943e648599ef082285001c34e" 64 }` 65 66 expectedListCodeResponse = ` 67 { 68 "app_codes": [ 69 { 70 "app_code": "dGVzdEFQSUNvZGVPZlRoZUFQSUdBcHBsaWNhdGlvbjEyMzQ1Njc4OTAhQCMkJSstLz10b0Jhc2U2NA==", 71 "app_id": "5b9ac7b0b2434860a264e05d8c31470e", 72 "create_time": "2021-06-19T06:21:36.446251055Z", 73 "id": "5103639943e648599ef082285001c34e" 74 } 75 ] 76 }` 77 ) 78 79 var ( 80 appOpts = &applications.AppOpts{ 81 Name: "tf_acc_test_0618", 82 Description: "Created by script", 83 } 84 85 expectedCreateResponseData = &applications.Application{ 86 AppKey: "6a4b1efab9374f599059ff3fe4382089", 87 AppSecret: "44e380875cf046feb29ab14694566239", 88 Type: "apig", 89 Creator: "USER", 90 Id: "50f768cf1c1f4389965aa58d255b2a65", 91 Name: "terraform_test", 92 RegistraionTime: "2021-06-19T03:15:23.181079903Z", 93 Description: "Created by script", 94 Status: 1, 95 UpdateTime: "2021-06-19T03:15:23.181080043Z", 96 } 97 98 expectedGetResponseData = &applications.Application{ 99 AppKey: "6a4b1efab9374f599059ff3fe4382089", 100 AppSecret: "44e380875cf046feb29ab14694566239", 101 Type: "apig", 102 Creator: "USER", 103 Id: "50f768cf1c1f4389965aa58d255b2a65", 104 Name: "terraform_test", 105 RegistraionTime: "2021-06-19T03:15:23.181079903Z", 106 Description: "Created by script", 107 Status: 1, 108 UpdateTime: "2021-06-19T03:15:23.181080043Z", 109 } 110 111 expectedListResponseData = []applications.Application{ 112 { 113 AppKey: "6a4b1efab9374f599059ff3fe4382089", 114 AppSecret: "44e380875cf046feb29ab14694566239", 115 Type: "apig", 116 Creator: "USER", 117 Id: "50f768cf1c1f4389965aa58d255b2a65", 118 Name: "terraform_test", 119 RegistraionTime: "2021-06-19T03:15:23.181079903Z", 120 Description: "Created by script", 121 Status: 1, 122 UpdateTime: "2021-06-19T03:15:23.181080043Z", 123 }, 124 } 125 126 appCodeOpts = applications.AppCodeOpts{ 127 AppCode: "dGVzdEFQSUNvZGVPZlRoZUFQSUdBcHBsaWNhdGlvbjEyMzQ1Njc4OTAhQCMkJSstLz10b0Jhc2U2NA==", 128 } 129 130 expectedAddCodeResponseData = &applications.AppCode{ 131 AppId: "5b9ac7b0b2434860a264e05d8c31470e", 132 Code: "dGVzdEFQSUNvZGVPZlRoZUFQSUdBcHBsaWNhdGlvbjEyMzQ1Njc4OTAhQCMkJSstLz10b0Jhc2U2NA==", 133 CreateTime: "2021-06-19T06:21:36.446251055Z", 134 Id: "5103639943e648599ef082285001c34e", 135 } 136 137 expectedListCodeResponseData = []applications.AppCode{ 138 { 139 AppId: "5b9ac7b0b2434860a264e05d8c31470e", 140 Code: "dGVzdEFQSUNvZGVPZlRoZUFQSUdBcHBsaWNhdGlvbjEyMzQ1Njc4OTAhQCMkJSstLz10b0Jhc2U2NA==", 141 CreateTime: "2021-06-19T06:21:36.446251055Z", 142 Id: "5103639943e648599ef082285001c34e", 143 }, 144 } 145 ) 146 147 func handleV2ApplicationCreate(t *testing.T) { 148 th.Mux.HandleFunc("/instances/c5faacb524d148b59ddd448dd02d016a/apps", 149 func(w http.ResponseWriter, r *http.Request) { 150 th.TestMethod(t, r, "POST") 151 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 152 w.Header().Add("Content-Type", "application/json") 153 w.WriteHeader(http.StatusCreated) 154 _, _ = fmt.Fprint(w, expectedCreateResponse) 155 }) 156 } 157 158 func handleV2ApplicationGet(t *testing.T) { 159 th.Mux.HandleFunc("/instances/c5faacb524d148b59ddd448dd02d016a/apps/50f768cf1c1f4389965aa58d255b2a65", 160 func(w http.ResponseWriter, r *http.Request) { 161 th.TestMethod(t, r, "GET") 162 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 163 w.Header().Add("Content-Type", "application/json") 164 w.WriteHeader(http.StatusOK) 165 _, _ = fmt.Fprint(w, expectedGetResponse) 166 }) 167 } 168 169 func handleV2ApplicationList(t *testing.T) { 170 th.Mux.HandleFunc("/instances/c5faacb524d148b59ddd448dd02d016a/apps", func(w http.ResponseWriter, r *http.Request) { 171 th.TestMethod(t, r, "GET") 172 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 173 w.Header().Add("Content-Type", "application/json") 174 w.WriteHeader(http.StatusOK) 175 _, _ = fmt.Fprint(w, expectedListResponse) 176 }) 177 } 178 179 func handleV2ApplicationUpdate(t *testing.T) { 180 th.Mux.HandleFunc("/instances/c5faacb524d148b59ddd448dd02d016a/apps/50f768cf1c1f4389965aa58d255b2a65", 181 func(w http.ResponseWriter, r *http.Request) { 182 th.TestMethod(t, r, "PUT") 183 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 184 w.Header().Add("Content-Type", "application/json") 185 w.WriteHeader(http.StatusOK) 186 _, _ = fmt.Fprint(w, expectedGetResponse) 187 }) 188 } 189 190 func handleV2ApplicationDelete(t *testing.T) { 191 th.Mux.HandleFunc("/instances/c5faacb524d148b59ddd448dd02d016a/apps/50f768cf1c1f4389965aa58d255b2a65", 192 func(w http.ResponseWriter, r *http.Request) { 193 th.TestMethod(t, r, "DELETE") 194 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 195 w.Header().Add("Content-Type", "application/json") 196 w.WriteHeader(http.StatusNoContent) 197 }) 198 } 199 200 func handleV2ApplicationCodeAdd(t *testing.T) { 201 th.Mux.HandleFunc("/instances/c5faacb524d148b59ddd448dd02d016a/apps/50f768cf1c1f4389965aa58d255b2a65/app-codes", 202 func(w http.ResponseWriter, r *http.Request) { 203 th.TestMethod(t, r, "POST") 204 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 205 w.Header().Add("Content-Type", "application/json") 206 w.WriteHeader(http.StatusCreated) 207 _, _ = fmt.Fprint(w, expectedAddCodeResponse) 208 }) 209 } 210 211 func handleV2ApplicationCodeAutoGenerate(t *testing.T) { 212 th.Mux.HandleFunc("/instances/c5faacb524d148b59ddd448dd02d016a/apps/50f768cf1c1f4389965aa58d255b2a65/app-codes", 213 func(w http.ResponseWriter, r *http.Request) { 214 th.TestMethod(t, r, "PUT") 215 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 216 w.Header().Add("Content-Type", "application/json") 217 w.WriteHeader(http.StatusCreated) 218 _, _ = fmt.Fprint(w, expectedAddCodeResponse) 219 }) 220 } 221 222 func handleV2ApplicationCodeGet(t *testing.T) { 223 th.Mux.HandleFunc("/instances/c5faacb524d148b59ddd448dd02d016a/apps/50f768cf1c1f4389965aa58d255b2a65/app-codes/f284119e19f34d4caead4dd94114a7f4", func(w http.ResponseWriter, r *http.Request) { 224 th.TestMethod(t, r, "GET") 225 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 226 w.Header().Add("Content-Type", "application/json") 227 w.WriteHeader(http.StatusCreated) 228 _, _ = fmt.Fprint(w, expectedAddCodeResponse) 229 }) 230 } 231 232 func handleV2ApplicationCodeList(t *testing.T) { 233 th.Mux.HandleFunc("/instances/c5faacb524d148b59ddd448dd02d016a/apps/50f768cf1c1f4389965aa58d255b2a65/app-codes", 234 func(w http.ResponseWriter, r *http.Request) { 235 th.TestMethod(t, r, "GET") 236 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 237 w.Header().Add("Content-Type", "application/json") 238 w.WriteHeader(http.StatusOK) 239 _, _ = fmt.Fprint(w, expectedListCodeResponse) 240 }) 241 } 242 243 func handleV2ApplicationCodeRemove(t *testing.T) { 244 th.Mux.HandleFunc("/instances/c5faacb524d148b59ddd448dd02d016a/apps/50f768cf1c1f4389965aa58d255b2a65/app-codes"+ 245 "/f284119e19f34d4caead4dd94114a7f4", func(w http.ResponseWriter, r *http.Request) { 246 th.TestMethod(t, r, "DELETE") 247 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 248 w.Header().Add("Content-Type", "application/json") 249 w.WriteHeader(http.StatusNoContent) 250 }) 251 }