From bbea9342330ff020b8e3094c849db88719915132 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Sat, 26 Dec 2020 12:54:42 +0100 Subject: Continued implementing config validation --- config/config_test.go | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) (limited to 'config/config_test.go') diff --git a/config/config_test.go b/config/config_test.go index 1fcc57c..5679d06 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -19,7 +19,6 @@ func TestLoadFile(t *testing.T) { 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", @@ -31,26 +30,46 @@ func TestLoadFile(t *testing.T) { //} t.Cleanup(func() { os.RemoveAll("var/") }) - // Invalid App example + // Invalid App if _, err := LoadFile("test_data/invalid_app.yaml"); err == nil { t.Fatal("Invalid App entry should fail to load") } - // Not enough menus example + // Not enough menus if _, err := LoadFile("test_data/not_enough_menus.yaml"); err == nil { t.Fatal("not enough menu entries should fail to load") } - // Invalid Menus example + // Invalid Menus if _, err := LoadFile("test_data/invalid_menus.yaml"); err == nil { t.Fatal("Invalid menu entry should fail to load") } - // no anonymous Menu example + // no anonymous Menu 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 + // no logged_in Menu if _, err := LoadFile("test_data/no_logged_in_menu.yaml"); err == nil { t.Fatal("Invalid menu entry should fail to load") } + // duplicate menu + if _, err := LoadFile("test_data/duplicate_menu.yaml"); err == nil { + t.Fatal("duplicate menu should fail to load") + } + // non existant menu action referenced + if _, err := LoadFile("test_data/non_existant_menu.yaml"); err == nil { + t.Fatal("menu entry referencing a non existant menu should fail to load") + } + // non existant game referenced in play action + if _, err := LoadFile("test_data/non_existant_game.yaml"); err == nil { + t.Fatal("menu entry referencing a non existant play action should fail to load") + } + // unreachable menu + if _, err := LoadFile("test_data/unreachable_menu.yaml"); err == nil { + t.Fatal("unreachable menu should fail to load") + } + // unreachable game + if _, err := LoadFile("test_data/unreachable_game.yaml"); err == nil { + t.Fatal("unreachable game should fail to load") + } // Complexe example config, err := LoadFile("../example/complete.yaml") @@ -137,6 +156,18 @@ func TestLoadFile(t *testing.T) { }, }, }, + "options": Menu{ + Banner: "Options%n=======", + XOffset: 5, + YOffset: 2, + MenuEntries: []MenuEntry{ + MenuEntry{ + Key: "z", + Label: "back", + Action: "menu logged_in", + }, + }, + }, }, Games: map[string]Game{ "nethack3.7": Game{ -- cgit v1.2.3