summaryrefslogtreecommitdiff
path: root/api/minecraft/minecraft_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'api/minecraft/minecraft_test.go')
-rw-r--r--api/minecraft/minecraft_test.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/api/minecraft/minecraft_test.go b/api/minecraft/minecraft_test.go
new file mode 100644
index 0000000..0c89fc5
--- /dev/null
+++ b/api/minecraft/minecraft_test.go
@@ -0,0 +1,40 @@
+package minecraft
+
+import (
+ "reflect"
+ "testing"
+)
+
+func TestParseList(t *testing.T) {
+ cases := []struct {
+ out string
+ want Status
+ }{
+ {
+ "There are 2 of a max of 20 players online: Alice, Bob",
+ Status{Online: true, Count: 2, Max: 20, Players: []string{"Alice", "Bob"}},
+ },
+ {
+ "There are 0 of a max of 20 players online:",
+ Status{Online: true, Count: 0, Max: 20, Players: []string{}},
+ },
+ {
+ "There are 1 of a max of 20 players online: Steve\n",
+ Status{Online: true, Count: 1, Max: 20, Players: []string{"Steve"}},
+ },
+ {
+ "some unexpected response",
+ Status{Online: true, Count: 0, Max: 0, Players: []string{}},
+ },
+ }
+
+ for _, c := range cases {
+ got := parseList(c.out)
+ if got.Players == nil {
+ got.Players = []string{}
+ }
+ if !reflect.DeepEqual(got, c.want) {
+ t.Errorf("parseList(%q) = %+v, want %+v", c.out, got, c.want)
+ }
+ }
+}