This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathkdb_handler_test.go
97 lines (73 loc) · 2.06 KB
/
kdb_handler_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
package main
import (
"net/http"
"testing"
)
func TestGetKdb(t *testing.T) {
keyName := "user:/tests/elektrad/kdb/get"
keyNameChild := "user:/tests/elektrad/kdb/get/child"
setupKey(t, keyName, keyNameChild)
w := testGet(t, "/kdb/"+keyName)
code := w.Result().StatusCode
Assertf(t, code == http.StatusOK, "wrong status code: %v", code)
var response lookupResult
parseBody(t, w, &response)
Assert(t, response.Exists, "key not found")
Assert(t, response.Path == keyName, "key path is wrong")
CompareStrings(t, []string{keyName, keyNameChild}, response.Ls, "Children are not the same")
removeKey(t, keyName)
removeKey(t, keyNameChild)
}
func TestPutKdb(t *testing.T) {
keyName := "user:/tests/elektrad/kdb/put"
value := "test me"
w := testPut(t, "/kdb/"+keyName, value)
code := w.Result().StatusCode
Assertf(t, code == http.StatusCreated, "wrong status code: %v", code)
key := getKey(t, keyName)
removeKey(t, keyName)
Assert(t, key != nil, "key was not created")
retrievedValue := key.String()
Assertf(t, retrievedValue == value, "wrong key value %s, expected %s", retrievedValue, value)
}
func TestPutAllKdb(t *testing.T) {
parentKeyName := "user:/tests/elektrad/kdb/all/put"
value1 := "value1"
value2 := "value2"
value3 := "value3"
value4 := "value4"
configurations := keyConfigurationSet{
[]keyValueBody{
{
Key: "key1",
Value: &value1,
},
{
Key: "key2",
Value: &value2,
},
{
Key: "key3",
Value: &value3,
},
{
Key: "key4",
Value: &value4,
},
},
}
w := testPut(t, "/kdb/"+parentKeyName, configurations)
code := w.Result().StatusCode
Assertf(t, code == http.StatusCreated, "wrong status code: %v", code)
assertContains(t, configurations)
}
func TestDeleteKdb(t *testing.T) {
keyName := "user:/tests/elektrad/kdb/delete"
setupKey(t, keyName)
w := testDelete(t, "/kdb/"+keyName, nil)
code := w.Result().StatusCode
Assertf(t, code == http.StatusNoContent, "wrong status code: %v", code)
key := getKey(t, keyName)
removeKey(t, keyName)
Assert(t, key == nil, "key was not deleted")
}