diff --git a/src/device/input/button/v01_exported_test.go b/src/device/input/button/v01_exported_test.go index 455a3b1..4d7af95 100644 --- a/src/device/input/button/v01_exported_test.go +++ b/src/device/input/button/v01_exported_test.go @@ -3,6 +3,8 @@ package button_test import ( "fmt" "mayhem-party/src/device/input/button" + "os" + "path" "testing" "time" ) @@ -29,3 +31,41 @@ func TestV01(t *testing.T) { } } } + +func TestV01WithCfg(t *testing.T) { + d := t.TempDir() + p := path.Join(d, "cfg.yaml") + os.WriteFile(p, []byte(` + users: + bel: + player: 2 + players: + - transformation: + w: t + - transformation: + w: i + `), os.ModePerm) + os.Setenv("BUTTON_PARSER_V01_CONFIG", p) + + t.Run("unknown user ignored", func(t *testing.T) { + v01 := button.NewV01(constSrc(`{"U":"qt","Y":"w"}`)) + got := v01.Read() + if len(got) != 0 { + t.Error(got) + } + }) + + t.Run("player2", func(t *testing.T) { + v01 := button.NewV01(constSrc(`{"U":"bel","Y":"w","N":"w"}`)) + got := v01.Read() + if len(got) != 2 { + t.Error(got) + } + if got[0] != (button.Button{Char: 'i', Down: true}) { + t.Error(got[0]) + } + if got[1] != (button.Button{Char: 'i', Down: false}) { + t.Error(got[1]) + } + }) +}