mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-29 06:15:31 +00:00
align test err checking and logs
This commit is contained in:
@@ -60,7 +60,7 @@ func TestGoodArtnetPacketDecode(t *testing.T) {
|
||||
got, err := packetDecoder.Process(t.Context(), test.payload)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("artnet.packet.decode failed: %s", err)
|
||||
t.Fatalf("artnet.packet.decode processing failed: %s", err)
|
||||
}
|
||||
|
||||
//TODO(jwetzell): work out better way to compare the any/any
|
||||
|
||||
@@ -60,7 +60,7 @@ func TestGoodArtnetPacketEncode(t *testing.T) {
|
||||
got, err := packetEncoder.Process(t.Context(), test.payload)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("artnet.packet.encode failed: %s", err)
|
||||
t.Fatalf("artnet.packet.encode processing failed: %s", err)
|
||||
}
|
||||
|
||||
//TODO(jwetzell): work out better way to compare the any/any
|
||||
|
||||
@@ -148,7 +148,7 @@ func TestGoodArtnetPacketFilter(t *testing.T) {
|
||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("artnet.packet.filter failed: %s", err)
|
||||
t.Fatalf("artnet.packet.filter processing failed: %s", err)
|
||||
}
|
||||
|
||||
if test.expected == nil {
|
||||
|
||||
@@ -91,7 +91,7 @@ func TestGoodFilterExpr(t *testing.T) {
|
||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("filter.expr failed: %s", err)
|
||||
t.Fatalf("filter.expr processing failed: %s", err)
|
||||
}
|
||||
|
||||
//TODO(jwetzell): work out better way to compare the any/any
|
||||
|
||||
@@ -76,14 +76,14 @@ func TestGoodFloatParse(t *testing.T) {
|
||||
}
|
||||
|
||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
||||
if err != nil {
|
||||
t.Fatalf("float.parse processing failed: %s", err)
|
||||
}
|
||||
|
||||
gotFloat, ok := got.(float64)
|
||||
if !ok {
|
||||
t.Fatalf("float.parse returned a %T payload: %s", got, got)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("float.parse failed: %s", err)
|
||||
}
|
||||
if gotFloat != test.expected {
|
||||
t.Fatalf("float.parse got %f, expected %f", gotFloat, test.expected)
|
||||
}
|
||||
|
||||
@@ -97,14 +97,14 @@ func TestGoodIntParse(t *testing.T) {
|
||||
}
|
||||
|
||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
||||
if err != nil {
|
||||
t.Fatalf("int.parse processing failed: %s", err)
|
||||
}
|
||||
|
||||
gotInt, ok := got.(int64)
|
||||
if !ok {
|
||||
t.Fatalf("int.parse returned a %T payload: %s", got, got)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("int.parse failed: %s", err)
|
||||
}
|
||||
if gotInt != test.expected {
|
||||
t.Fatalf("int.parse got %d, expected %d", gotInt, test.expected)
|
||||
}
|
||||
|
||||
@@ -98,13 +98,14 @@ func TestGoodIntRandom(t *testing.T) {
|
||||
}
|
||||
|
||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
||||
if err != nil {
|
||||
t.Fatalf("int.random processing failed: %s", err)
|
||||
}
|
||||
|
||||
gotInt, ok := got.(int)
|
||||
if !ok {
|
||||
t.Fatalf("int.random returned a %T payload: %s", got, got)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("int.random failed: %s", err)
|
||||
}
|
||||
|
||||
minNum, ok := test.params["min"].(int)
|
||||
if !ok {
|
||||
|
||||
@@ -75,14 +75,15 @@ 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)
|
||||
if err != nil {
|
||||
t.Fatalf("json.decode processing failed: %s", err)
|
||||
}
|
||||
|
||||
gotMap, ok := got.(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("json.decode returned a %T payload: %s", got, got)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("json.decode failed: %s", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(gotMap, test.expected) {
|
||||
t.Fatalf("json.decode got %x, expected %s", got, test.expected)
|
||||
}
|
||||
|
||||
@@ -69,14 +69,15 @@ 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)
|
||||
if err != nil {
|
||||
t.Fatalf("json.encode processing failed: %s", err)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -104,14 +104,15 @@ func TestGoodMIDIMessageCreate(t *testing.T) {
|
||||
}
|
||||
|
||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
||||
if err != nil {
|
||||
t.Fatalf("midi.message.create processing failed: %s", err)
|
||||
}
|
||||
|
||||
gotMessage, ok := got.(midi.Message)
|
||||
if !ok {
|
||||
t.Fatalf("midi.message.create returned a %T payload: %s", got, got)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("midi.message.create failed: %s", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(gotMessage, test.expected) {
|
||||
t.Fatalf("midi.message.create got %v, expected %v", gotMessage, test.expected)
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ func TestGoodMIDIMessageDecode(t *testing.T) {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
||||
if err != nil {
|
||||
t.Fatalf("midi.message.decode failed: %s", err)
|
||||
t.Fatalf("midi.message.decode processing failed: %s", err)
|
||||
}
|
||||
|
||||
gotMessage, ok := got.(midi.Message)
|
||||
|
||||
@@ -45,14 +45,15 @@ 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)
|
||||
if err != nil {
|
||||
t.Fatalf("midi.message.encode processing failed: %s", err)
|
||||
}
|
||||
|
||||
gotBytes, ok := got.([]byte)
|
||||
if !ok {
|
||||
t.Fatalf("midi.message.encode returned a %T payload: %s", got, got)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("midi.message.encode failed: %s", err)
|
||||
}
|
||||
|
||||
if !slices.Equal(gotBytes, test.expected) {
|
||||
t.Fatalf("midi.message.encode got %+v, expected %+v", got, test.expected)
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ func TestGoodMIDIMessageFilter(t *testing.T) {
|
||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("midi.message.filter failed: %s", err)
|
||||
t.Fatalf("midi.message.filter processing failed: %s", err)
|
||||
}
|
||||
|
||||
if test.expected == nil {
|
||||
|
||||
@@ -106,7 +106,7 @@ func TestGoodMQTTMessageCreate(t *testing.T) {
|
||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("mqtt.message.create process failed: %s", err)
|
||||
t.Fatalf("mqtt.message.create processing failed: %s", err)
|
||||
}
|
||||
|
||||
if test.expected == nil {
|
||||
|
||||
@@ -45,14 +45,15 @@ 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)
|
||||
if err != nil {
|
||||
t.Fatalf("mqtt.message.encode processing failed: %s", err)
|
||||
}
|
||||
|
||||
gotBytes, ok := got.([]byte)
|
||||
if !ok {
|
||||
t.Fatalf("mqtt.message.encode returned a %T payload: %s", got, got)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("mqtt.message.encode failed: %s", err)
|
||||
}
|
||||
|
||||
if !slices.Equal(gotBytes, test.expected) {
|
||||
t.Fatalf("mqtt.message.encode got %s, expected %s", got, test.expected)
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ func TestGoodOSCMessageCreate(t *testing.T) {
|
||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("osc.message.create process failed: %s", err)
|
||||
t.Fatalf("osc.message.create processing failed: %s", err)
|
||||
}
|
||||
|
||||
if test.expected == nil {
|
||||
|
||||
@@ -75,7 +75,7 @@ func TestGoodOSCMessageFilter(t *testing.T) {
|
||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("osc.message.filter process failed: %s", err)
|
||||
t.Fatalf("osc.message.filter processing failed: %s", err)
|
||||
}
|
||||
|
||||
if test.expected == nil {
|
||||
|
||||
@@ -36,6 +36,8 @@ func (t TestStruct) GetData() any {
|
||||
return t.Data
|
||||
}
|
||||
|
||||
func (t TestStruct) Void() {}
|
||||
|
||||
type TestProcessor struct {
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ func TestGoodScriptExpr(t *testing.T) {
|
||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("script.expr failed: %s", err)
|
||||
t.Fatalf("script.expr processing failed: %s", err)
|
||||
}
|
||||
|
||||
//TODO(jwetzell): work out better way to compare the any/any
|
||||
|
||||
@@ -145,7 +145,7 @@ func TestGoodScriptJS(t *testing.T) {
|
||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("script.js process failed: %s", err)
|
||||
t.Fatalf("script.js processing failed: %s", err)
|
||||
}
|
||||
|
||||
//TODO(jwetzell): work out better way to compare the any/any
|
||||
|
||||
@@ -77,7 +77,7 @@ func TestGoodScriptWASM(t *testing.T) {
|
||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("script.wasm process failed: %s", err)
|
||||
t.Fatalf("script.wasm processing failed: %s", err)
|
||||
}
|
||||
|
||||
gotBytes, ok := got.([]byte)
|
||||
|
||||
@@ -98,13 +98,14 @@ func TestGoodStringCreate(t *testing.T) {
|
||||
|
||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("string.create processing failed: %s", err)
|
||||
}
|
||||
|
||||
gotStrings, ok := got.(string)
|
||||
if !ok {
|
||||
t.Fatalf("string.create returned a %T payload: %s", got, got)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("string.create failed: %s", err)
|
||||
}
|
||||
if gotStrings != test.expected {
|
||||
t.Fatalf("string.create got %s, expected %s", got, test.expected)
|
||||
}
|
||||
|
||||
@@ -54,14 +54,15 @@ 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)
|
||||
if err != nil {
|
||||
t.Fatalf("string.decode processing failed: %s", err)
|
||||
}
|
||||
|
||||
gotString, ok := got.(string)
|
||||
if !ok {
|
||||
t.Fatalf("string.decode returned a %T payload: %s", got, got)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("string.decode failed: %s", err)
|
||||
}
|
||||
|
||||
if gotString != test.expected {
|
||||
t.Fatalf("string.decode got %s, expected %s", got, test.expected)
|
||||
}
|
||||
|
||||
@@ -61,16 +61,16 @@ 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)
|
||||
if err != nil {
|
||||
t.Fatalf("string.encode processing failed: %s", err)
|
||||
}
|
||||
|
||||
gotBytes, ok := got.([]byte)
|
||||
if !ok {
|
||||
t.Fatalf("string.encode returned a %T payload: %s", got, got)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("string.encode failed: %s", err)
|
||||
}
|
||||
if !slices.Equal(gotBytes, test.expected) {
|
||||
t.Fatalf("string.encode got %s, expected %s", got, test.expected)
|
||||
t.Fatalf("string.encode got %+v, expected %+v", gotBytes, test.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ func TestGoodStringFilter(t *testing.T) {
|
||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("string.filter failed: %s", err)
|
||||
t.Fatalf("string.filter processing failed: %s", err)
|
||||
}
|
||||
|
||||
if test.expected == nil {
|
||||
|
||||
@@ -79,16 +79,17 @@ func TestGoodStringSplit(t *testing.T) {
|
||||
}
|
||||
|
||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
||||
if err != nil {
|
||||
t.Fatalf("string.split processing failed: %s", err)
|
||||
}
|
||||
|
||||
gotStrings, ok := got.([]string)
|
||||
if !ok {
|
||||
t.Fatalf("string.split returned a %T payload: %s", got, got)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("string.split failed: %s", err)
|
||||
}
|
||||
|
||||
if !slices.Equal(gotStrings, test.expected) {
|
||||
t.Fatalf("string.split got %s, expected %s", got, test.expected)
|
||||
t.Fatalf("string.split got %+v, expected %+v", gotStrings, test.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ func TestGoodStructFieldGet(t *testing.T) {
|
||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("struct.field.get failed: %s", err)
|
||||
t.Fatalf("struct.field.get processing failed: %s", err)
|
||||
}
|
||||
|
||||
if got != test.expected {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package processor_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
@@ -93,11 +94,11 @@ func TestGoodStructMethodGet(t *testing.T) {
|
||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("struct.method.get failed: %s", err)
|
||||
t.Fatalf("struct.method.get processing failed: %s", err)
|
||||
}
|
||||
|
||||
if got != test.expected {
|
||||
t.Fatalf("struct.method.get got %s, expected %s", got, test.expected)
|
||||
if !reflect.DeepEqual(got, test.expected) {
|
||||
t.Fatalf("struct.method.get got %+v, expected %+v", got, test.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ func TestGoodTimeSleep(t *testing.T) {
|
||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("time.sleep failed: %s", err)
|
||||
t.Fatalf("time.sleep processing failed: %s", err)
|
||||
}
|
||||
|
||||
if got != test.payload {
|
||||
|
||||
@@ -77,14 +77,15 @@ func TestGoodUintParse(t *testing.T) {
|
||||
}
|
||||
|
||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
||||
if err != nil {
|
||||
t.Fatalf("uint.parse processing failed: %s", err)
|
||||
}
|
||||
|
||||
gotUint, ok := got.(uint64)
|
||||
if !ok {
|
||||
t.Fatalf("uint.parse returned a %T payload: %s", got, got)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("uint.parse failed: %s", err)
|
||||
}
|
||||
|
||||
if gotUint != test.expected {
|
||||
t.Fatalf("uint.parse got %d, expected %d", gotUint, test.expected)
|
||||
}
|
||||
|
||||
@@ -96,14 +96,15 @@ func TestGoodUintRandom(t *testing.T) {
|
||||
}
|
||||
|
||||
got, err := processorInstance.Process(t.Context(), test.payload)
|
||||
if err != nil {
|
||||
t.Fatalf("uint.random processing failed: %s", err)
|
||||
}
|
||||
|
||||
gotUint, ok := got.(uint)
|
||||
if !ok {
|
||||
t.Fatalf("uint.random returned a %T payload: %s", got, got)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("uint.random failed: %s", err)
|
||||
}
|
||||
|
||||
minNum, ok := test.params["min"].(int)
|
||||
if !ok {
|
||||
t.Fatalf("uint.random test min param is not a number")
|
||||
|
||||
Reference in New Issue
Block a user