Skip to content

Commit 858c7fd

Browse files
author
miktwon
committed
add test for fpm
1 parent 92a86ef commit 858c7fd

File tree

6 files changed

+118
-3
lines changed

6 files changed

+118
-3
lines changed

.travis.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
language: go
22

3+
sudo: required
4+
35
go:
46
- 1.8
57

8+
before_install:
9+
- sudo apt-get -qq update
10+
- sudo apt-get install -y php5-fpm
11+
612
install:
713
- wget "https://github.com/Masterminds/glide/releases/download/0.10.2/glide-0.10.2-linux-amd64.tar.gz"
814
- mkdir -p $HOME/bin
915
- tar -vxz -C $HOME/bin --strip=1 -f glide-0.10.2-linux-amd64.tar.gz
1016
- export PATH="$HOME/bin:$PATH"
1117
- glide i
1218
- go build
19+
- cp fpmTest/test.php /tmp/
20+
- sudo /etc/init.d/php5-fpm stop
21+
- sudo ./docker-fpm-wrapper --fpm /usr/sbin/php5-fpm 2> /tmp/stderr &
1322

14-
script: go test $(glide novendor)
23+
script:
24+
- go test $(glide novendor)
25+
- go build -o fpmTest/fpmTest fpmTest/main.go
26+
- sudo ./fpmTest/fpmTest
1527

1628
deploy:
1729
provider: releases

fpmTest/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fpmTest

fpmTest/main.go

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package main
2+
3+
import (
4+
"encoding/hex"
5+
"fmt"
6+
"io/ioutil"
7+
"log"
8+
"net"
9+
"os"
10+
"time"
11+
12+
fcgiclient "github.com/tomasen/fcgi_client"
13+
)
14+
15+
const (
16+
fpmSocket = "/var/run/php5-fpm.sock"
17+
phpTestFile = "/tmp/test.php"
18+
19+
fpmWrapperSocket = "/tmp/fpm-wrapper.sock"
20+
fpmWrapperStderr = "/tmp/stderr"
21+
)
22+
23+
const (
24+
testData1 = "en taro adun en taro tassadar en taro zeratul"
25+
testData2 = "power overwhelming"
26+
)
27+
28+
func main() {
29+
testFPMExecute()
30+
testWrapperSocket()
31+
}
32+
33+
func testFPMExecute() {
34+
log.Println("testFPMExecute:")
35+
scriptFilename := phpTestFile
36+
if scriptFilename[0] != '/' {
37+
cwd, err := os.Getwd()
38+
if err != nil {
39+
log.Fatalln("os.Getwd:", err)
40+
}
41+
scriptFilename = fmt.Sprintf("%s/%s", cwd, scriptFilename)
42+
}
43+
44+
env := map[string]string{
45+
"SCRIPT_FILENAME": scriptFilename,
46+
}
47+
log.Println(env)
48+
49+
fcgi, err := fcgiclient.Dial("unix", fpmSocket)
50+
if err != nil {
51+
log.Fatalln("fcgiclient.Dial:", err)
52+
}
53+
54+
resp, err := fcgi.Get(env)
55+
if err != nil {
56+
log.Fatalln("fcgi.Get:", err)
57+
}
58+
59+
content, err := ioutil.ReadAll(resp.Body)
60+
if err != nil {
61+
log.Fatalln("ioutil.ReadAll:", err)
62+
}
63+
64+
if string(content) != testData1 {
65+
log.Fatalln("content not match:", string(content), "dump:\n", hex.Dump(content))
66+
}
67+
68+
log.Println("content is match")
69+
}
70+
71+
func testWrapperSocket() {
72+
log.Println("testWrapperSocket:")
73+
conn, err := net.Dial("unix", fpmWrapperSocket)
74+
defer conn.Close()
75+
if err != nil {
76+
log.Fatalln("net.Dial:", err)
77+
}
78+
79+
_, err = conn.Write([]byte(testData2))
80+
if err != nil {
81+
log.Fatalln("conn.Write:", err)
82+
}
83+
err = conn.Close()
84+
if err != nil {
85+
log.Fatalln("conn.Close:", err)
86+
}
87+
88+
time.Sleep(100 * time.Millisecond)
89+
stderrData, err := ioutil.ReadFile(fpmWrapperStderr)
90+
if err != nil {
91+
log.Fatalln("ioutil.ReadFile:", err)
92+
}
93+
94+
if string(stderrData) != testData2 {
95+
log.Fatalln("content not match:", string(stderrData), "dump:\n", hex.Dump(stderrData))
96+
}
97+
}

fpmTest/test.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
echo "en taro adun en taro tassadar en taro zeratul";

glide.lock

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

glide.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ package: github.com/code-tool/docker-fpm-wrapper
22
import:
33
- package: github.com/FZambia/viper-lite
44
- package: github.com/spf13/pflag
5+
- package: github.com/tomasen/fcgi_client

0 commit comments

Comments
 (0)