wrap payload for all processors

This commit is contained in:
Joel Wetzell
2026-03-16 17:05:49 -05:00
parent b6c1c5c600
commit f273aedbc6
76 changed files with 674 additions and 486 deletions

View File

@@ -5,6 +5,7 @@ import (
"testing"
"github.com/jwetzell/artnet-go"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
@@ -57,15 +58,15 @@ func TestGoodArtnetPacketDecode(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := packetDecoder.Process(t.Context(), test.payload)
got, err := packetDecoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err != nil {
t.Fatalf("artnet.packet.decode processing failed: %s", err)
}
//TODO(jwetzell): work out better way to compare the any/any
if !reflect.DeepEqual(got, test.expected) {
t.Fatalf("artnet.packet.decode got %+v (%T), expected %+v (%T)", got, got, test.expected, test.expected)
if !reflect.DeepEqual(got.Payload, test.expected) {
t.Fatalf("artnet.packet.decode got %+v (%T), expected %+v (%T)", got.Payload, got.Payload, test.expected, test.expected)
}
})
}
@@ -93,7 +94,7 @@ func TestBadArtnetPacketDecode(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := packetDecoder.Process(t.Context(), test.payload)
got, err := packetDecoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err == nil {
t.Fatalf("artnet.packet.decode expected to fail but succeeded, got: %v", got)

View File

@@ -5,6 +5,7 @@ import (
"testing"
"github.com/jwetzell/artnet-go"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
@@ -57,14 +58,14 @@ func TestGoodArtnetPacketEncode(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := packetEncoder.Process(t.Context(), test.payload)
got, err := packetEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err != nil {
t.Fatalf("artnet.packet.encode processing failed: %s", err)
}
//TODO(jwetzell): work out better way to compare the any/any
if !reflect.DeepEqual(got, test.expected) {
if !reflect.DeepEqual(got.Payload, test.expected) {
t.Fatalf("artnet.packet.encode got %+v (%T), expected %+v (%T)", got, got, test.expected, test.expected)
}
})
@@ -88,7 +89,7 @@ func TestBadArtnetPacketEncode(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := packetEncoder.Process(t.Context(), test.payload)
got, err := packetEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err == nil {
t.Fatalf("artnet.packet.encode expected to fail but succeeded, got: %v", got)

View File

@@ -3,6 +3,7 @@ package processor_test
import (
"testing"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
@@ -28,12 +29,12 @@ func TestDebugLogFromRegistry(t *testing.T) {
payload := "test"
expected := "test"
got, err := processorInstance.Process(t.Context(), payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), payload))
if err != nil {
t.Fatalf("debug.log processing failed: %s", err)
}
if got != expected {
if got.Payload != expected {
t.Fatalf("debug.log got %+v, expected %+v", got, expected)
}
}

View File

@@ -1,9 +1,9 @@
package processor_test
import (
"reflect"
"testing"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
@@ -31,10 +31,10 @@ func TestFilterExprFromRegistry(t *testing.T) {
func TestGoodFilterExpr(t *testing.T) {
tests := []struct {
name string
params map[string]any
payload any
expected any
name string
params map[string]any
payload any
match bool
}{
{
name: "number",
@@ -44,9 +44,7 @@ func TestGoodFilterExpr(t *testing.T) {
payload: TestStruct{
Int: 1,
},
expected: TestStruct{
Int: 1,
},
match: true,
},
{
name: "string",
@@ -56,9 +54,7 @@ func TestGoodFilterExpr(t *testing.T) {
payload: TestStruct{
String: "hello",
},
expected: TestStruct{
String: "hello",
},
match: true,
},
{
name: "not matching",
@@ -68,7 +64,7 @@ func TestGoodFilterExpr(t *testing.T) {
payload: TestStruct{
Int: 0,
},
expected: nil,
match: false,
},
}
@@ -88,15 +84,15 @@ func TestGoodFilterExpr(t *testing.T) {
t.Fatalf("filter.expr failed to create processor: %s", err)
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err != nil {
t.Fatalf("filter.expr processing failed: %s", err)
}
//TODO(jwetzell): work out better way to compare the any/any
if !reflect.DeepEqual(got, test.expected) {
t.Fatalf("filter.expr got %+v (%T), expected %+v (%T)", got, got, test.expected, test.expected)
if got.End != !test.match {
t.Fatalf("filter.expr did fitler properly %+v (%T), expected %+v (%T)", got, got, test.match, test.match)
}
})
}
@@ -162,7 +158,7 @@ func TestBadFilterExpr(t *testing.T) {
}
return
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err == nil {
t.Fatalf("filter.expr expected to fail but succeeded, got: %v", got)

View File

@@ -1,9 +1,9 @@
package processor_test
import (
"reflect"
"testing"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
@@ -31,12 +31,12 @@ func TestStringFilterFromRegistry(t *testing.T) {
payload := "hello"
expected := "hello"
got, err := processorInstance.Process(t.Context(), payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), payload))
if err != nil {
t.Fatalf("filter.regex processing failed: %s", err)
}
gotString, ok := got.(string)
gotString, ok := got.Payload.(string)
if !ok {
t.Fatalf("filter.regex should return byte slice")
@@ -49,28 +49,28 @@ func TestStringFilterFromRegistry(t *testing.T) {
func TestGoodStringFilter(t *testing.T) {
tests := []struct {
name string
params map[string]any
payload string
expected any
name string
params map[string]any
payload string
match bool
}{
{
name: "matches pattern",
payload: "hello",
params: map[string]any{"pattern": "hello"},
expected: "hello",
name: "matches pattern",
payload: "hello",
params: map[string]any{"pattern": "hello"},
match: true,
},
{
name: "does not match pattern",
payload: "hello",
params: map[string]any{"pattern": "world"},
expected: nil,
name: "does not match pattern",
payload: "hello",
params: map[string]any{"pattern": "world"},
match: false,
},
{
name: "basic regex",
payload: "hello world",
params: map[string]any{"pattern": ".* world"},
expected: "hello world",
name: "basic regex",
payload: "hello world",
params: map[string]any{"pattern": ".* world"},
match: true,
},
}
@@ -90,26 +90,14 @@ func TestGoodStringFilter(t *testing.T) {
t.Fatalf("filter.regex failed to create processor: %s", err)
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err != nil {
t.Fatalf("filter.regex processing failed: %s", err)
}
if test.expected == nil {
if got != nil {
t.Fatalf("filter.regex got %+v, expected nil", got)
}
return
}
gotString, ok := got.(string)
if !ok {
t.Fatalf("filter.regex returned a %T payload: %s", got, got)
}
if !reflect.DeepEqual(gotString, test.expected) {
t.Fatalf("filter.regex got %+v, expected %+v", gotString, test.expected)
if got.End != !test.match {
t.Fatalf("filter.regex did not filter properly %+v, expected %+v", got, test.match)
}
})
}
@@ -173,10 +161,10 @@ func TestBadStringFilter(t *testing.T) {
return
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err == nil {
t.Fatalf("filter.regex expected to fail but got payload: %s", got)
t.Fatalf("filter.regex expected to fail but got payload: %+v", got)
}
if err.Error() != test.errorString {

View File

@@ -3,6 +3,7 @@ package processor_test
import (
"testing"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
@@ -75,14 +76,14 @@ func TestGoodFloatParse(t *testing.T) {
t.Fatalf("float.parse failed to create processor: %s", err)
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err != nil {
t.Fatalf("float.parse processing failed: %s", err)
}
gotFloat, ok := got.(float64)
gotFloat, ok := got.Payload.(float64)
if !ok {
t.Fatalf("float.parse returned a %T payload: %s", got, got)
t.Fatalf("float.parse returned a %T payload: %+v", got, got)
}
if gotFloat != test.expected {
t.Fatalf("float.parse got %f, expected %f", gotFloat, test.expected)
@@ -151,7 +152,7 @@ func TestBadFloatParse(t *testing.T) {
return
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err == nil {
t.Fatalf("float.parse expected to fail but succeeded, got: %v", got)

View File

@@ -3,6 +3,7 @@ package processor_test
import (
"testing"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
@@ -70,7 +71,7 @@ func TestGoodFloatRandom(t *testing.T) {
t.Fatalf("float.random failed to create processor: %s", err)
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err != nil {
t.Fatalf("float.random processing failed: %s", err)
}
@@ -82,16 +83,16 @@ func TestGoodFloatRandom(t *testing.T) {
var gotFloat float64
if bitSize == 32 {
gotFloat32, ok := got.(float32)
gotFloat32, ok := got.Payload.(float32)
if !ok {
t.Fatalf("float.random returned a %T payload: %s", got, got)
t.Fatalf("float.random returned a %T payload: %+v", got, got)
}
gotFloat = float64(gotFloat32)
}
if bitSize == 64 {
gotFloat64, ok := got.(float64)
gotFloat64, ok := got.Payload.(float64)
if !ok {
t.Fatalf("float.random returned a %T payload: %s", got, got)
t.Fatalf("float.random returned a %T payload: %+v", got, got)
}
gotFloat = gotFloat64
}
@@ -171,10 +172,10 @@ func TestBadFloatRandom(t *testing.T) {
return
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err == nil {
t.Fatalf("float.random expected to fail but got payload: %s", got)
t.Fatalf("float.random expected to fail but got payload: %+v", got)
}
if err.Error() != test.errorString {

View File

@@ -3,6 +3,7 @@ package processor_test
import (
"testing"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
@@ -96,14 +97,14 @@ func TestGoodIntParse(t *testing.T) {
t.Fatalf("int.parse failed to create processor: %s", err)
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err != nil {
t.Fatalf("int.parse processing failed: %s", err)
}
gotInt, ok := got.(int64)
gotInt, ok := got.Payload.(int64)
if !ok {
t.Fatalf("int.parse returned a %T payload: %s", got, got)
t.Fatalf("int.parse returned a %T payload: %+v", got, got)
}
if gotInt != test.expected {
t.Fatalf("int.parse got %d, expected %d", gotInt, test.expected)
@@ -185,7 +186,7 @@ func TestBadIntParse(t *testing.T) {
return
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err == nil {
t.Fatalf("int.parse expected to fail but succeeded, got: %v", got)

View File

@@ -3,6 +3,7 @@ package processor_test
import (
"testing"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
@@ -50,14 +51,14 @@ func TestIntRandomGoodConfig(t *testing.T) {
payload := "12345"
got, err := processorInstance.Process(t.Context(), payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), payload))
if err != nil {
t.Fatalf("int.random processing failed: %s", err)
}
gotInt, ok := got.(int)
gotInt, ok := got.Payload.(int)
if !ok {
t.Fatalf("int.random returned a %T payload: %s", got, got)
t.Fatalf("int.random returned a %T payload: %+v", got, got)
}
if gotInt < 1 || gotInt > 10 {
@@ -97,14 +98,14 @@ func TestGoodIntRandom(t *testing.T) {
t.Fatalf("int.random failed to create processor: %s", err)
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err != nil {
t.Fatalf("int.random processing failed: %s", err)
}
gotInt, ok := got.(int)
gotInt, ok := got.Payload.(int)
if !ok {
t.Fatalf("int.random returned a %T payload: %s", got, got)
t.Fatalf("int.random returned a %T payload: %+v", got, got)
}
minNum, ok := test.params["min"].(int)
@@ -182,10 +183,10 @@ func TestBadIntRandom(t *testing.T) {
return
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err == nil {
t.Fatalf("int.random expected to fail but got payload: %s", got)
t.Fatalf("int.random expected to fail but got payload: %+v", got)
}
if err.Error() != test.errorString {

View File

@@ -3,6 +3,7 @@ package processor_test
import (
"testing"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
@@ -68,14 +69,14 @@ func TestGoodIntScale(t *testing.T) {
t.Fatalf("int.scale failed to create processor: %s", err)
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err != nil {
t.Fatalf("int.scale processing failed: %s", err)
}
gotInt, ok := got.(int)
gotInt, ok := got.Payload.(int)
if !ok {
t.Fatalf("int.scale returned a %T payload: %s", got, got)
t.Fatalf("int.scale returned a %T payload: %+v", got, got)
}
if gotInt != test.expected {
@@ -156,10 +157,10 @@ func TestBadIntScale(t *testing.T) {
return
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err == nil {
t.Fatalf("int.scale expected to fail but got payload: %s", got)
t.Fatalf("int.scale expected to fail but got payload: %+v", got)
}
if err.Error() != test.errorString {

View File

@@ -4,6 +4,7 @@ import (
"reflect"
"testing"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
@@ -31,12 +32,12 @@ func TestJsonDecodeFromRegistry(t *testing.T) {
"property": "hello",
}
got, err := processorInstance.Process(t.Context(), payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), payload))
if err != nil {
t.Fatalf("json.decode processing failed: %s", err)
}
gotMap, ok := got.(map[string]any)
gotMap, ok := got.Payload.(map[string]any)
if !ok {
t.Fatalf("json.decode should return byte slice")
@@ -74,18 +75,18 @@ func TestGoodJsonDecode(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := jsonDecoder.Process(t.Context(), test.payload)
got, err := jsonDecoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err != nil {
t.Fatalf("json.decode processing failed: %s", err)
}
gotMap, ok := got.(map[string]any)
gotMap, ok := got.Payload.(map[string]any)
if !ok {
t.Fatalf("json.decode returned a %T payload: %s", got, got)
t.Fatalf("json.decode returned a %T payload: %+v", got, got)
}
if !reflect.DeepEqual(gotMap, test.expected) {
t.Fatalf("json.decode got %x, expected %s", got, test.expected)
t.Fatalf("json.decode got %+v, expected %s", got, test.expected)
}
})
}
@@ -112,7 +113,7 @@ func TestBadJsonDecode(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := stringEncoder.Process(t.Context(), test.payload)
got, err := stringEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err == nil {
t.Fatalf("json.decode expected to fail but got payload: %+v", got)

View File

@@ -5,6 +5,7 @@ import (
"testing"
"github.com/jwetzell/osc-go"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
@@ -34,15 +35,15 @@ func TestJsonEncodeFromRegistry(t *testing.T) {
expected := []byte("{\"property\":\"hello\"}")
got, err := processorInstance.Process(t.Context(), payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), payload))
if err != nil {
t.Fatalf("json.encode processing failed: %s", err)
}
gotBytes, ok := got.([]byte)
gotBytes, ok := got.Payload.([]byte)
if !ok {
t.Fatalf("json.encode should return byte slice")
t.Fatalf("json.encode should return byte slice got %T: %+v", got.Payload, got.Payload)
}
if !slices.Equal(gotBytes, expected) {
@@ -68,18 +69,18 @@ func TestGoodJsonEncode(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := jsonEncoder.Process(t.Context(), test.payload)
got, err := jsonEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err != nil {
t.Fatalf("json.encode processing failed: %s", err)
}
gotBytes, ok := got.([]byte)
gotBytes, ok := got.Payload.([]byte)
if !ok {
t.Fatalf("json.encode returned a %T payload: %s", got, got)
t.Fatalf("json.encode returned a %T payload: %+v", got.Payload, got.Payload)
}
if !slices.Equal(gotBytes, test.expected) {
t.Fatalf("json.encode got %x, expected %s", got, test.expected)
t.Fatalf("json.encode got %+v, expected %s", got, test.expected)
}
})
}
@@ -101,7 +102,7 @@ func TestBadJsonEncode(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := stringEncoder.Process(t.Context(), test.payload)
got, err := stringEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err == nil {
t.Fatalf("json.encode expected to fail but got payload: %+v", got)

View File

@@ -4,6 +4,7 @@ import (
"reflect"
"testing"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
"gitlab.com/gomidi/midi/v2"
@@ -103,14 +104,14 @@ func TestGoodMIDIMessageCreate(t *testing.T) {
t.Fatalf("midi.message.create failed to create processor: %s", err)
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err != nil {
t.Fatalf("midi.message.create processing failed: %s", err)
}
gotMessage, ok := got.(midi.Message)
gotMessage, ok := got.Payload.(midi.Message)
if !ok {
t.Fatalf("midi.message.create returned a %T payload: %s", got, got)
t.Fatalf("midi.message.create returned a %T payload: %+v", got, got)
}
if !reflect.DeepEqual(gotMessage, test.expected) {
@@ -279,7 +280,7 @@ func TestBadMIDIMessageCreate(t *testing.T) {
return
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err == nil {
t.Fatalf("midi.message.create expected to fail but succeeded, got: %v", got)

View File

@@ -4,6 +4,7 @@ import (
"reflect"
"testing"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
"gitlab.com/gomidi/midi/v2"
@@ -44,14 +45,14 @@ func TestGoodMIDIMessageDecode(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err != nil {
t.Fatalf("midi.message.decode processing failed: %s", err)
}
gotMessage, ok := got.(midi.Message)
gotMessage, ok := got.Payload.(midi.Message)
if !ok {
t.Fatalf("midi.message.decode returned a %T payload: %s", got, got)
t.Fatalf("midi.message.decode returned a %T payload: %+v", got, got)
}
if !reflect.DeepEqual(gotMessage, test.expected) {
@@ -78,7 +79,7 @@ func TestBadMIDIMessageDecode(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err == nil {
t.Fatalf("midi.message.decode expected to fail but succeeded, got: %v", got)

View File

@@ -4,6 +4,7 @@ import (
"slices"
"testing"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
"gitlab.com/gomidi/midi/v2"
@@ -44,14 +45,14 @@ func TestGoodMIDIMessageEncode(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := midiMessageEncoder.Process(t.Context(), test.payload)
got, err := midiMessageEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err != nil {
t.Fatalf("midi.message.encode processing failed: %s", err)
}
gotBytes, ok := got.([]byte)
gotBytes, ok := got.Payload.([]byte)
if !ok {
t.Fatalf("midi.message.encode returned a %T payload: %s", got, got)
t.Fatalf("midi.message.encode returned a %T payload: %+v", got, got)
}
if !slices.Equal(gotBytes, test.expected) {
@@ -77,10 +78,10 @@ func TestBadMIDIMessageEncode(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := midiMessageEncoder.Process(t.Context(), test.payload)
got, err := midiMessageEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err == nil {
t.Fatalf("midi.message.encode expected to fail but got payload: %s", got)
t.Fatalf("midi.message.encode expected to fail but got payload: %+v", got)
}
if err.Error() != test.errorString {
t.Fatalf("midi.message.encode got error '%s', expected '%s'", err.Error(), test.errorString)

View File

@@ -5,6 +5,7 @@ import (
"testing"
mqtt "github.com/eclipse/paho.mqtt.golang"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
@@ -103,22 +104,22 @@ func TestGoodMQTTMessageCreate(t *testing.T) {
t.Fatalf("mqtt.message.create failed to create processor: %s", err)
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err != nil {
t.Fatalf("mqtt.message.create processing failed: %s", err)
}
if test.expected == nil {
if got != nil {
if got.Payload != nil {
t.Fatalf("mqtt.message.create got %+v, expected nil", got)
}
return
}
gotMessage, ok := got.(mqtt.Message)
gotMessage, ok := got.Payload.(mqtt.Message)
if !ok {
t.Fatalf("mqtt.message.create returned a %T payload: %s", got, got)
t.Fatalf("mqtt.message.create returned a %T payload: %+v", got, got)
}
if !reflect.DeepEqual(gotMessage, test.expected) {
@@ -227,7 +228,7 @@ func TestBadMQTTMessageCreate(t *testing.T) {
return
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err == nil {
t.Fatalf("mqtt.message.create expected to fail but succeeded, got: %v", got)

View File

@@ -5,6 +5,7 @@ import (
"testing"
mqtt "github.com/eclipse/paho.mqtt.golang"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
@@ -44,18 +45,18 @@ func TestGoodMQTTMessageEncode(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := stringEncoder.Process(t.Context(), test.payload)
got, err := stringEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err != nil {
t.Fatalf("mqtt.message.encode processing failed: %s", err)
}
gotBytes, ok := got.([]byte)
gotBytes, ok := got.Payload.([]byte)
if !ok {
t.Fatalf("mqtt.message.encode returned a %T payload: %s", got, got)
t.Fatalf("mqtt.message.encode returned a %T payload: %+v", got, got)
}
if !slices.Equal(gotBytes, test.expected) {
t.Fatalf("mqtt.message.encode got %s, expected %s", got, test.expected)
t.Fatalf("mqtt.message.encode got %+v, expected %s", got, test.expected)
}
})
}
@@ -77,10 +78,10 @@ func TestBadMQTTMessageEncode(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := stringEncoder.Process(t.Context(), test.payload)
got, err := stringEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err == nil {
t.Fatalf("mqtt.message.encode expected to fail but got payload: %s", got)
t.Fatalf("mqtt.message.encode expected to fail but got payload: %+v", got)
}
if err.Error() != test.errorString {
t.Fatalf("mqtt.message.encode got error '%s', expected '%s'", err.Error(), test.errorString)

View File

@@ -5,6 +5,7 @@ import (
"testing"
"github.com/jwetzell/osc-go"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
@@ -149,22 +150,22 @@ func TestGoodOSCMessageCreate(t *testing.T) {
t.Fatalf("osc.message.create failed to create processor: %s", err)
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err != nil {
t.Fatalf("osc.message.create processing failed: %s", err)
}
if test.expected == nil {
if got != nil {
if got.Payload != nil {
t.Fatalf("osc.message.create got %+v, expected nil", got)
}
return
}
gotMessage, ok := got.(*osc.OSCMessage)
gotMessage, ok := got.Payload.(*osc.OSCMessage)
if !ok {
t.Fatalf("osc.message.create returned a %T payload: %s", got, got)
t.Fatalf("osc.message.create returned a %T payload: %+v", got, got)
}
if !reflect.DeepEqual(gotMessage, test.expected) {
@@ -286,7 +287,7 @@ func TestBadOSCMessageCreate(t *testing.T) {
"address": "/test/{{.missing}}",
},
payload: "test",
errorString: "template: address:1:8: executing \"address\" at <.missing>: can't evaluate field missing in type processor.TemplateData",
errorString: "template: address:1:8: executing \"address\" at <.missing>: can't evaluate field missing in type common.WrappedPayload",
},
{
name: "address doesn't start with slash",
@@ -304,7 +305,7 @@ func TestBadOSCMessageCreate(t *testing.T) {
"types": "s",
},
payload: "test",
errorString: "template: arg:1:2: executing \"arg\" at <.missing>: can't evaluate field missing in type processor.TemplateData",
errorString: "template: arg:1:2: executing \"arg\" at <.missing>: can't evaluate field missing in type common.WrappedPayload",
},
}
@@ -327,7 +328,7 @@ func TestBadOSCMessageCreate(t *testing.T) {
return
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err == nil {
t.Fatalf("osc.message.create expected to fail but succeeded, got: %v", got)

View File

@@ -5,6 +5,7 @@ import (
"testing"
"github.com/jwetzell/osc-go"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
@@ -60,15 +61,15 @@ func TestGoodOSCMessageDecode(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err != nil {
t.Fatalf("osc.message.decode processing failed: %s", err)
}
gotMessage, ok := got.(*osc.OSCMessage)
gotMessage, ok := got.Payload.(*osc.OSCMessage)
if !ok {
t.Fatalf("osc.message.decode returned a %T payload: %s", got, got)
t.Fatalf("osc.message.decode returned a %T payload: %+v", got, got)
}
if !reflect.DeepEqual(gotMessage, test.expected) {
@@ -109,10 +110,10 @@ func TestBadOSCMessageDecode(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err == nil {
t.Fatalf("osc.message.decode expected to fail but got payload: %s", got)
t.Fatalf("osc.message.decode expected to fail but got payload: %+v", got)
}
if err.Error() != test.errorString {
t.Fatalf("osc.message.decode got error '%s', expected '%s'", err.Error(), test.errorString)

View File

@@ -5,6 +5,7 @@ import (
"testing"
"github.com/jwetzell/osc-go"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
@@ -59,14 +60,14 @@ func TestGoodOSCMessageEncode(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err != nil {
t.Fatalf("osc.message.encode processing failed: %s", err)
}
gotBytes, ok := got.([]byte)
gotBytes, ok := got.Payload.([]byte)
if !ok {
t.Fatalf("osc.message.encode returned a %T payload: %s", got, got)
t.Fatalf("osc.message.encode returned a %T payload: %+v", got, got)
}
if !slices.Equal(gotBytes, test.expected) {
@@ -92,10 +93,10 @@ func TestBadOSCMessageEncode(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err == nil {
t.Fatalf("osc.message.encode expected to fail but got payload: %s", got)
t.Fatalf("osc.message.encode expected to fail but got payload: %+v", got)
}
if err.Error() != test.errorString {
t.Fatalf("osc.message.encode got error '%s', expected '%s'", err.Error(), test.errorString)

View File

@@ -4,6 +4,7 @@ import (
"context"
"testing"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
@@ -44,8 +45,8 @@ type TestProcessor struct {
func (p *TestProcessor) Type() string {
return "test"
}
func (p *TestProcessor) Process(ctx context.Context, input any) (any, error) {
return input, nil
func (p *TestProcessor) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
return wrappedPayload, nil
}
func TestProcessorBadRegistrationNoType(t *testing.T) {

View File

@@ -3,6 +3,7 @@ package processor_test
import (
"testing"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
@@ -75,14 +76,14 @@ func TestGoodScriptExpr(t *testing.T) {
t.Fatalf("script.expr failed to create processor: %s", err)
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err != nil {
t.Fatalf("script.expr processing failed: %s", err)
}
//TODO(jwetzell): work out better way to compare the any/any
if got != test.expected {
if got.Payload != test.expected {
t.Fatalf("script.expr got %+v (%T), expected %+v (%T)", got, got, test.expected, test.expected)
}
})
@@ -133,7 +134,7 @@ func TestBadScriptExpr(t *testing.T) {
return
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err == nil {
t.Fatalf("script.expr expected to fail but succeeded, got: %v", got)

View File

@@ -4,6 +4,7 @@ import (
"maps"
"testing"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
@@ -33,12 +34,12 @@ func TestScriptJSFromRegistry(t *testing.T) {
payload := 1
expected := 2
got, err := processorInstance.Process(t.Context(), payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), payload))
if err != nil {
t.Fatalf("script.js processing failed: %s", err)
}
if got != expected {
if got.Payload != expected {
t.Fatalf("script.js got %+v, expected %+v", got, expected)
}
}
@@ -142,7 +143,7 @@ func TestGoodScriptJS(t *testing.T) {
t.Fatalf("script.js failed to create processor: %s", err)
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err != nil {
t.Fatalf("script.js processing failed: %s", err)
@@ -150,7 +151,7 @@ func TestGoodScriptJS(t *testing.T) {
//TODO(jwetzell): work out better way to compare the any/any
gotMap, ok := got.(map[string]interface{})
gotMap, ok := got.Payload.(map[string]interface{})
if ok {
// got a map
expectedMap, ok := test.expected.(map[string]interface{})
@@ -162,8 +163,8 @@ func TestGoodScriptJS(t *testing.T) {
t.Fatalf("script.js got %+v, expected %+v", got, test.expected)
}
} else {
if got != test.expected {
t.Fatalf("script.js got %+v, expected %+v", got, test.expected)
if got.Payload != test.expected {
t.Fatalf("script.js got %+v, expected %+v", got.Payload, test.expected)
}
}
})
@@ -201,7 +202,7 @@ func TestBadScriptJS(t *testing.T) {
Params: test.params,
})
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err == nil {
t.Fatalf("script.js expected to fail but succeeded, got: %v", got)

View File

@@ -4,6 +4,7 @@ import (
"slices"
"testing"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
@@ -74,15 +75,15 @@ func TestGoodScriptWASM(t *testing.T) {
t.Fatalf("script.wasm failed to create processor: %s", err)
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err != nil {
t.Fatalf("script.wasm processing failed: %s", err)
}
gotBytes, ok := got.([]byte)
gotBytes, ok := got.Payload.([]byte)
if !ok {
t.Fatalf("script.wasm returned a %T payload: %s", got, got)
t.Fatalf("script.wasm returned a %T payload: %+v", got, got)
}
if !slices.Equal(gotBytes, test.expected) {
@@ -180,7 +181,7 @@ func TestBadScriptWASM(t *testing.T) {
return
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err == nil {
t.Fatalf("script.wasm expected to fail but succeeded, got: %v", got)

View File

@@ -3,6 +3,7 @@ package processor_test
import (
"testing"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
@@ -30,12 +31,12 @@ func TestStringCreateFromRegistry(t *testing.T) {
payload := "hello"
expected := "hello"
got, err := processorInstance.Process(t.Context(), payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), payload))
if err != nil {
t.Fatalf("string.create processing failed: %s", err)
}
if got != expected {
if got.Payload != expected {
t.Fatalf("string.create got %+v, expected %+v", got, expected)
}
}
@@ -96,18 +97,18 @@ func TestGoodStringCreate(t *testing.T) {
t.Fatalf("string.create failed to create processor: %s", err)
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err != nil {
t.Fatalf("string.create processing failed: %s", err)
}
gotStrings, ok := got.(string)
gotStrings, ok := got.Payload.(string)
if !ok {
t.Fatalf("string.create returned a %T payload: %s", got, got)
t.Fatalf("string.create returned a %T payload: %+v", got, got)
}
if gotStrings != test.expected {
t.Fatalf("string.create got %s, expected %s", got, test.expected)
t.Fatalf("string.create got %+v, expected %s", got, test.expected)
}
})
}
@@ -148,7 +149,7 @@ func TestBadStringCreate(t *testing.T) {
params: map[string]any{
"template": "{{.Invalid}}",
},
errorString: "template: template:1:2: executing \"template\" at <.Invalid>: can't evaluate field Invalid in type processor.TemplateData",
errorString: "template: template:1:2: executing \"template\" at <.Invalid>: can't evaluate field Invalid in type common.WrappedPayload",
},
}
@@ -172,10 +173,10 @@ func TestBadStringCreate(t *testing.T) {
return
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err == nil {
t.Fatalf("string.create expected to fail but got payload: %s", got)
t.Fatalf("string.create expected to fail but got payload: %+v", got)
}
if err.Error() != test.errorString {

View File

@@ -3,6 +3,7 @@ package processor_test
import (
"testing"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
@@ -27,12 +28,12 @@ func TestStringDecodeFromRegistry(t *testing.T) {
payload := []byte{'h', 'e', 'l', 'l', 'o'}
expected := "hello"
got, err := processorInstance.Process(t.Context(), payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), payload))
if err != nil {
t.Fatalf("string.decode processing failed: %s", err)
}
if got != expected {
if got.Payload != expected {
t.Fatalf("string.decode got %+v, expected %+v", got, expected)
}
}
@@ -53,18 +54,18 @@ func TestGoodStringDecode(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := stringDecoder.Process(t.Context(), test.payload)
got, err := stringDecoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err != nil {
t.Fatalf("string.decode processing failed: %s", err)
}
gotString, ok := got.(string)
gotString, ok := got.Payload.(string)
if !ok {
t.Fatalf("string.decode returned a %T payload: %s", got, got)
t.Fatalf("string.decode returned a %T payload: %+v", got, got)
}
if gotString != test.expected {
t.Fatalf("string.decode got %s, expected %s", got, test.expected)
t.Fatalf("string.decode got %+v, expected %s", got, test.expected)
}
})
}
@@ -86,10 +87,10 @@ func TestBadStringDecode(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := stringDecoder.Process(t.Context(), test.payload)
got, err := stringDecoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err == nil {
t.Fatalf("string.decode expected to fail but got payload: %s", got)
t.Fatalf("string.decode expected to fail but got payload: %+v", got)
}
if err.Error() != test.errorString {
t.Fatalf("string.decode got error '%s', expected '%s'", err.Error(), test.errorString)

View File

@@ -4,6 +4,7 @@ import (
"slices"
"testing"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
@@ -28,12 +29,12 @@ func TestStringEncodeFromRegistry(t *testing.T) {
payload := "hello"
expected := []byte{'h', 'e', 'l', 'l', 'o'}
got, err := processorInstance.Process(t.Context(), payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), payload))
if err != nil {
t.Fatalf("string.encode processing failed: %s", err)
}
gotBytes, ok := got.([]byte)
gotBytes, ok := got.Payload.([]byte)
if !ok {
t.Fatalf("string.encode should return byte slice")
@@ -60,14 +61,14 @@ func TestGoodStringEncode(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := stringEncoder.Process(t.Context(), test.payload)
got, err := stringEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err != nil {
t.Fatalf("string.encode processing failed: %s", err)
}
gotBytes, ok := got.([]byte)
gotBytes, ok := got.Payload.([]byte)
if !ok {
t.Fatalf("string.encode returned a %T payload: %s", got, got)
t.Fatalf("string.encode returned a %T payload: %+v", got, got)
}
if !slices.Equal(gotBytes, test.expected) {
t.Fatalf("string.encode got %+v, expected %+v", gotBytes, test.expected)
@@ -92,10 +93,10 @@ func TestBadStringEncode(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, err := stringEncoder.Process(t.Context(), test.payload)
got, err := stringEncoder.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err == nil {
t.Fatalf("string.encode expected to fail but got payload: %s", got)
t.Fatalf("string.encode expected to fail but got payload: %+v", got)
}
if err.Error() != test.errorString {
t.Fatalf("string.encode got error '%s', expected '%s'", err.Error(), test.errorString)

View File

@@ -4,6 +4,7 @@ import (
"slices"
"testing"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
@@ -31,12 +32,12 @@ func TestStringSplitFromRegistry(t *testing.T) {
payload := "part1,part2,part3"
expected := []string{"part1", "part2", "part3"}
got, err := processorInstance.Process(t.Context(), payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), payload))
if err != nil {
t.Fatalf("string.split processing failed: %s", err)
}
gotStrings, ok := got.([]string)
gotStrings, ok := got.Payload.([]string)
if !ok {
t.Fatalf("string.split should return a slice of strings")
@@ -78,14 +79,14 @@ func TestGoodStringSplit(t *testing.T) {
t.Fatalf("string.split failed to create processor: %s", err)
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err != nil {
t.Fatalf("string.split processing failed: %s", err)
}
gotStrings, ok := got.([]string)
gotStrings, ok := got.Payload.([]string)
if !ok {
t.Fatalf("string.split returned a %T payload: %s", got, got)
t.Fatalf("string.split returned a %T payload: %+v", got, got)
}
if !slices.Equal(gotStrings, test.expected) {
@@ -141,10 +142,10 @@ func TestBadStringSplit(t *testing.T) {
return
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err == nil {
t.Fatalf("string.split expected error but got none, payload: %s", got)
t.Fatalf("string.split expected error but got none, payload: %+v", got)
}
if err.Error() != test.errorString {
t.Fatalf("string.split got error '%s', expected '%s'", err.Error(), test.errorString)

View File

@@ -3,6 +3,7 @@ package processor_test
import (
"testing"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
@@ -30,12 +31,12 @@ func TestStructFieldGetFromRegistry(t *testing.T) {
payload := TestStruct{Data: "hello"}
expected := "hello"
got, err := processorInstance.Process(t.Context(), payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), payload))
if err != nil {
t.Fatalf("struct.field.get processing failed: %s", err)
}
if got != expected {
if got.Payload != expected {
t.Fatalf("struct.field.get got %+v, expected %+v", got, expected)
}
}
@@ -96,14 +97,14 @@ func TestGoodStructFieldGet(t *testing.T) {
t.Fatalf("struct.field.get failed to create processor: %s", err)
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err != nil {
t.Fatalf("struct.field.get processing failed: %s", err)
}
if got != test.expected {
t.Fatalf("struct.field.get got %s, expected %s", got, test.expected)
if got.Payload != test.expected {
t.Fatalf("struct.field.get got %+v, expected %s", got, test.expected)
}
})
}
@@ -168,10 +169,10 @@ func TestBadStructFieldGet(t *testing.T) {
return
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err == nil {
t.Fatalf("struct.field.get expected to fail but got payload: %s", got)
t.Fatalf("struct.field.get expected to fail but got payload: %+v", got)
}
if err.Error() != test.errorString {

View File

@@ -4,6 +4,7 @@ import (
"reflect"
"testing"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
@@ -31,12 +32,12 @@ func TestStructMethodGetFromRegistry(t *testing.T) {
payload := TestStruct{Data: "hello"}
expected := "hello"
got, err := processorInstance.Process(t.Context(), payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), payload))
if err != nil {
t.Fatalf("struct.method.get processing failed: %s", err)
}
if got != expected {
if got.Payload != expected {
t.Fatalf("struct.method.get got %+v, expected %+v", got, expected)
}
}
@@ -115,14 +116,14 @@ func TestGoodStructMethodGet(t *testing.T) {
t.Fatalf("struct.method.get failed to create processor: %s", err)
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err != nil {
t.Fatalf("struct.method.get processing failed: %s", err)
}
if !reflect.DeepEqual(got, test.expected) {
t.Fatalf("struct.method.get got %+v, expected %+v", got, test.expected)
if !reflect.DeepEqual(got.Payload, test.expected) {
t.Fatalf("struct.method.get got payload: %+v, expected %+v", got.Payload, test.expected)
}
})
}
@@ -187,10 +188,10 @@ func TestBadStructMethodGet(t *testing.T) {
return
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err == nil {
t.Fatalf("struct.method.get expected to fail but got payload: %s", got)
t.Fatalf("struct.method.get expected to fail but got payload: %+v", got)
}
if err.Error() != test.errorString {

View File

@@ -3,6 +3,7 @@ package processor_test
import (
"testing"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
@@ -58,13 +59,13 @@ func TestGoodTimeSleep(t *testing.T) {
t.Fatalf("time.sleep failed to create processor: %s", err)
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err != nil {
t.Fatalf("time.sleep processing failed: %s", err)
}
if got != test.payload {
if got.Payload != test.payload {
t.Fatalf("time.sleep got %+v, expected %+v", got, test.payload)
}
})
@@ -113,7 +114,7 @@ func TestBadTimeSleep(t *testing.T) {
return
}
got, err := processorInstance.Process(t.Context(), test.payload)
got, err := processorInstance.Process(t.Context(), common.GetWrappedPayload(t.Context(), test.payload))
if err == nil {
t.Fatalf("time.sleep expected to fail but succeeded, got: %v", got)