external test on player transformation

master
bel 2023-03-25 09:12:10 -06:00
parent db69f76aa0
commit 3d9ea1296c
1 changed files with 40 additions and 0 deletions

View File

@ -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])
}
})
}