This is an automated email from the ASF dual-hosted git repository.
tianxiaoliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-service-center.git
The following commit(s) were added to refs/heads/master by this push:
new 2a0931c add ut of transform, fix bug in transform (#876)
2a0931c is described below
commit 2a0931cf2f9fcfa526a502f126e2e302b6022d30
Author: yeyiwei <[email protected]>
AuthorDate: Mon Mar 1 09:09:03 2021 +0800
add ut of transform, fix bug in transform (#876)
---
syncer/plugins/servicecenter/transform.go | 2 +-
syncer/plugins/servicecenter/transform_test.go | 108 +++++++++++++++++++++++++
2 files changed, 109 insertions(+), 1 deletion(-)
diff --git a/syncer/plugins/servicecenter/transform.go
b/syncer/plugins/servicecenter/transform.go
index 67d88c8..3680970 100644
--- a/syncer/plugins/servicecenter/transform.go
+++ b/syncer/plugins/servicecenter/transform.go
@@ -473,7 +473,7 @@ func InstanceCopyRe(instance *pbsc.MicroServiceInstance)
*scpb.MicroServiceInsta
ModTimestamp: instance.ModTimestamp,
Version: instance.Version,
}
- if instance.DataCenterInfo.Name != "" {
+ if instance.DataCenterInfo != nil &&
instance.DataCenterInfo.Name != "" {
instanceInpbs.DataCenterInfo = &dataCenterInfo
}
}
diff --git a/syncer/plugins/servicecenter/transform_test.go
b/syncer/plugins/servicecenter/transform_test.go
new file mode 100644
index 0000000..5d45e04
--- /dev/null
+++ b/syncer/plugins/servicecenter/transform_test.go
@@ -0,0 +1,108 @@
+package servicecenter
+
+import (
+ pbsc "github.com/apache/servicecomb-service-center/syncer/proto/sc"
+ scpb "github.com/go-chassis/cari/discovery"
+ "github.com/stretchr/testify/assert"
+
+ "testing"
+)
+
+func TestTransform_ServiceCopy(t *testing.T) {
+ t.Run("value will copy from scpb.MicroService to pbsc.MicroService",
func(t *testing.T) {
+ service := scpb.MicroService{
+ ServiceId: "1234567",
+ }
+ serviceInpbsc := ServiceCopy(&service)
+ assert.NotNil(t, serviceInpbsc.ServiceId, "serviceId is not
nil")
+ assert.Equal(t, "1234567", serviceInpbsc.ServiceId)
+ })
+ t.Run("more values will copy from scpb.MicroService to
pbsc.MicroService", func(t *testing.T) {
+ service := scpb.MicroService{
+ ServiceId: "1234567",
+ AppId: "appid",
+ ServiceName: "service",
+ }
+ serviceInpbsc := ServiceCopy(&service)
+ assert.NotNil(t, serviceInpbsc.ServiceId, "serviceId is not
nil")
+ assert.Equal(t, "1234567", serviceInpbsc.ServiceId)
+ assert.Equal(t, "appid", serviceInpbsc.AppId)
+ assert.Equal(t, "service", serviceInpbsc.ServiceName)
+ })
+}
+
+func TestTransform_ServiceCopyRe(t *testing.T) {
+ t.Run("value will copy from pbsc.MicroService to scpb.MicroService",
func(t *testing.T) {
+ service := pbsc.MicroService{
+ ServiceId: "1234567",
+ }
+ serviceInpbsc := ServiceCopyRe(&service)
+ assert.NotNil(t, serviceInpbsc.ServiceId, "serviceId is not
nil")
+ assert.Equal(t, "1234567", serviceInpbsc.ServiceId)
+ })
+ t.Run("more values will copy from pbsc.MicroService to
scpb.MicroService", func(t *testing.T) {
+ service := pbsc.MicroService{
+ ServiceId: "1234567",
+ AppId: "appid",
+ ServiceName: "service",
+ }
+ serviceInpbsc := ServiceCopyRe(&service)
+ assert.NotNil(t, serviceInpbsc.ServiceId, "serviceId is not
nil")
+ assert.Equal(t, "1234567", serviceInpbsc.ServiceId)
+ assert.Equal(t, "appid", serviceInpbsc.AppId)
+ assert.Equal(t, "service", serviceInpbsc.ServiceName)
+ })
+}
+
+func TestTransform_InstanceCopy(t *testing.T) {
+ t.Run("value will copy from scpb.MicroServiceInstance to
pbsc.MicroServiceInstance", func(t *testing.T) {
+ instance := scpb.MicroServiceInstance{
+ ServiceId: "1234567",
+ }
+ instanceInpbsc := InstanceCopy(&instance)
+ assert.NotNil(t, instanceInpbsc.ServiceId, "serviceId is not
nil")
+ assert.Equal(t, "1234567", instanceInpbsc.ServiceId)
+ })
+ t.Run("more values will copy from scpb.MicroServiceInstance to
pbsc.MicroServiceInstance", func(t *testing.T) {
+ instance := scpb.MicroServiceInstance{
+ ServiceId: "1234567",
+ InstanceId: "7654321",
+ }
+ instanceInpbsc := InstanceCopy(&instance)
+ assert.NotNil(t, instanceInpbsc.ServiceId, "serviceId is not
nil")
+ assert.Equal(t, "1234567", instanceInpbsc.ServiceId)
+ assert.Equal(t, "7654321", instanceInpbsc.InstanceId)
+ })
+}
+
+func TestTransform_InstanceCopyRe(t *testing.T) {
+ t.Run("value will copy from pbsc.MicroServiceInstance to
scpb.MicroServiceInstance", func(t *testing.T) {
+ instance := pbsc.MicroServiceInstance{
+ ServiceId: "1234567",
+ }
+ instanceInpbsc := InstanceCopyRe(&instance)
+ assert.NotNil(t, instanceInpbsc.ServiceId, "serviceId is not
nil")
+ assert.Equal(t, "1234567", instanceInpbsc.ServiceId)
+ })
+ t.Run("value will copy from pbsc.MicroServiceInstance to
scpb.MicroServiceInstance", func(t *testing.T) {
+ instance := pbsc.MicroServiceInstance{
+ ServiceId: "1234567",
+ InstanceId: "7654321",
+ }
+ instanceInpbsc := InstanceCopyRe(&instance)
+ assert.NotNil(t, instanceInpbsc.ServiceId, "serviceId is not
nil")
+ assert.Equal(t, "1234567", instanceInpbsc.ServiceId)
+ assert.Equal(t, "7654321", instanceInpbsc.InstanceId)
+ })
+}
+
+func TestTransform_SchemaCopy(t *testing.T) {
+ t.Run("value will copy from scpb.Schema to pbsc.Schema", func(t
*testing.T) {
+ schema := scpb.Schema{
+ SchemaId: "1234567",
+ }
+ instanceInpbsc := SchemaCopy(&schema)
+ assert.NotNil(t, instanceInpbsc.SchemaId, "schemaId is not nil")
+ assert.Equal(t, "1234567", instanceInpbsc.SchemaId)
+ })
+}