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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
package gzip
import (
"encoding/json"
"github.com/sirupsen/logrus"
"github.com/sirupsen/logrus/hooks/test"
"github.com/spiral/roadrunner/service"
rrhttp "github.com/spiral/roadrunner/service/http"
"github.com/stretchr/testify/assert"
"testing"
)
type testCfg struct {
gzip string
httpCfg string
//static string
target string
}
func (cfg *testCfg) Get(name string) service.Config {
if name == rrhttp.ID {
return &testCfg{target: cfg.httpCfg}
}
if name == ID {
return &testCfg{target: cfg.gzip}
}
return nil
}
func (cfg *testCfg) Unmarshal(out interface{}) error {
return json.Unmarshal([]byte(cfg.target), out)
}
//func get(url string) (string, *http.Response, error) {
// r, err := http.Get(url)
// if err != nil {
// return "", nil, err
// }
//
// b, err := ioutil.ReadAll(r.Body)
// if err != nil {
// return "", nil, err
// }
//
// err = r.Body.Close()
// if err != nil {
// return "", nil, err
// }
//
// return string(b), r, err
//}
func Test_Disabled(t *testing.T) {
logger, _ := test.NewNullLogger()
logger.SetLevel(logrus.DebugLevel)
c := service.NewContainer(logger)
c.Register(ID, &Service{})
assert.NoError(t, c.Init(&testCfg{
gzip: `{"enable":false}`,
}))
s, st := c.Get(ID)
assert.NotNil(t, s)
assert.Equal(t, service.StatusInactive, st)
}
// func Test_Files(t *testing.T) {
// logger, _ := test.NewNullLogger()
// logger.SetLevel(logrus.DebugLevel)
// c := service.NewContainer(logger)
// c.Register(rrhttp.ID, &rrhttp.Service{})
// c.Register(ID, &Service{})
// assert.NoError(t, c.Init(&testCfg{
// gzip: `{"enable":true}`,
// static: `{"enable":true, "dir":"../../tests", "forbid":[]}`,
// httpCfg: `{
// "enable": true,
// "address": ":6029",
// "maxRequestSize": 1024,
// "uploads": {
// "dir": ` + tmpDir() + `,
// "forbid": []
// },
// "workers":{
// "command": "php ../../tests/http/client.php pid pipes",
// "relay": "pipes",
// "pool": {
// "numWorkers": 1,
// "allocateTimeout": 10000000,
// "destroyTimeout": 10000000
// }
// }
// }`}))
// go func() {
// err := c.Serve()
// if err != nil {
// t.Errorf("serve error: %v", err)
// }
// }()
// time.Sleep(time.Millisecond * 1000)
// defer c.Stop()
// b, _, _ := get("http://localhost:6029/sample.txt")
// assert.Equal(t, "sample", b)
// //header should not contain content-encoding:gzip because content-length < gziphandler.DefaultMinSize
// // b, _, _ := get("http://localhost:6029/gzip-large-file.txt")
// //header should contain content-encoding:gzip because content-length > gziphandler.DefaultMinSize
// }
//func tmpDir() string {
// p := os.TempDir()
// r, _ := json.Marshal(p)
//
// return string(r)
//}
|