MCPcopy
hub / github.com/istio/istio / ServeHTTP

Method ServeHTTP

pilot/pkg/request/command_test.go:43–68  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

41}
42
43func (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
70func Test_command_do(t *testing.T) {
71 tests := []struct {

Callers 11

withDelayFunction · 0.45
initServersMethod · 0.45
metricsMiddlewareFunction · 0.45
testEdszFunction · 0.45
getSyncStatusFunction · 0.45
getConfigDumpFunction · 0.45
TestDebugHandlersFunction · 0.45
processDebugRequestFunction · 0.45

Calls 4

CompareFunction · 0.92
WriteHeaderMethod · 0.80
CloseMethod · 0.65
WriteMethod · 0.65

Tested by

no test coverage detected