-
Notifications
You must be signed in to change notification settings - Fork 0
/
message_test.go
113 lines (103 loc) · 2.66 KB
/
message_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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package main
import "testing"
import "reflect"
func TestIndexMessageParsing(t *testing.T) {
msg := NewMessage("INDEX|foo|bar,biz")
if msg.cmd != INDEX {
t.Error("Expected INDEX got", INDEX, msg.cmd)
}
if msg.pkg != "foo" {
t.Error("Expected pkg foo, got", msg.pkg)
}
deps := [2]string{"bar", "biz"}
if !reflect.DeepEqual(msg.dep, deps[:]) {
t.Error("Expected dep \"bar\", \"biz\", got", msg.dep)
}
}
func TestIndexMessageParsingMakesZeroLengthDepths(t *testing.T) {
msg := NewMessage("INDEX|foo|")
if msg.cmd != INDEX {
t.Error("Expected INDEX got", INDEX, msg.cmd)
}
if msg.pkg != "foo" {
t.Error("Expected pkg foo, got", msg.pkg)
}
deps := [0]string{}
if !reflect.DeepEqual(msg.dep, deps[:]) {
t.Error("Expected no deps, got", msg.dep)
}
}
func TestQueryMessageParsing(t *testing.T) {
msg := NewMessage("QUERY|foo|bar,biz")
if msg.cmd != QUERY {
t.Error("Expected QUERY got", QUERY, msg.cmd)
}
if msg.pkg != "foo" {
t.Error("Expected pkg foo, got", msg.pkg)
}
deps := [2]string{"bar", "biz"}
if !reflect.DeepEqual(msg.dep, deps[:]) {
t.Error("Expected dep \"bar\", \"biz\", got", msg.dep)
}
}
func TestRemoveMessageParsing(t *testing.T) {
msg := NewMessage("REMOVE|foo|bar,biz")
if msg.cmd != REMOVE {
t.Error("Expected REMOVE got", REMOVE, msg.cmd)
}
if msg.pkg != "foo" {
t.Error("Expected pkg foo, got", msg.pkg)
}
deps := [2]string{"bar", "biz"}
if !reflect.DeepEqual(msg.dep, deps[:]) {
t.Error("Expected dep \"bar\", \"biz\", got", msg.dep)
}
}
func TestErrorMessageParsing(t *testing.T) {
msg := NewMessage("RE|foo|bar,biz")
if msg.cmd != ERROR {
t.Error("Expected ERROR got", ERROR, msg.cmd)
}
if msg.pkg != "" {
t.Error("Expected pkg '', got", msg.pkg)
}
if len(msg.dep) != 0 {
t.Error("Expected empty, got", msg.dep)
}
msg = NewMessage("QUERY|")
if msg.cmd != ERROR {
t.Error("Expected ERROR got", ERROR, msg.cmd)
}
if msg.pkg != "" {
t.Error("Expected pkg '', got", msg.pkg)
}
if len(msg.dep) != 0 {
t.Error("Expected empty, got", msg.dep)
}
msg = NewMessage("INDEX||")
if msg.cmd != ERROR {
t.Error("Expected ERROR got", ERROR, msg.cmd)
}
if msg.pkg != "" {
t.Error("Expected pkg '', got", msg.pkg)
}
if len(msg.dep) != 0 {
t.Error("Expected empty, got", msg.dep)
}
msg = NewMessage("BLINDEX|a|b")
if msg.cmd != ERROR {
t.Error("Expected ERROR got", ERROR, msg.cmd)
}
if msg.pkg != "" {
t.Error("Expected pkg '', got", msg.pkg)
}
if len(msg.dep) != 0 {
t.Error("Expected empty, got", msg.dep)
}
}
func TestMessageStringer(t *testing.T) {
msg := NewMessage("REMOVE|foo|bar,biz")
if msg.String() != "[REMOVE|foo|[bar biz]]" {
t.Error("Expected [REMOVE|foo|[bar biz]] got", msg.String())
}
}