|
@@ -21,6 +21,8 @@ import (
|
|
|
"reflect"
|
|
|
"testing"
|
|
|
|
|
|
+ "github.com/stretchr/testify/assert"
|
|
|
+
|
|
|
"github.com/lf-edge/ekuiper/internal/conf"
|
|
|
"github.com/lf-edge/ekuiper/internal/schema"
|
|
|
"github.com/lf-edge/ekuiper/internal/testx"
|
|
@@ -42,7 +44,7 @@ func TestEncode(t *testing.T) {
|
|
|
"id": 1,
|
|
|
"age": 1,
|
|
|
},
|
|
|
- r: []byte{0x0a, 0x04, 0x74, 0x65, 0x73, 0x74, 0x10, 0x01, 0x1a, 0x00},
|
|
|
+ r: []byte{0x0a, 0x04, 0x74, 0x65, 0x73, 0x74, 0x10, 0x01},
|
|
|
}, {
|
|
|
m: map[string]interface{}{
|
|
|
"name": "test",
|
|
@@ -50,6 +52,16 @@ func TestEncode(t *testing.T) {
|
|
|
"email": "Dddd",
|
|
|
},
|
|
|
r: []byte{0x0a, 0x04, 0x74, 0x65, 0x73, 0x74, 0x10, 0x01, 0x1a, 0x04, 0x44, 0x64, 0x64, 0x64},
|
|
|
+ }, {
|
|
|
+ m: map[string]interface{}{
|
|
|
+ "name": "test",
|
|
|
+ "id": 1,
|
|
|
+ "code": []any{
|
|
|
+ map[string]any{"doubles": []any{1.1, 2.2, 3.3}},
|
|
|
+ map[string]any{"doubles": []any{3.3, 1.1}},
|
|
|
+ },
|
|
|
+ },
|
|
|
+ r: []byte{0x0a, 0x04, 0x74, 0x65, 0x73, 0x74, 0x10, 0x01, 0x22, 0x1b, 0x09, 0x9a, 0x99, 0x99, 0x99, 0x99, 0x99, 0xf1, 0x3f, 0x09, 0x9a, 0x99, 0x99, 0x99, 0x99, 0x99, 0x01, 0x40, 0x09, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x0a, 0x40, 0x22, 0x12, 0x09, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x0a, 0x40, 0x09, 0x9a, 0x99, 0x99, 0x99, 0x99, 0x99, 0xf1, 0x3f},
|
|
|
},
|
|
|
}
|
|
|
fmt.Printf("The test bucket size is %d.\n\n", len(tests))
|
|
@@ -109,7 +121,6 @@ func TestDecode(t *testing.T) {
|
|
|
tests := []struct {
|
|
|
m map[string]interface{}
|
|
|
r []byte
|
|
|
- e string
|
|
|
}{
|
|
|
{
|
|
|
m: map[string]interface{}{
|
|
@@ -120,15 +131,26 @@ func TestDecode(t *testing.T) {
|
|
|
},
|
|
|
r: []byte{0x0a, 0x04, 0x74, 0x65, 0x73, 0x74, 0x10, 0x01, 0x1a, 0x04, 0x44, 0x64, 0x64, 0x64},
|
|
|
},
|
|
|
+ {
|
|
|
+ m: map[string]interface{}{
|
|
|
+ "name": "test",
|
|
|
+ "id": int64(1),
|
|
|
+ "email": "",
|
|
|
+ "code": []map[string]any{
|
|
|
+ {"doubles": []float64{1.1, 2.2, 3.3}},
|
|
|
+ {"doubles": []float64{3.3, 1.1}},
|
|
|
+ },
|
|
|
+ },
|
|
|
+ r: []byte{0x0a, 0x04, 0x74, 0x65, 0x73, 0x74, 0x10, 0x01, 0x22, 0x1b, 0x09, 0x9a, 0x99, 0x99, 0x99, 0x99, 0x99, 0xf1, 0x3f, 0x09, 0x9a, 0x99, 0x99, 0x99, 0x99, 0x99, 0x01, 0x40, 0x09, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x0a, 0x40, 0x22, 0x12, 0x09, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x0a, 0x40, 0x09, 0x9a, 0x99, 0x99, 0x99, 0x99, 0x99, 0xf1, 0x3f},
|
|
|
+ },
|
|
|
}
|
|
|
- fmt.Printf("The test bucket size is %d.\n\n", len(tests))
|
|
|
+
|
|
|
for i, tt := range tests {
|
|
|
- a, err := c.Decode(tt.r)
|
|
|
- if !reflect.DeepEqual(tt.e, testx.Errstring(err)) {
|
|
|
- t.Errorf("%d.error mismatch:\n exp=%s\n got=%s\n\n", i, tt.e, err)
|
|
|
- } else if tt.e == "" && !reflect.DeepEqual(tt.m, a) {
|
|
|
- t.Errorf("%d. \n\nresult mismatch:\n\nexp=%v\n\ngot=%v\n\n", i, tt.m, a)
|
|
|
- }
|
|
|
+ t.Run(fmt.Sprintf("test %d", i), func(t *testing.T) {
|
|
|
+ a, err := c.Decode(tt.r)
|
|
|
+ assert.NoError(t, err)
|
|
|
+ assert.Equal(t, tt.m, a)
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
|