MCPcopy Index your code
hub / github.com/apache/cloudstack-go / CreateTestServer

Function CreateTestServer

test/cloudstack_test.go:43–77  ·  view source on GitHub ↗
(t *testing.T, responses map[string]json.RawMessage)

Source from the content-addressed store, hash-verified

41)
42
43func CreateTestServer(t *testing.T, responses map[string]json.RawMessage) *httptest.Server {
44 return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
45 response := responses[r.FormValue("command")]
46 rawResult, _ := getRawValue(response)
47
48 var result map[string]json.RawMessage
49 err := json.Unmarshal(rawResult, &result)
50 if err != nil {
51 fmt.Fprintln(w, string(response))
52 return
53 }
54
55 // Since we're using a sync client, pass the job result as the response
56 val, ok := result["jobresult"]
57 if !ok {
58 fmt.Fprintln(w, string(response))
59 return
60 }
61
62 err = json.Unmarshal(val, &result)
63 if err != nil {
64 fmt.Fprintln(w, string(response))
65 return
66 }
67
68 // Handle success response separately
69 if _, ok := result["success"]; ok {
70 fmt.Fprintf(w, `{"jobresult":{"success":true}}`)
71 return
72 }
73
74 fmt.Fprintln(w, string(val))
75
76 }))
77}
78
79func getRawValue(b json.RawMessage) (json.RawMessage, error) {
80 var m map[string]json.RawMessage

Callers 15

TestCertificateServiceFunction · 0.85
TestMetricsServiceFunction · 0.85
TestAutoScaleServiceFunction · 0.85
TestLimitServiceFunction · 0.85
TestNiciraNVPServiceFunction · 0.85
TestMiscServiceFunction · 0.85
TestRouterServiceFunction · 0.85
TestWebhookServiceFunction · 0.85
TestNetworkServiceFunction · 0.85
TestInternalLBServiceFunction · 0.85

Calls 1

getRawValueFunction · 0.70

Tested by

no test coverage detected