(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func TestFastCgi(t *testing.T) { |
| 17 | payload := []byte("Hello, World!") |
| 18 | http.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) { |
| 19 | w.Header().Set("X-Test-Response-Header", "response header value") |
| 20 | |
| 21 | if len(payload) <= 0 { |
| 22 | return |
| 23 | } |
| 24 | |
| 25 | w.Header().Set("Content-Type", "text/plain") |
| 26 | w.Header().Set("Content-Length", strconv.Itoa(len(payload))) |
| 27 | w.WriteHeader(http.StatusOK) |
| 28 | |
| 29 | w.Write(payload) |
| 30 | }) |
| 31 | |
| 32 | l, err := net.Listen("tcp", "127.0.0.1:0") |
| 33 | if err != nil { |
| 34 | panic(err) |
| 35 | } |
| 36 | defer l.Close() |
| 37 | |
| 38 | go fcgi.Serve(l, nil) |
| 39 | |
| 40 | u, _ := url.ParseRequestURI("http://www.example.org/hello") |
| 41 | |
| 42 | rt, err := NewRoundTripper(&logging.DefaultLog{}, l.Addr().String(), "index.php") |
| 43 | if err != nil { |
| 44 | t.Errorf("could not create roundtripper: %v", err) |
| 45 | |
| 46 | return |
| 47 | } |
| 48 | |
| 49 | r := &http.Request{ |
| 50 | URL: u, |
| 51 | Method: "GET", |
| 52 | Proto: "HTTP/1.0", |
| 53 | } |
| 54 | |
| 55 | response, err := rt.RoundTrip(r) |
| 56 | if err != nil { |
| 57 | t.Errorf("could not create roundtrip: %v", err) |
| 58 | |
| 59 | return |
| 60 | } |
| 61 | b, err := io.ReadAll(response.Body) |
| 62 | if err != nil { |
| 63 | t.Error(err) |
| 64 | |
| 65 | return |
| 66 | } |
| 67 | |
| 68 | if response.StatusCode != http.StatusOK || !bytes.Equal(b, payload) { |
| 69 | t.Error("wrong routing 1") |
| 70 | } |
| 71 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…