mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-26 21:05:30 +00:00
add test for slice to struct get processors
This commit is contained in:
@@ -10,11 +10,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type TestStruct struct {
|
type TestStruct struct {
|
||||||
String string
|
String string
|
||||||
Int int
|
Int int
|
||||||
Float float64
|
Float float64
|
||||||
Bool bool
|
Bool bool
|
||||||
Data any
|
Data any
|
||||||
|
IntSlice []int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t TestStruct) GetString() string {
|
func (t TestStruct) GetString() string {
|
||||||
@@ -37,6 +38,10 @@ func (t TestStruct) GetData() any {
|
|||||||
return t.Data
|
return t.Data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t TestStruct) GetIntSlice() []int {
|
||||||
|
return t.IntSlice
|
||||||
|
}
|
||||||
|
|
||||||
func (t TestStruct) Void() {}
|
func (t TestStruct) Void() {}
|
||||||
|
|
||||||
type TestProcessor struct {
|
type TestProcessor struct {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package processor_test
|
package processor_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/jwetzell/showbridge-go/internal/common"
|
"github.com/jwetzell/showbridge-go/internal/common"
|
||||||
@@ -79,6 +80,14 @@ func TestGoodStructFieldGet(t *testing.T) {
|
|||||||
payload: &TestStruct{Data: "hello"},
|
payload: &TestStruct{Data: "hello"},
|
||||||
expected: "hello",
|
expected: "hello",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "int slice",
|
||||||
|
params: map[string]any{
|
||||||
|
"name": "IntSlice",
|
||||||
|
},
|
||||||
|
payload: TestStruct{IntSlice: []int{1, 2, 3}},
|
||||||
|
expected: []int{1, 2, 3},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
@@ -103,7 +112,7 @@ func TestGoodStructFieldGet(t *testing.T) {
|
|||||||
t.Fatalf("struct.field.get processing failed: %s", err)
|
t.Fatalf("struct.field.get processing failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if got.Payload != test.expected {
|
if !reflect.DeepEqual(got.Payload, test.expected) {
|
||||||
t.Fatalf("struct.field.get got %+v, expected %s", got, test.expected)
|
t.Fatalf("struct.field.get got %+v, expected %s", got, test.expected)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -98,6 +98,14 @@ func TestGoodStructMethodGet(t *testing.T) {
|
|||||||
payload: &TestStruct{Data: "hello"},
|
payload: &TestStruct{Data: "hello"},
|
||||||
expected: "hello",
|
expected: "hello",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "int slice",
|
||||||
|
params: map[string]any{
|
||||||
|
"name": "GetIntSlice",
|
||||||
|
},
|
||||||
|
payload: TestStruct{IntSlice: []int{1, 2, 3}},
|
||||||
|
expected: []int{1, 2, 3},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
|||||||
Reference in New Issue
Block a user