-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
61 lines (49 loc) · 1.31 KB
/
main_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
package test1
import (
"fmt"
"testing"
)
func TestListen(t *testing.T) {
// Test that the Listen function registers Listener("subscriber")
// to listeners = []Listener{}
if len(listeners) != 0 {
t.Errorf("Expected %d, found %d", 0, len(listeners))
}
Listen(func(cmd Cmd) { fmt.Println(1, cmd) })
if len(listeners) != 1 {
t.Errorf("Expected %d, found %d", 1, len(listeners))
}
Listen(func(cmd Cmd) { fmt.Println(1, cmd) })
Listen(func(cmd Cmd) { fmt.Println(1, cmd) })
if len(listeners) != 3 {
t.Errorf("Expected %d, found %d", 3, len(listeners))
}
}
func TestSetupServers(t *testing.T) {
// TODO
// Need to figure out how this can be tested since
// it's a big chuck of the program. Probably integration test
// for verifying that it actually starts the http and tcp server
}
func TestValidateData(t *testing.T) {
validData := Cmd{"King of Rock", 666}
invalidData := Cmd{"", 666}
invalidData2 := Cmd{"", 0}
invalidData4 := Cmd{}
_, err := validateData(validData)
if err != nil {
t.Errorf("This data should be valid")
}
_, err = validateData(invalidData)
if err == nil {
t.Errorf("This data is invalid")
}
_, err = validateData(invalidData2)
if err == nil {
t.Errorf("This data is invalid")
}
_, err = validateData(invalidData4)
if err == nil {
t.Errorf("This data is invalid")
}
}