github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/rts/v1/stacktemplates/testing/fixtures.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 th "github.com/huaweicloud/golangsdk/testhelper" 9 fake "github.com/huaweicloud/golangsdk/testhelper/client" 10 ) 11 12 // GetExpected represents the expected object from a Get request. 13 var GetExpected = "{\n \"description\": \"Simple template to test heat commands\",\n \"heat_template_version\": \"2013-05-23\",\n \"parameters\": {\n \"flavor\": {\n \"default\": \"m1.tiny\",\n \"type\": \"string\"\n }\n },\n \"resources\": {\n \"hello_world\": {\n \"properties\": {\n \"flavor\": {\n \"get_param\": \"flavor\"\n },\n \"image\": \"ad091b52-742f-469e-8f3c-fd81cadf0743\",\n \"key_name\": \"heat_key\"\n },\n \"type\": \"OS::Nova::Server\"\n }\n }\n}" 14 15 // GetOutput represents the response body from a Get request. 16 const GetOutput = ` 17 { 18 "heat_template_version": "2013-05-23", 19 "description": "Simple template to test heat commands", 20 "parameters": { 21 "flavor": { 22 "default": "m1.tiny", 23 "type": "string" 24 } 25 }, 26 "resources": { 27 "hello_world": { 28 "type": "OS::Nova::Server", 29 "properties": { 30 "key_name": "heat_key", 31 "flavor": { 32 "get_param": "flavor" 33 }, 34 "image": "ad091b52-742f-469e-8f3c-fd81cadf0743" 35 } 36 } 37 } 38 }` 39 40 // HandleGetSuccessfully creates an HTTP handler at `/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87/template` 41 // on the test handler mux that responds with a `Get` response. 42 func HandleGetSuccessfully(t *testing.T, output string) { 43 th.Mux.HandleFunc("/stacks/postman_stack/16ef0584-4458-41eb-87c8-0dc8d5f66c87/template", func(w http.ResponseWriter, r *http.Request) { 44 th.TestMethod(t, r, "GET") 45 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 46 th.TestHeader(t, r, "Accept", "application/json") 47 48 w.Header().Set("Content-Type", "application/json") 49 w.WriteHeader(http.StatusOK) 50 fmt.Fprintf(w, output) 51 }) 52 }