(w http.ResponseWriter, r *http.Request)
| 41 | } |
| 42 | |
| 43 | func (p *pilotStubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
| 44 | p.Lock() |
| 45 | if r.Method == p.States[0].wantMethod { |
| 46 | if r.URL.Path == p.States[0].wantPath { |
| 47 | defer r.Body.Close() |
| 48 | body, _ := io.ReadAll(r.Body) |
| 49 | if err := util.Compare(body, p.States[0].wantBody); err == nil { |
| 50 | w.WriteHeader(p.States[0].StatusCode) |
| 51 | w.Write([]byte(p.States[0].Response)) |
| 52 | } else { |
| 53 | w.WriteHeader(http.StatusBadRequest) |
| 54 | w.Write([]byte(fmt.Sprintf("wanted body %q got %q", string(p.States[0].wantBody), string(body)))) |
| 55 | } |
| 56 | } else { |
| 57 | w.WriteHeader(http.StatusBadRequest) |
| 58 | w.Write([]byte(fmt.Sprintf("wanted path %q got %q", p.States[0].wantPath, r.URL.Path))) |
| 59 | } |
| 60 | } else { |
| 61 | w.WriteHeader(http.StatusBadRequest) |
| 62 | w.Write([]byte(fmt.Sprintf("wanted method %q got %q", p.States[0].wantMethod, r.Method))) |
| 63 | } |
| 64 | |
| 65 | p.States[0] = ptr.Empty[pilotStubState]() |
| 66 | p.States = p.States[1:] |
| 67 | p.Unlock() |
| 68 | } |
| 69 | |
| 70 | func Test_command_do(t *testing.T) { |
| 71 | tests := []struct { |
no test coverage detected