mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-27 13:25:40 +00:00
46 lines
969 B
Go
46 lines
969 B
Go
package processor_test
|
|
|
|
import (
|
|
"slices"
|
|
"testing"
|
|
|
|
"github.com/jwetzell/osc-go"
|
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
|
)
|
|
|
|
func TestGoodJsonEncode(t *testing.T) {
|
|
stringEncoder := processor.JsonEncode{}
|
|
tests := []struct {
|
|
processor processor.Processor
|
|
name string
|
|
payload any
|
|
expected []byte
|
|
}{
|
|
{
|
|
processor: &stringEncoder,
|
|
name: "hello",
|
|
payload: osc.OSCMessage{
|
|
Address: "/hello",
|
|
},
|
|
expected: []byte("{\"address\":\"/hello\",\"args\":null}"),
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
got, err := test.processor.Process(t.Context(), test.payload)
|
|
|
|
gotBytes, ok := got.([]byte)
|
|
if !ok {
|
|
t.Fatalf("json.encode returned a %T payload: %s", got, got)
|
|
}
|
|
if err != nil {
|
|
t.Fatalf("json.encode failed: %s", err)
|
|
}
|
|
if !slices.Equal(gotBytes, test.expected) {
|
|
t.Fatalf("json.encode got %x, expected %s", got, test.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|