yjp 1 год назад
Родитель
Сommit
571e7c995f
3 измененных файлов с 104 добавлено и 0 удалено
  1. 3 0
      go.mod
  2. 3 0
      go.sum
  3. 98 0
      test/v1/sdk.go

+ 3 - 0
go.mod

@@ -6,12 +6,15 @@ require (
 	github.com/golang/protobuf v1.5.3
 	github.com/mwitkow/go-proto-validators v0.3.2
 	github.com/satori/go.uuid v1.2.0
+	github.com/stretchr/testify v1.3.0
 	google.golang.org/grpc v1.60.1
 	google.golang.org/protobuf v1.32.0
 )
 
 require (
+	github.com/davecgh/go-spew v1.1.0 // indirect
 	github.com/gogo/protobuf v1.3.0 // indirect
+	github.com/pmezard/go-difflib v1.0.0 // indirect
 	golang.org/x/net v0.16.0 // indirect
 	golang.org/x/sys v0.13.0 // indirect
 	golang.org/x/text v0.13.0 // indirect

+ 3 - 0
go.sum

@@ -1,3 +1,4 @@
+github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/gogo/protobuf v1.3.0 h1:G8O7TerXerS4F6sx9OV7/nRfJdnXgHZu/S/7F2SN+UE=
 github.com/gogo/protobuf v1.3.0/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
@@ -17,10 +18,12 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
 github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
 github.com/mwitkow/go-proto-validators v0.3.2 h1:qRlmpTzm2pstMKKzTdvwPCF5QfBNURSlAgN/R+qbKos=
 github.com/mwitkow/go-proto-validators v0.3.2/go.mod h1:ej0Qp0qMgHN/KtDyUt+Q1/tA7a5VarXUOUxD+oeD30w=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
 github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
 golang.org/x/net v0.16.0 h1:7eBu7KsSvFDtSXUIDbh3aqlK4DPsZ1rByC8PFfBThos=
 golang.org/x/net v0.16.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=

+ 98 - 0
test/v1/sdk.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"git.sxidc.com/service-supports/dps-sdk"
 	"git.sxidc.com/service-supports/dps-sdk/ports"
+	"github.com/stretchr/testify/assert"
 	"testing"
 )
 
@@ -76,3 +77,100 @@ func (toolKit *ToolKit) update(req *ports.UpdateRequest) *ToolKit {
 
 	return toolKit
 }
+
+func (toolKit *ToolKit) queryByWhereAndOrderBy(req *ports.QueryByWhereAndOrderByRequest, retInfosMap *[]map[string]any) *ToolKit {
+	statement, infosMap, totalCount, err := clientInstance.QueryByWhereAndOrderBy(req)
+	if err != nil {
+		toolKit.t.Fatal(err)
+	}
+
+	toolKit.assertEqual(len(infosMap), int(totalCount), "总数不一致")
+
+	fmt.Println(statement)
+
+	if retInfosMap != nil {
+		*retInfosMap = make([]map[string]any, 0)
+		*retInfosMap = infosMap
+	}
+
+	return toolKit
+}
+
+func (toolKit *ToolKit) commonQuery(req *ports.CommonQueryRequest, retInfosMap *[]map[string]any) *ToolKit {
+	statement, infosMap, totalCount, err := clientInstance.CommonQuery(req)
+	if err != nil {
+		toolKit.t.Fatal(err)
+	}
+
+	toolKit.assertEqual(len(infosMap), int(totalCount), "总数不一致")
+
+	fmt.Println(statement)
+
+	if retInfosMap != nil {
+		*retInfosMap = make([]map[string]any, 0)
+		*retInfosMap = infosMap
+	}
+
+	return toolKit
+}
+
+func (toolKit *ToolKit) commonQueryByKeys(req *ports.CommonQueryByKeysRequest, retInfoMap *map[string]any) *ToolKit {
+	statement, infoMap, err := clientInstance.CommonQueryByKeys(req)
+	if err != nil {
+		toolKit.t.Fatal(err)
+	}
+
+	fmt.Println(statement)
+
+	if retInfoMap != nil {
+		*retInfoMap = make(map[string]any)
+		*retInfoMap = infoMap
+	}
+
+	return toolKit
+}
+
+func (toolKit *ToolKit) CountWhere(req *ports.CountWhereRequest, retCount *int64) *ToolKit {
+	statement, count, err := clientInstance.CountWhere(req)
+	if err != nil {
+		toolKit.t.Fatal(err)
+	}
+
+	fmt.Println(statement)
+
+	if retCount != nil {
+		*retCount = count
+	}
+
+	return toolKit
+}
+
+func (toolKit *ToolKit) CommonCount(req *ports.CommonCountRequest, retCount *int64) *ToolKit {
+	statement, count, err := clientInstance.CommonCount(req)
+	if err != nil {
+		toolKit.t.Fatal(err)
+	}
+
+	fmt.Println(statement)
+
+	if retCount != nil {
+		*retCount = count
+	}
+
+	return toolKit
+}
+
+func (toolKit *ToolKit) assertEqual(expected interface{}, actual interface{}, msgAndArgs ...interface{}) *ToolKit {
+	assert.Equal(toolKit.t, expected, actual, msgAndArgs)
+	return toolKit
+}
+
+func (toolKit *ToolKit) assertNotEqual(expected interface{}, actual interface{}, msgAndArgs ...interface{}) *ToolKit {
+	assert.NotEqual(toolKit.t, expected, actual, msgAndArgs)
+	return toolKit
+}
+
+func (toolKit *ToolKit) assertNotEmpty(object interface{}, msgAndArgs ...interface{}) *ToolKit {
+	assert.NotEmpty(toolKit.t, object, msgAndArgs)
+	return toolKit
+}