-type StatusAndBody struct {
- respStatus int
- responseBody string
-}
-
-type APIStub struct {
- data map[string]StatusAndBody
-}
-
-func (stub *APIStub) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
- if req.URL.Path == "/redirect-loop" {
- http.Redirect(resp, req, "/redirect-loop", http.StatusFound)
- return
- }
-
- pathResponse := stub.data[req.URL.Path]
- if pathResponse.responseBody != "" {
- if pathResponse.respStatus == -1 {
- http.Redirect(resp, req, "/redirect-loop", http.StatusFound)
- } else {
- resp.WriteHeader(pathResponse.respStatus)
- resp.Write([]byte(pathResponse.responseBody))
- }
- } else {
- resp.WriteHeader(500)
- resp.Write([]byte(``))
- }
-}
-
-type KeepServerStub struct {
- data map[string]StatusAndBody
-}
-
-func (stub *KeepServerStub) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
- if req.URL.Path == "/redirect-loop" {
- http.Redirect(resp, req, "/redirect-loop", http.StatusFound)
- return
- }
-
- pathResponse := stub.data[req.URL.Path]
- if pathResponse.responseBody != "" {
- if pathResponse.respStatus == -1 {
- http.Redirect(resp, req, "/redirect-loop", http.StatusFound)
- } else {
- resp.WriteHeader(pathResponse.respStatus)
- resp.Write([]byte(pathResponse.responseBody))
- }
- } else {
- resp.WriteHeader(500)
- resp.Write([]byte(``))
- }
-}
-