aboutsummaryrefslogtreecommitdiff
path: root/config/config_test.go
diff options
context:
space:
mode:
authorJulien Dessaux2020-12-24 15:18:24 +0100
committerJulien Dessaux2020-12-24 15:18:24 +0100
commitb4dc5d6841f7ded5995e5f308509b1a3a034cbed (patch)
tree254466925238c53bd51372a57558ec68fdf78205 /config/config_test.go
parentImplemented the configuration file format (diff)
downloadshell-game-launcher-b4dc5d6841f7ded5995e5f308509b1a3a034cbed.tar.gz
shell-game-launcher-b4dc5d6841f7ded5995e5f308509b1a3a034cbed.tar.bz2
shell-game-launcher-b4dc5d6841f7ded5995e5f308509b1a3a034cbed.zip
Began implementing config validation
Diffstat (limited to 'config/config_test.go')
-rw-r--r--config/config_test.go81
1 files changed, 68 insertions, 13 deletions
diff --git a/config/config_test.go b/config/config_test.go
index adbfc7e..1fcc57c 100644
--- a/config/config_test.go
+++ b/config/config_test.go
@@ -1,19 +1,58 @@
package config
import (
+ "os"
"reflect"
"testing"
)
func TestLoadFile(t *testing.T) {
+ // Non existant file
_, err := LoadFile("test_data/non-existant")
if err == nil {
t.Fatal("non-existant config file failed without error")
}
+
+ // Invalid yaml file
_, err = LoadFile("test_data/invalid_yaml")
if err == nil {
t.Fatal("invalid_yaml config file failed without error")
}
+
+ // TODO test non existant menu in action menu entries, and duplicate, and that anonymous and logged_in exist
+ // TODO test non existant game in play actions, and duplicate
+ //menuEntry = MenuEntry{
+ //Key: "p",
+ //Label: "play non existant game",
+ //Action: "play nonexistant",
+ //}
+ //if err := menuEntry.validate(); err == nil {
+ //t.Fatal("An inexistant game cannot be played")
+ //}
+
+ t.Cleanup(func() { os.RemoveAll("var/") })
+ // Invalid App example
+ if _, err := LoadFile("test_data/invalid_app.yaml"); err == nil {
+ t.Fatal("Invalid App entry should fail to load")
+ }
+ // Not enough menus example
+ if _, err := LoadFile("test_data/not_enough_menus.yaml"); err == nil {
+ t.Fatal("not enough menu entries should fail to load")
+ }
+ // Invalid Menus example
+ if _, err := LoadFile("test_data/invalid_menus.yaml"); err == nil {
+ t.Fatal("Invalid menu entry should fail to load")
+ }
+ // no anonymous Menu example
+ if _, err := LoadFile("test_data/no_anonymous_menu.yaml"); err == nil {
+ t.Fatal("Invalid menu entry should fail to load")
+ }
+ // no logged_in Menu example
+ if _, err := LoadFile("test_data/no_logged_in_menu.yaml"); err == nil {
+ t.Fatal("Invalid menu entry should fail to load")
+ }
+
+ // Complexe example
config, err := LoadFile("../example/complete.yaml")
want := Config{
App: App{
@@ -28,8 +67,8 @@ func TestLoadFile(t *testing.T) {
"mkdir %w/userdata/%u/ttyrec",
},
},
- Menus: []Menu{
- Menu{
+ Menus: map[string]Menu{
+ "anonymous": Menu{
Banner: "Shell Game Launcher - Anonymous access%n======================================",
XOffset: 5,
YOffset: 2,
@@ -50,18 +89,13 @@ func TestLoadFile(t *testing.T) {
Action: "watch_menu",
},
MenuEntry{
- Key: "s",
- Label: "scores",
- Action: "scores",
- },
- MenuEntry{
Key: "q",
Label: "quit",
Action: "quit",
},
},
},
- Menu{
+ "logged_in": Menu{
Banner: "Shell Game Launcher%n===================",
XOffset: 5,
YOffset: 2,
@@ -74,17 +108,27 @@ func TestLoadFile(t *testing.T) {
MenuEntry{
Key: "o",
Label: "edit game options",
- Action: "options",
+ Action: "menu options",
},
MenuEntry{
Key: "w",
Label: "watch",
- Action: "watch_menu",
+ Action: "watch",
+ },
+ MenuEntry{
+ Key: "r",
+ Label: "replay",
+ Action: "replay",
},
MenuEntry{
- Key: "s",
- Label: "scores",
- Action: "scores",
+ Key: "c",
+ Label: "change password",
+ Action: "passwd",
+ },
+ MenuEntry{
+ Key: "m",
+ Label: "change email",
+ Action: "chmail",
},
MenuEntry{
Key: "q",
@@ -98,6 +142,17 @@ func TestLoadFile(t *testing.T) {
"nethack3.7": Game{
ChrootPath: "/opt/nethack",
FileMode: "0666",
+ ScoreCommands: []string{
+ "exec /games/nethack -s all",
+ "wait",
+ },
+ Commands: []string{
+ "cp /games/var/save/%u%n.gz /games/var/save/%u%n.gz.bak",
+ "exec /games/nethack -u %n",
+ },
+ Env: map[string]string{
+ "NETHACKOPTIONS": "@%ruserdata/%n/%n.nhrc",
+ },
},
},
}