-
Notifications
You must be signed in to change notification settings - Fork 7
/
py_test.go
97 lines (89 loc) · 2.16 KB
/
py_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// +build !smoke
package gofcgisrv
import (
"errors"
"net"
"os"
"os/exec"
"strings"
"testing"
"time"
)
func waitForConn(addr string, timeout time.Duration) error {
ticker := time.NewTicker(time.Millisecond * 10)
timer := time.NewTimer(timeout)
defer timer.Stop()
defer ticker.Stop()
for {
select {
case <-ticker.C:
c, err := net.Dial("tcp", addr)
if err == nil {
c.Close()
return nil
}
case <-timer.C:
return errors.New("timeout")
}
}
panic("Unreachable")
}
func TestPyServer(t *testing.T) {
cmd := exec.Command("python", "./testdata/cgi_test.py", "--host=127.0.0.1", "--port=9001")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Start()
if err != nil {
t.Fatalf("Error running cgi_test.py: %v", err)
}
defer cmd.Process.Kill()
waitForConn("127.0.0.1:9001", time.Second)
s := NewFCGI("127.0.0.1:9001")
testRequester(t, httpTestData{
name: "py fastcgi",
f: s,
body: strings.NewReader("This is a test"),
status: 200,
expected: "This is a test",
})
}
func TestPyCGI(t *testing.T) {
s := NewCGI("python", "./testdata/cgi_test.py", "--cgi")
testRequester(t, httpTestData{
name: "py cgi",
f: s,
body: strings.NewReader("This is a test"),
status: 200,
expected: "This is a test",
})
}
func TestPySCGI(t *testing.T) {
cmd := exec.Command("python", "./testdata/cgi_test.py", "--scgi", "--host=127.0.0.1", "--port=9002")
// flup barfs some output. Why?? Seems wrong to me.
err := cmd.Start()
if err != nil {
t.Fatalf("Error running cgi_test.py: %v", err)
}
defer cmd.Process.Kill()
waitForConn("127.0.0.1:9002", time.Second)
s := NewSCGI("127.0.0.1:9002")
testRequester(t, httpTestData{
name: "py scgi",
f: s,
body: strings.NewReader("This is a test"),
status: 200,
expected: "This is a test",
})
}
func TestPyFcgiStdin(t *testing.T) {
s := NewFCGIStdin("python", "./testdata/cgi_test.py", "--fcgi")
s.dialer.(*StdinDialer).Start()
defer s.dialer.(*StdinDialer).Close()
testRequester(t, httpTestData{
name: "py fastcgi stdin",
f: s,
body: strings.NewReader("This is a test"),
status: 200,
expected: "This is a test",
})
}