7 // StubResponse struct with response status and body
8 type StubResponse struct {
13 // ServerStub with response map of path and StubResponse
14 // Ex: /arvados/v1/keep_services = arvadostest.StubResponse{200, string(`{}`)}
15 type ServerStub struct {
16 Responses map[string]StubResponse
19 func (stub *ServerStub) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
20 if req.URL.Path == "/redirect-loop" {
21 http.Redirect(resp, req, "/redirect-loop", http.StatusFound)
25 pathResponse := stub.Responses[req.URL.Path]
26 if pathResponse.Status == -1 {
27 http.Redirect(resp, req, "/redirect-loop", http.StatusFound)
28 } else if pathResponse.Body != "" {
29 resp.WriteHeader(pathResponse.Status)
30 resp.Write([]byte(pathResponse.Body))
33 resp.Write([]byte(``))