1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
11 // StubResponse struct with response status and body
12 type StubResponse struct {
17 // ServerStub with response map of path and StubResponse
18 // Ex: /arvados/v1/keep_services = arvadostest.StubResponse{200, string(`{}`)}
19 type ServerStub struct {
20 Responses map[string]StubResponse
23 func (stub *ServerStub) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
24 if req.URL.Path == "/redirect-loop" {
25 http.Redirect(resp, req, "/redirect-loop", http.StatusFound)
29 pathResponse := stub.Responses[req.URL.Path]
30 if pathResponse.Status == -1 {
31 http.Redirect(resp, req, "/redirect-loop", http.StatusFound)
32 } else if pathResponse.Body != "" {
33 resp.WriteHeader(pathResponse.Status)
34 resp.Write([]byte(pathResponse.Body))
37 resp.Write([]byte(``))