-
Notifications
You must be signed in to change notification settings - Fork 1
/
commander_test.go
79 lines (59 loc) · 1.59 KB
/
commander_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
package kece
import (
"bytes"
"testing"
)
func TestCommander(t *testing.T) {
dataStructures := []DataStructure{newStructureMock()}
for _, ds := range dataStructures {
cmd := NewCommander(ds)
t.Run("should success SET new value to db", func(t *testing.T) {
key := []byte("1")
value := []byte("wuriyanto")
command := []byte("SET")
expectedValue := []byte("wuriyanto")
newValue, err := cmd.Set(command, key, value)
if err != nil {
t.Error("command is not valid")
}
if !bytes.Equal(newValue.Value, expectedValue) {
t.Error("new value is not equal to value")
}
})
t.Run("should success GET value from db", func(t *testing.T) {
key := []byte("1")
expectedValue := []byte("wuriyanto")
command := []byte("GET")
value, err := cmd.Get(command, key)
if err != nil {
t.Error(err.Error())
}
if !bytes.Equal(value.Value, expectedValue) {
t.Error("value is not equal to expected value")
}
})
t.Run("should error SET new value to db with invalid command", func(t *testing.T) {
key := []byte("1")
value := []byte("wuriyanto")
command := []byte("ET")
newValue, err := cmd.Set(command, key, value)
if err == nil {
t.Error("command should invalid")
}
if newValue != nil {
t.Error("new value should be nil")
}
})
t.Run("should error GET value from db with invalid command", func(t *testing.T) {
key := []byte("1")
command := []byte("ET")
value, err := cmd.Get(command, key)
if err == nil {
t.Error("command is not valid")
}
if value != nil {
t.Error("value should be nil")
}
})
}
}