package gamemanager_test
import (
"fmt"
"testing"
"git.sr.ht/~nromdotcom/gemif/pkg/gamemanager"
"github.com/stretchr/testify/assert"
)
func TestGetSerDeFormat(t *testing.T) {
arrayTests := []struct {
name string
condition string // input
expected gamemanager.SerializationFormat // expected result
}{
{
"JSON",
"json", gamemanager.JSON,
},
{
"Protobuf",
"proto", gamemanager.Protobuf,
},
{
"Neither",
"something_else", 0,
},
}
t.Parallel()
for _, tc := range arrayTests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
actual := gamemanager.GetSerDeFormat(tc.condition)
assert.True(t, assert.ObjectsAreEqualValues(tc.expected, actual))
})
}
}
func TestNewEngineFormatPass(t *testing.T) {
arrayTests := []struct {
name string
render bool
format string // input
expected gamemanager.EngineConfig // expected result
}{
{
"JSON/true", true, "json",
gamemanager.EngineConfig{
RenderDescriptions: true,
StateTokenFormat: gamemanager.JSON,
},
},
{
"Proto/true", true, "proto",
gamemanager.EngineConfig{
RenderDescriptions: true,
StateTokenFormat: gamemanager.Protobuf,
},
},
{
"JSON/false", false, "json",
gamemanager.EngineConfig{
RenderDescriptions: false,
StateTokenFormat: gamemanager.JSON,
},
},
{
"Proto/false", false, "proto",
gamemanager.EngineConfig{
RenderDescriptions: false,
StateTokenFormat: gamemanager.Protobuf,
},
},
}
t.Parallel()
for _, tc := range arrayTests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
actual, _ := gamemanager.NewEngineConfig(tc.render, tc.format)
assert.True(t, assert.ObjectsAreEqualValues(tc.expected, actual))
})
}
}
func TestNewEngineFormatFail(t *testing.T) {
arrayTests := []struct {
name string
render bool
format string // input
expected error // expected result
}{
{
"Neither/true", true, "neither",
gamemanager.ErrInvalidSerializationFormat,
},
{
"Neither/false", false, "neither",
gamemanager.ErrInvalidSerializationFormat,
},
}
t.Parallel()
for _, tc := range arrayTests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
_, err := gamemanager.NewEngineConfig(tc.render, tc.format)
assert.True(t, assert.EqualError(t, err, fmt.Sprintf("%s: %s", tc.expected, tc.format)))
})
}
}