-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocker_test.go
55 lines (50 loc) · 1.1 KB
/
locker_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
package cloudlocker
import (
"encoding/json"
"io/ioutil"
"net/http"
"os"
"strings"
"testing"
)
var testPath = "./tmp"
var testUrl = "127.0.0.1:33300"
var testUrl4client = "http://" + testUrl
func TestHandlers(t *testing.T) {
s, err := NewLockerServer(testPath, testUrl)
if err != nil {
t.Fatal(err)
}
go s.Start()
e := Entry{
K: []byte{0x01},
V: []byte{0x02},
}
b, _ := json.Marshal(e)
_, err = http.Post(testUrl4client+"/set", "application/json", strings.NewReader(string(b)))
if err != nil {
panic(err)
}
resp, err := http.Post(testUrl4client+"/get", "application/json", strings.NewReader(string(e.K)))
if err != nil {
panic(err)
}
defer resp.Body.Close()
out, _ := ioutil.ReadAll(resp.Body)
if len(out) == 0 || out[0] != e.V[0] {
panic("value not exactly set")
}
s.Stop()
_, err = http.Post(testUrl4client+"/set", "application/json", strings.NewReader(string(b)))
if err == nil {
panic("server should has been stop")
}
_ = os.RemoveAll(testPath)
}
func TestHandlers1(t *testing.T) {
s, err := NewLockerServer(testPath, testUrl)
if err != nil {
t.Fatal(err)
}
s.Start()
}