add registry test for json.decode

This commit is contained in:
Joel Wetzell
2026-02-08 21:23:21 -06:00
parent ebbce3261c
commit 0ef512eb28

View File

@@ -4,9 +4,49 @@ import (
"reflect" "reflect"
"testing" "testing"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor" "github.com/jwetzell/showbridge-go/internal/processor"
) )
func TestJsonDecodeFromRegistry(t *testing.T) {
registration, ok := processor.ProcessorRegistry["json.decode"]
if !ok {
t.Fatalf("json.decode processor not registered")
}
processorInstance, err := registration.New(config.ProcessorConfig{
Type: "json.decode",
})
if err != nil {
t.Fatalf("failed to create json.decode processor: %s", err)
}
if processorInstance.Type() != "json.decode" {
t.Fatalf("json.decode processor has wrong type: %s", processorInstance.Type())
}
payload := "{\"property\":\"hello\"}"
expected := map[string]any{
"property": "hello",
}
got, err := processorInstance.Process(t.Context(), payload)
if err != nil {
t.Fatalf("json.decode processing failed: %s", err)
}
gotMap, ok := got.(map[string]any)
if !ok {
t.Fatalf("json.decode should return byte slice")
}
if !reflect.DeepEqual(gotMap, expected) {
t.Fatalf("json.decode got %+v, expected %+v", got, expected)
}
}
func TestGoodJsonDecode(t *testing.T) { func TestGoodJsonDecode(t *testing.T) {
jsonDecoder := processor.JsonDecode{} jsonDecoder := processor.JsonDecode{}
tests := []struct { tests := []struct {