-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulation_test.go
90 lines (74 loc) · 1.78 KB
/
simulation_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
package main
import (
"log"
"os"
"reflect"
"testing"
)
var test_fixtures = "fixtures.yaml"
func fakeLogger() *log.Logger {
_, logfile, _ := os.Pipe()
return log.New(logfile, "[Server Test] ", log.LstdFlags)
}
func Test_getConfig(t *testing.T) {
_, err := getConfig(test_fixtures)
if err != nil {
t.Errorf(err.Error())
}
}
func Test_Config_GetAllCommandName(t *testing.T) {
config, _ := getConfig(test_fixtures)
commands := config.GetAllCommandName()
if len(commands) != 4 {
t.Errorf("Incorrect number of commands")
}
}
func Test_Config_hasCommand(t *testing.T) {
config, _ := getConfig(test_fixtures)
if !config.hasCommand("meow") {
t.Errorf("Not exist command 'meow'")
}
if config.hasCommand("nonono") {
t.Errorf("hasCommand() error")
}
}
func Test_Config_Verify(t *testing.T) {
config, _ := getConfig(test_fixtures)
if config.Verify() != nil {
t.Errorf("fixtures Verify failed")
}
config.Default = append(config.Default, "test_test")
if config.Verify() == nil {
t.Errorf("fixtures Verify failed")
}
}
func Test_Config_DetectMutex(t *testing.T) {
config, _ := getConfig(test_fixtures)
for line := range config.DetectMutex("meow") {
if reflect.DeepEqual(line, []string{"meow", "shine"}) {
t.Errorf("DetectMutex failed")
}
}
}
func Test_GetMethods(t *testing.T) {
config, _ := getConfig(test_fixtures)
ch_command := make(chan string)
ch_send := make(chan []byte, 128)
ch_recv := make(chan []byte, 128)
simulation := Simulation{
Input: ch_recv,
Output: ch_send,
Command: ch_command,
config: config,
logger: fakeLogger(),
}
go simulation.Run()
simulation.Command <- "shine"
if string(<-ch_send) != "No ~ \n" {
t.Errorf("Output failed")
}
simulation.RunDefault()
if string(<-ch_send) != "Meow ~ Meow ~\n" {
t.Errorf("Output failed")
}
}