Skip to content

Commit 46c79de

Browse files
authored
[fix] when domain or project is empty should return default (#59)
1 parent cbf87fb commit 46c79de

File tree

5 files changed

+72
-0
lines changed

5 files changed

+72
-0
lines changed

Diff for: sync/task.go

+6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ func NewTask(domain, project, action, resourceType string, resource interface{})
3535
if err != nil {
3636
return nil, err
3737
}
38+
if len(domain) == 0 {
39+
domain = Default
40+
}
41+
if len(project) == 0 {
42+
project = Default
43+
}
3844

3945
var resourceValue []byte
4046
switch rv := resource.(type) {

Diff for: sync/task_test.go

+26
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
118
package sync
219

320
import (
@@ -15,6 +32,15 @@ func TestNewTask(t *testing.T) {
1532
}
1633
})
1734

35+
t.Run("resource is string, domain and project is empty, domain and project should return default", func(t *testing.T) {
36+
task, err := NewTask("", "", "", "", "hello")
37+
if assert.Nil(t, err) {
38+
assert.Equal(t, []byte("hello"), task.Resource)
39+
assert.Equal(t, Default, task.Domain)
40+
assert.Equal(t, Default, task.Project)
41+
}
42+
})
43+
1844
t.Run("resource is []byte", func(t *testing.T) {
1945
task, err := NewTask("", "", "", "", []byte("hello"))
2046
if assert.Nil(t, err) {

Diff for: sync/tombstone.go

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ import "time"
2121

2222
// NewTombstone return tombstone with resourceID,resourceType ,domain and project
2323
func NewTombstone(domain, project, resourceType, resourceID string) *Tombstone {
24+
if len(domain) == 0 {
25+
domain = Default
26+
}
27+
if len(project) == 0 {
28+
project = Default
29+
}
2430
return &Tombstone{
2531
ResourceID: resourceID,
2632
ResourceType: resourceType,

Diff for: sync/tombstone_test.go

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package sync
19+
20+
import (
21+
"testing"
22+
23+
"github.com/stretchr/testify/assert"
24+
)
25+
26+
func TestNewTombstone(t *testing.T) {
27+
t.Run("create a tombstone, the domain and project is empty should return default", func(t *testing.T) {
28+
tombstone := NewTombstone("", "", "kv", "11111")
29+
assert.Equal(t, Default, tombstone.Domain)
30+
assert.Equal(t, Default, tombstone.Project)
31+
})
32+
}

Diff for: sync/types.go

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const (
2121
CreateAction = "create"
2222
UpdateAction = "update"
2323
DeleteAction = "delete"
24+
25+
Default = "default"
2426
)
2527

2628
// Task is db struct to store sync task

0 commit comments

Comments
 (0)