From 484734ab36b06a9e6d35348e357312d99522302c Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Wed, 23 Dec 2020 12:01:05 +0100 Subject: Implemented the configuration file format --- config/config_test.go | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 config/config_test.go (limited to 'config/config_test.go') diff --git a/config/config_test.go b/config/config_test.go new file mode 100644 index 0000000..adbfc7e --- /dev/null +++ b/config/config_test.go @@ -0,0 +1,107 @@ +package config + +import ( + "reflect" + "testing" +) + +func TestLoadFile(t *testing.T) { + _, err := LoadFile("test_data/non-existant") + if err == nil { + t.Fatal("non-existant config file failed without error") + } + _, err = LoadFile("test_data/invalid_yaml") + if err == nil { + t.Fatal("invalid_yaml config file failed without error") + } + config, err := LoadFile("../example/complete.yaml") + want := Config{ + App: App{ + WorkingDirectory: "var/", + MaxUsers: 512, + AllowRegistration: true, + MaxNickLen: 15, + MenuMaxIdleTime: 600, + PostLoginCommands: []string{ + "mkdir %w/userdata/%u", + "mkdir %w/userdata/%u/dumplog", + "mkdir %w/userdata/%u/ttyrec", + }, + }, + Menus: []Menu{ + Menu{ + Banner: "Shell Game Launcher - Anonymous access%n======================================", + XOffset: 5, + YOffset: 2, + MenuEntries: []MenuEntry{ + MenuEntry{ + Key: "l", + Label: "login", + Action: "login", + }, + MenuEntry{ + Key: "r", + Label: "register", + Action: "register", + }, + MenuEntry{ + Key: "w", + Label: "watch", + Action: "watch_menu", + }, + MenuEntry{ + Key: "s", + Label: "scores", + Action: "scores", + }, + MenuEntry{ + Key: "q", + Label: "quit", + Action: "quit", + }, + }, + }, + Menu{ + Banner: "Shell Game Launcher%n===================", + XOffset: 5, + YOffset: 2, + MenuEntries: []MenuEntry{ + MenuEntry{ + Key: "p", + Label: "play Nethack 3.7", + Action: "play nethack3.7", + }, + MenuEntry{ + Key: "o", + Label: "edit game options", + Action: "options", + }, + MenuEntry{ + Key: "w", + Label: "watch", + Action: "watch_menu", + }, + MenuEntry{ + Key: "s", + Label: "scores", + Action: "scores", + }, + MenuEntry{ + Key: "q", + Label: "quit", + Action: "quit", + }, + }, + }, + }, + Games: map[string]Game{ + "nethack3.7": Game{ + ChrootPath: "/opt/nethack", + FileMode: "0666", + }, + }, + } + if err != nil || !reflect.DeepEqual(want, config) { + t.Fatalf("complete example failed:\nerror %v\nwant:%+v\ngot: %+v", err, want, config) + } +} -- cgit v1.2.3