mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-27 05:15:47 +00:00
Merge pull request #10 from jwetzell/chore/processor-tests
add some basic processor tests
This commit is contained in:
50
internal/processor/float-parse_test.go
Normal file
50
internal/processor/float-parse_test.go
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
package processor_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGoodFloatParse(t *testing.T) {
|
||||||
|
floatParser := processor.FloatParse{}
|
||||||
|
tests := []struct {
|
||||||
|
processor processor.Processor
|
||||||
|
name string
|
||||||
|
payload any
|
||||||
|
expected float64
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "positive number",
|
||||||
|
payload: "12345.67",
|
||||||
|
expected: 12345.67,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "negative number",
|
||||||
|
payload: "-12345.67",
|
||||||
|
expected: -12345.67,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "zero",
|
||||||
|
payload: "0",
|
||||||
|
expected: 0,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
got, err := floatParser.Process(t.Context(), test.payload)
|
||||||
|
|
||||||
|
gotFloat, ok := got.(float64)
|
||||||
|
if !ok {
|
||||||
|
t.Errorf("float.parse returned a %T payload: %s", got, got)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("float.parse failed: %s", err)
|
||||||
|
}
|
||||||
|
if gotFloat != test.expected {
|
||||||
|
t.Errorf("float.parse got %f, expected %f", gotFloat, test.expected)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
50
internal/processor/int-parse_test.go
Normal file
50
internal/processor/int-parse_test.go
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
package processor_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGoodIntParse(t *testing.T) {
|
||||||
|
intParser := processor.IntParse{}
|
||||||
|
tests := []struct {
|
||||||
|
processor processor.Processor
|
||||||
|
name string
|
||||||
|
payload any
|
||||||
|
expected int64
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "positive number",
|
||||||
|
payload: "12345",
|
||||||
|
expected: 12345,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "negative number",
|
||||||
|
payload: "-12345",
|
||||||
|
expected: -12345,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "zero",
|
||||||
|
payload: "0",
|
||||||
|
expected: 0,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
got, err := intParser.Process(t.Context(), test.payload)
|
||||||
|
|
||||||
|
gotInt, ok := got.(int64)
|
||||||
|
if !ok {
|
||||||
|
t.Errorf("int.parse returned a %T payload: %s", got, got)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("int.parse failed: %s", err)
|
||||||
|
}
|
||||||
|
if gotInt != test.expected {
|
||||||
|
t.Errorf("int.parse got %d, expected %d", gotInt, test.expected)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
45
internal/processor/uint-parse_test.go
Normal file
45
internal/processor/uint-parse_test.go
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package processor_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jwetzell/showbridge-go/internal/processor"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGoodUintParse(t *testing.T) {
|
||||||
|
uintParser := processor.UintParse{}
|
||||||
|
tests := []struct {
|
||||||
|
processor processor.Processor
|
||||||
|
name string
|
||||||
|
payload any
|
||||||
|
expected uint64
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "positive number",
|
||||||
|
payload: "12345",
|
||||||
|
expected: 12345,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "zero",
|
||||||
|
payload: "0",
|
||||||
|
expected: 0,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
got, err := uintParser.Process(t.Context(), test.payload)
|
||||||
|
|
||||||
|
gotUint, ok := got.(uint64)
|
||||||
|
if !ok {
|
||||||
|
t.Errorf("uint.parse returned a %T payload: %s", got, got)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("uint.parse failed: %s", err)
|
||||||
|
}
|
||||||
|
if gotUint != test.expected {
|
||||||
|
t.Errorf("uint.parse got %d, expected %d", gotUint, test.expected)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user