mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-27 05:15:47 +00:00
add complete test coverage for string processors
This commit is contained in:
@@ -4,9 +4,46 @@ import (
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/showbridge-go/internal/config"
|
||||
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||
)
|
||||
|
||||
func TestStringEncodeFromRegistry(t *testing.T) {
|
||||
registration, ok := processor.ProcessorRegistry["string.encode"]
|
||||
if !ok {
|
||||
t.Fatalf("string.encode processor not registered")
|
||||
}
|
||||
|
||||
processorInstance, err := registration.New(config.ProcessorConfig{
|
||||
Type: "string.encode",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create string.encode processor: %s", err)
|
||||
}
|
||||
|
||||
if processorInstance.Type() != "string.encode" {
|
||||
t.Fatalf("string.encode processor has wrong type: %s", processorInstance.Type())
|
||||
}
|
||||
|
||||
payload := "hello"
|
||||
expected := []byte{'h', 'e', 'l', 'l', 'o'}
|
||||
|
||||
got, err := processorInstance.Process(t.Context(), payload)
|
||||
if err != nil {
|
||||
t.Fatalf("string.encode processing failed: %s", err)
|
||||
}
|
||||
|
||||
gotBytes, ok := got.([]byte)
|
||||
|
||||
if !ok {
|
||||
t.Fatalf("string.encode should return byte slice")
|
||||
}
|
||||
|
||||
if !slices.Equal(gotBytes, expected) {
|
||||
t.Fatalf("string.encode got %+v, expected %+v", got, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGoodStringEncode(t *testing.T) {
|
||||
stringEncoder := processor.StringEncode{}
|
||||
tests := []struct {
|
||||
|
||||
Reference in New Issue
Block a user