MCPcopy Create free account
hub / github.com/zalando/skipper / TestFastCgi

Function TestFastCgi

proxy/fastcgi/fastcgi_test.go:16–71  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func 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}

Callers

nothing calls this directly

Calls 12

RoundTripMethod · 0.95
NewRoundTripperFunction · 0.85
SetMethod · 0.65
CloseMethod · 0.65
ServeMethod · 0.65
StringMethod · 0.65
ErrorfMethod · 0.65
ErrorMethod · 0.65
HeaderMethod · 0.45
WriteHeaderMethod · 0.45
WriteMethod · 0.45
AddrMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…