little-cui commented on a change in pull request #228:
URL: https://github.com/apache/servicecomb-kie/pull/228#discussion_r757724988
##########
File path: server/datasource/dao.go
##########
@@ -70,13 +74,14 @@ func GetBroker() Broker {
//KVDao provide api of KV entity
type KVDao interface {
// Create Update List are usually for admin console
- Create(ctx context.Context, kv *model.KVDoc) (*model.KVDoc, error)
- Update(ctx context.Context, kv *model.KVDoc) error
+ Create(ctx context.Context, kv *model.KVDoc, options ...WriteOption)
(*model.KVDoc, error)
Review comment:
请补充UT:
1、使用WriteOption = true
2、通过etcdadpt验证数据
##########
File path: server/service/kv/kv_svc_test.go
##########
@@ -178,3 +180,93 @@ func TestService_Delete(t *testing.T) {
assert.NoError(t, err)
})
}
+
+// Test the situation after the synchronization is turned on
+func TestSync(t *testing.T) {
+
+ t.Run("Transactional write configuration and generate synchronization
tasks", func(t *testing.T) {
Review comment:
这些用例没有准确的断言,没有意义
##########
File path: server/service/kv/kv_svc_test.go
##########
@@ -178,3 +180,93 @@ func TestService_Delete(t *testing.T) {
assert.NoError(t, err)
})
}
+
+// Test the situation after the synchronization is turned on
+func TestSync(t *testing.T) {
+
+ t.Run("Transactional write configuration and generate synchronization
tasks", func(t *testing.T) {
+ // turn on the synchronization switch
+ kcfg.Configurations.Sync.Enabled = true
+ var syncKVIDOne, syncKVIDTwo, syncKVIDThree string
+ // create three kvDoc
+ t.Run("create kv one,with labels app and service, should pass",
func(t *testing.T) {
+ result, err := kvsvc.Create(context.TODO(),
&model.KVDoc{
+ Key: "one",
+ Value: "1",
+ Status: common.StatusEnabled,
+ Labels: map[string]string{
+ "app": "one",
+ "service": "oneService",
+ },
+ Domain: domain,
+ Project: project,
+ })
+ assert.Nil(t, err)
+ assert.NotEmpty(t, result.ID)
+ assert.Equal(t, "1", result.Value)
+ syncKVIDOne = result.ID
+ })
+
+ t.Run("create kv two,with labels app and service, should pass",
func(t *testing.T) {
+ result, err := kvsvc.Create(context.TODO(),
&model.KVDoc{
+ Key: "two",
+ Value: "2",
+ Status: common.StatusEnabled,
+ Labels: map[string]string{
+ "app": "two",
+ "service": "twoService",
+ },
+ Domain: domain,
+ Project: project,
+ })
+ assert.Nil(t, err)
+ assert.NotEmpty(t, result.ID)
+ assert.Equal(t, "2", result.Value)
+ syncKVIDTwo = result.ID
+ })
+
+ t.Run("create kv three,with labels app and service, should
pass", func(t *testing.T) {
+ result, err := kvsvc.Create(context.TODO(),
&model.KVDoc{
+ Key: "three",
+ Value: "3",
+ Status: common.StatusEnabled,
+ Labels: map[string]string{
+ "app": "three",
+ "service": "threeService",
+ },
+ Domain: domain,
+ Project: project,
+ })
+ assert.Nil(t, err)
+ assert.NotEmpty(t, result.ID)
+ assert.Equal(t, "3", result.Value)
+ syncKVIDThree = result.ID
+ })
+
+ // update syncKVIDOne
+ t.Run("update kv by kvID, should pass", func(t *testing.T) {
+ result, err := kvsvc.Update(context.TODO(),
&model.UpdateKVRequest{
+ ID: syncKVIDOne,
+ Value: "one",
+ Domain: domain,
+ Project: project,
+ })
+ assert.NoError(t, err)
+ assert.Equal(t, "one", result.Value)
+ })
+ // delete syncKVIDOne
+ t.Run("delete kv by kvID, should pass", func(t *testing.T) {
+ _, err := kvsvc.FindOneAndDelete(context.TODO(),
syncKVIDOne, project, domain)
+ assert.NoError(t, err)
+ })
+
+ // delete syncKVIDTwo & syncKVIDThree
+ t.Run("delete kvs by array of kvID, should pass", func(t
*testing.T) {
+ _, err := kvsvc.FindManyAndDelete(context.TODO(),
[]string{syncKVIDTwo, syncKVIDThree}, project, domain)
+ assert.NoError(t, err)
+ })
+
+ // stop sync
+ kcfg.Configurations.Sync.Enabled = false
Review comment:
使用defer即可
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]