mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-26 21:05:30 +00:00
add registry test for json.encode
This commit is contained in:
@@ -5,9 +5,51 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/jwetzell/osc-go"
|
"github.com/jwetzell/osc-go"
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/config"
|
||||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestJsonEncodeFromRegistry(t *testing.T) {
|
||||||
|
registration, ok := processor.ProcessorRegistry["json.encode"]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("json.encode processor not registered")
|
||||||
|
}
|
||||||
|
|
||||||
|
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||||
|
Type: "json.encode",
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create json.encode processor: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if processorInstance.Type() != "json.encode" {
|
||||||
|
t.Fatalf("json.encode processor has wrong type: %s", processorInstance.Type())
|
||||||
|
}
|
||||||
|
|
||||||
|
payload := struct {
|
||||||
|
Property string `json:"property"`
|
||||||
|
}{
|
||||||
|
Property: "hello",
|
||||||
|
}
|
||||||
|
|
||||||
|
expected := []byte("{\"property\":\"hello\"}")
|
||||||
|
|
||||||
|
got, err := processorInstance.Process(t.Context(), payload)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("json.encode processing failed: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
gotBytes, ok := got.([]byte)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("json.encode should return byte slice")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !slices.Equal(gotBytes, expected) {
|
||||||
|
t.Fatalf("json.encode got %+v, expected %+v", got, expected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestGoodJsonEncode(t *testing.T) {
|
func TestGoodJsonEncode(t *testing.T) {
|
||||||
jsonEncoder := processor.JsonEncode{}
|
jsonEncoder := processor.JsonEncode{}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user