Skip to content

Commit

Permalink
Add test cases to apply consistent log outputs.
Browse files Browse the repository at this point in the history
(cherry picked from commit d9386b1)
  • Loading branch information
dchoi-viant committed Dec 7, 2023
1 parent 5dfa459 commit eac9407
Showing 1 changed file with 53 additions and 27 deletions.
80 changes: 53 additions & 27 deletions service/stream/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/viant/tapper/msg/json"
)

// batch:single output:single payload
// not-batch output:single payload
type sssp struct {
O1 string `json:"out1"`
}
Expand All @@ -24,8 +24,8 @@ type ssfp struct {
O1 float64 `json:"out1"`
}

// batch:multi, output:single or batch:single output:multi string payload
// xx = mixed
// batched, output:single or not-batched output:multi string payload
// mx == mixed
type mxsp struct {
O1 []string `json:"out1"`
}
Expand All @@ -38,7 +38,7 @@ type mxfp struct {
O1 []float64 `json:"out1"`
}

// batch:multi, output:multi string payload
// batched, output:multi string payload
type mmsp struct {
O1 []struct {
Ov []string `json:"output"`
Expand All @@ -62,12 +62,14 @@ func TestWriteObject(t *testing.T) {
os := []domain.Output{{Name: "out1"}}

testCases := []struct {
name string
out []interface{}
name string
batched bool
out []interface{}
// expected instance
ei func() interface{}
}{
{
// batch/single - single/multi output - type
name: "single-single-string",
out: []interface{}{[][]string{[]string{"a"}}},
ei: func() interface{} { return new(sssp) },
Expand All @@ -78,14 +80,22 @@ func TestWriteObject(t *testing.T) {
ei: func() interface{} { return new(mxsp) },
},
{
name: "batch-single-string",
out: []interface{}{[][]string{[]string{"a"}, []string{"b"}}},
ei: func() interface{} { return new(mxsp) },
name: "batch-single-string",
batched: true,
out: []interface{}{[][]string{[]string{"a"}, []string{"b"}}},
ei: func() interface{} { return new(mxsp) },
},
{
name: "batch-multi-string",
batched: true,
out: []interface{}{[][]string{[]string{"a", "b"}, []string{"c", "d"}}},
ei: func() interface{} { return new(mmsp) },
},
{
name: "batch-multi-string",
out: []interface{}{[][]string{[]string{"a", "b"}, []string{"c", "d"}}},
ei: func() interface{} { return new(mmsp) },
name: "batch-len1-multi-string",
batched: true,
out: []interface{}{[][]string{[]string{"a", "b"}}},
ei: func() interface{} { return new(mmsp) },
},
{
name: "single-single-int",
Expand All @@ -98,14 +108,22 @@ func TestWriteObject(t *testing.T) {
ei: func() interface{} { return new(mxip) },
},
{
name: "batch-single-int",
out: []interface{}{[][]int64{[]int64{1}, []int64{2}}},
ei: func() interface{} { return new(mxip) },
name: "batch-single-int",
batched: true,
out: []interface{}{[][]int64{[]int64{1}, []int64{2}}},
ei: func() interface{} { return new(mxip) },
},
{
name: "batch-multi-int",
out: []interface{}{[][]int64{[]int64{1, 2, 5}, []int64{3, 4, 6}}},
ei: func() interface{} { return new(mmip) },
name: "batch-multi-int",
batched: true,
out: []interface{}{[][]int64{[]int64{1, 2, 5}, []int64{3, 4, 6}}},
ei: func() interface{} { return new(mmip) },
},
{
name: "batch-len1-multi-int",
batched: true,
out: []interface{}{[][]int64{[]int64{1, 2, 5}}},
ei: func() interface{} { return new(mmip) },
},
{
name: "single-single-float",
Expand All @@ -118,26 +136,34 @@ func TestWriteObject(t *testing.T) {
ei: func() interface{} { return new(mxfp) },
},
{
name: "batch-single-float",
out: []interface{}{[][]float32{[]float32{1}, []float32{2}}},
ei: func() interface{} { return new(mxfp) },
name: "batch-single-float",
batched: true,
out: []interface{}{[][]float32{[]float32{1}, []float32{2}}},
ei: func() interface{} { return new(mxfp) },
},
{
name: "batch-multi-float",
batched: true,
out: []interface{}{[][]float32{[]float32{1, 2, 5}, []float32{3, 4, 6}}},
ei: func() interface{} { return new(mmfp) },
},
{
name: "batch-multi-float",
out: []interface{}{[][]float32{[]float32{1, 2, 5}, []float32{3, 4, 6}}},
ei: func() interface{} { return new(mmfp) },
name: "batch-len1-multi-float",
batched: true,
out: []interface{}{[][]float32{[]float32{1, 2, 5}}},
ei: func() interface{} { return new(mmfp) },
},
}

for _, tc := range testCases {
m := p.NewMessage()
err := writeObject(m, false, tc.out, os)
require.Nil(t, err)
err := writeObject(m, tc.batched, tc.out, os)
require.Nil(t, err, tc.name)
b := new(bytes.Buffer)
m.WriteTo(b)
ei := tc.ei()
err = stdjson.Unmarshal(b.Bytes(), ei)
require.Nil(t, err)
require.Nil(t, err, tc.name)
m.Free()
}
}

0 comments on commit eac9407

Please sign in to comment.