-
Notifications
You must be signed in to change notification settings - Fork 3
/
wrapper_test.go
68 lines (57 loc) · 1.61 KB
/
wrapper_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
package wrapper
import (
"testing"
"time"
)
func TestWrapperStart(t *testing.T) {
c, err := newTestConsole("testdata/server_start_log")
if err != nil {
t.Errorf("failed to load test file: %w", err)
return
}
wpr := NewWrapper(c, logParserFunc)
if wpr.State() != WrapperOffline {
t.Errorf("wrapper should be 'offline', got %s", wpr.State())
}
if err := wpr.Start(); err != nil {
t.Error(err)
return
}
select {
case <-wpr.Loaded():
case <-time.After(1 * time.Second):
t.Error("wrapper timeout, failed to start")
}
if wpr.State() != WrapperOnline {
t.Errorf("wrapper should be 'online', got %s", wpr.State())
}
expectedDetectedVersion := "1.16.4"
if wpr.Version != expectedDetectedVersion {
t.Errorf("wrapper version be %s, got %s", expectedDetectedVersion, wpr.Version)
}
}
func TestWrapperOffline(t *testing.T) {
c, err := newTestConsole("testdata/server_start_log")
if err != nil {
t.Errorf("failed to load test file: %w", err)
return
}
wpr := NewWrapper(c, logParserFunc)
if wpr.State() != WrapperOffline {
t.Errorf("wrapper should be 'offline', got %s", wpr.State())
}
// test simple entry command (no output expected).
if err := wpr.Ban("player-1", "reason-1"); err == nil {
t.Error("wrapper.Ban should error when 'offline'")
}
// test single entry command (with expected output).
_, err = wpr.DataGet("entity", "player-1")
if err == nil {
t.Error("wrapper.DataGet should error when 'offline'")
}
// test list entry command (with output parsing multiple log lines).
_, err = wpr.BanList(BanPlayers)
if err == nil {
t.Error("wrapper.BanList should error when 'offline'")
}
}