瀏覽代碼

chore: use `t.Logf` in unit tests

Logf formats its arguments according to the format, analogous to Printf, and records the text in the error log. A final newline is added if not provided.

Signed-off-by: xjasonlyu <xjasonlyu@gmail.com>
xjasonlyu 1 年之前
父節點
當前提交
d62ec8cfce
共有 3 個文件被更改,包括 5 次插入7 次删除
  1. 3 4
      pkg/ast/sourceStmt_test.go
  2. 1 1
      pkg/cast/cast_test.go
  3. 1 2
      sdk/go/example/mirror/random_source_test.go

+ 3 - 4
pkg/ast/sourceStmt_test.go

@@ -15,7 +15,6 @@
 package ast
 package ast
 
 
 import (
 import (
-	"fmt"
 	"reflect"
 	"reflect"
 	"testing"
 	"testing"
 )
 )
@@ -55,9 +54,9 @@ func TestPrintFieldType(t *testing.T) {
 		},
 		},
 		printed: `string`,
 		printed: `string`,
 	}}
 	}}
-	fmt.Printf("The test bucket size is %d.\n\n", len(tests))
+	t.Logf("The test bucket size is %d.", len(tests))
 	for i, tt := range tests {
 	for i, tt := range tests {
-		//fmt.Printf("Parsing SQL %q.\n",tt.s)
+		// t.Logf("Parsing SQL %q.",tt.s)
 		result, _ := doPrintFieldTypeForJson(tt.ft)
 		result, _ := doPrintFieldTypeForJson(tt.ft)
 		if !reflect.DeepEqual(tt.printed, result) {
 		if !reflect.DeepEqual(tt.printed, result) {
 			t.Errorf("%d. \nstmt mismatch:\n\nexp=%#v\n\ngot=%#v\n\n", i, tt.printed, result)
 			t.Errorf("%d. \nstmt mismatch:\n\nexp=%#v\n\ngot=%#v\n\n", i, tt.printed, result)
@@ -128,7 +127,7 @@ func TestToJsonFields(t *testing.T) {
 			},
 			},
 		},
 		},
 	}
 	}
-	fmt.Printf("The test bucket size is %d.\n\n", len(tests))
+	t.Logf("The test bucket size is %d.", len(tests))
 	for i, tt := range tests {
 	for i, tt := range tests {
 		result := tt.input.ToJsonSchema()
 		result := tt.input.ToJsonSchema()
 		if !reflect.DeepEqual(tt.output, result) {
 		if !reflect.DeepEqual(tt.output, result) {

+ 1 - 1
pkg/cast/cast_test.go

@@ -67,7 +67,7 @@ func TestToTypedSlice(t *testing.T) {
 			e: "cannot convert []interface {}([<nil> bbb ddd]) to string slice for the 0 element: <nil>",
 			e: "cannot convert []interface {}([<nil> bbb ddd]) to string slice for the 0 element: <nil>",
 		},
 		},
 	}
 	}
-	fmt.Printf("The test bucket size is %d.\n\n", len(tests))
+	t.Logf("The test bucket size is %d.", len(tests))
 	for i, tt := range tests {
 	for i, tt := range tests {
 		result, err := ToTypedSlice(tt.s, func(input interface{}, ssn Strictness) (interface{}, error) {
 		result, err := ToTypedSlice(tt.s, func(input interface{}, ssn Strictness) (interface{}, error) {
 			if input == nil {
 			if input == nil {

+ 1 - 2
sdk/go/example/mirror/random_source_test.go

@@ -15,7 +15,6 @@
 package main
 package main
 
 
 import (
 import (
-	"fmt"
 	"github.com/lf-edge/ekuiper/sdk/go/api"
 	"github.com/lf-edge/ekuiper/sdk/go/api"
 	"github.com/lf-edge/ekuiper/sdk/go/mock"
 	"github.com/lf-edge/ekuiper/sdk/go/mock"
 	"reflect"
 	"reflect"
@@ -60,7 +59,7 @@ func TestConfigure(t *testing.T) {
 			err: "source `random` property `pattern` is required",
 			err: "source `random` property `pattern` is required",
 		},
 		},
 	}
 	}
-	fmt.Printf("The test bucket size is %d.\n\n", len(tests))
+	t.Logf("The test bucket size is %d.", len(tests))
 	for i, tt := range tests {
 	for i, tt := range tests {
 		r := &randomSource{}
 		r := &randomSource{}
 		err := r.Configure("new", tt.p)
 		err := r.Configure("new", tt.p)