Files
showbridge-go/internal/processor/test/processor_test.go
2026-03-17 19:33:41 -05:00

103 lines
2.1 KiB
Go

package processor_test
import (
"context"
"testing"
"github.com/jwetzell/showbridge-go/internal/common"
"github.com/jwetzell/showbridge-go/internal/config"
"github.com/jwetzell/showbridge-go/internal/processor"
)
type TestStruct struct {
String string
Int int
Float float64
Bool bool
Data any
IntSlice []int
}
func (t TestStruct) GetString() string {
return t.String
}
func (t TestStruct) GetInt() int {
return t.Int
}
func (t TestStruct) GetFloat() float64 {
return t.Float
}
func (t TestStruct) GetBool() bool {
return t.Bool
}
func (t TestStruct) GetData() any {
return t.Data
}
func (t TestStruct) GetIntSlice() []int {
return t.IntSlice
}
func (t TestStruct) Void() {}
func (t TestStruct) MultipleReturnValues() (string, int) {
return t.String, t.Int
}
type TestProcessor struct {
}
func (p *TestProcessor) Type() string {
return "test"
}
func (p *TestProcessor) Process(ctx context.Context, wrappedPayload common.WrappedPayload) (common.WrappedPayload, error) {
return wrappedPayload, nil
}
func TestProcessorBadRegistrationNoType(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Fatalf("processor registration should have panicked but did not")
}
}()
processor.RegisterProcessor(processor.ProcessorRegistration{
Type: "",
New: func(config config.ProcessorConfig) (processor.Processor, error) {
return &TestProcessor{}, nil
},
})
}
func TestProcessorBadRegistrationNoNew(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Fatalf("processor registration should have panicked but did not")
}
}()
processor.RegisterProcessor(processor.ProcessorRegistration{
Type: "test",
New: nil,
})
}
func TestProcessorBadRegistrationExistingType(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Fatalf("processor registration should have panicked but did not")
}
}()
processor.RegisterProcessor(processor.ProcessorRegistration{
Type: "string.create",
New: func(config config.ProcessorConfig) (processor.Processor, error) {
return &TestProcessor{}, nil
},
})
}