aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Dessaux2021-01-12 15:55:41 +0100
committerJulien Dessaux2021-01-12 15:55:41 +0100
commit8c03774e1f05a1b9a87c5231562ba39989604773 (patch)
treea40aa7a2535ac565964059f798afb65a747e6416
parentContinued implementing config validation (diff)
downloadshell-game-launcher-8c03774e1f05a1b9a87c5231562ba39989604773.tar.gz
shell-game-launcher-8c03774e1f05a1b9a87c5231562ba39989604773.tar.bz2
shell-game-launcher-8c03774e1f05a1b9a87c5231562ba39989604773.zip
Updated menu tests to account properly for duplicate keys
-rw-r--r--config/config.go2
-rw-r--r--config/menu.go9
-rw-r--r--config/menu_test.go19
-rw-r--r--go.mod2
-rw-r--r--go.sum4
5 files changed, 10 insertions, 26 deletions
diff --git a/config/config.go b/config/config.go
index 1deaf04..aa1672a 100644
--- a/config/config.go
+++ b/config/config.go
@@ -4,7 +4,7 @@ import (
"os"
"github.com/pkg/errors"
- "gopkg.in/yaml.v2"
+ "gopkg.in/yaml.v3"
)
type Config struct {
diff --git a/config/menu.go b/config/menu.go
index 004c7fe..a442036 100644
--- a/config/menu.go
+++ b/config/menu.go
@@ -47,13 +47,12 @@ func (m *Menu) validate(name string) error {
return errors.New("YOffset must be a positive integer")
}
// MenuEntries
- keys := make(map[string]bool)
+ if len(m.MenuEntries) == 0 {
+ return errors.New("A Menu needs MenuEntries to be valid")
+ }
+ // Duplicate detection is natively handled by the yaml parser
for i := 0; i < len(m.MenuEntries); i++ {
m.MenuEntries[i].validate()
- if _, duplicate := keys[m.MenuEntries[i].Key]; duplicate {
- return errors.New("A Menu has a duplicate key " + m.MenuEntries[i].Key)
- }
- keys[m.MenuEntries[i].Key] = true
if m.MenuEntries[i].Action == "menu "+name {
return errors.New("A menu shall not loop on itself")
}
diff --git a/config/menu_test.go b/config/menu_test.go
index 98405c7..d0b1805 100644
--- a/config/menu_test.go
+++ b/config/menu_test.go
@@ -26,24 +26,9 @@ func TestMenuValidate(t *testing.T) {
t.Fatal("Negative YOffset should not be valid")
}
// MenuEntries are mostly tested bellow
- menu = Menu{
- XOffset: 1,
- YOffset: 1,
- MenuEntries: []MenuEntry{
- MenuEntry{
- Key: "a",
- Label: "test",
- Action: "quit",
- },
- MenuEntry{
- Key: "a",
- Label: "duplicate",
- Action: "quit",
- },
- },
- }
+ menu = Menu{}
if err := menu.validate("test"); err == nil {
- t.Fatal("Duplicate Keys in MenuEntries should not be allowed")
+ t.Fatal("A menu without menu entries should not be valid")
}
// loop menu
menu = Menu{
diff --git a/go.mod b/go.mod
index f43c8d2..8924672 100644
--- a/go.mod
+++ b/go.mod
@@ -5,5 +5,5 @@ go 1.15
require (
github.com/pkg/errors v0.9.1
golang.org/x/sys v0.0.0-20201223074533-0d417f636930
- gopkg.in/yaml.v2 v2.4.0
+ gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
)
diff --git a/go.sum b/go.sum
index 8b4f631..d35cf33 100644
--- a/go.sum
+++ b/go.sum
@@ -4,5 +4,5 @@ golang.org/x/sys v0.0.0-20201223074533-0d417f636930 h1:vRgIt+nup/B/BwIS0g2oC0haq
golang.org/x/sys v0.0.0-20201223074533-0d417f636930/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
-gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
+gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
+gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=