Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
perxis-go
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
perxis
perxis-go
Commits
cbe7886e
Commit
cbe7886e
authored
1 year ago
by
Anton Sattarov
Browse files
Options
Downloads
Patches
Plain Diff
Исправлена ошибка в функции keepSource пакета schema - всегда возвращался флаг `изменено`
parent
1ee79c63
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
perxis-proto
+1
-1
1 addition, 1 deletion
perxis-proto
pkg/schema/walk/fn.go
+5
-0
5 additions, 0 deletions
pkg/schema/walk/fn.go
pkg/schema/walk/walk_test.go
+113
-2
113 additions, 2 deletions
pkg/schema/walk/walk_test.go
with
119 additions
and
3 deletions
perxis-proto
@
8c2633f8
Compare
81c96784
...
8c2633f8
Subproject commit 8
1c967842f55811b459e455572703631712d7d86
Subproject commit 8
c2633f87320a29c7abd9389cedda60a64f88bfa
This diff is collapsed.
Click to expand it.
pkg/schema/walk/fn.go
+
5
−
0
View file @
cbe7886e
package
walk
import
"reflect"
func
GenericMerge
(
c
*
WalkContext
)
(
err
error
)
{
return
}
func
KeepSrc
(
c
*
WalkContext
)
(
err
error
)
{
if
reflect
.
DeepEqual
(
c
.
Src
,
c
.
Dst
)
{
return
}
c
.
Dst
=
c
.
Src
c
.
Changed
=
true
return
...
...
This diff is collapsed.
Click to expand it.
pkg/schema/walk/walk_test.go
+
113
−
2
View file @
cbe7886e
...
...
@@ -46,6 +46,54 @@ func TestWalker_DataWalk(t *testing.T) {
wantErr
bool
}{
{
"generic"
,
&
WalkConfig
{
Fields
:
map
[
string
]
FieldConfig
{},
},
map
[
string
]
interface
{}{
"a"
:
"src_a"
,
"b"
:
"src_b"
,
"obj1"
:
map
[
string
]
interface
{}{
"a"
:
"src_obj1_a"
,
"b"
:
"src_obj1_b"
,
"obj2"
:
map
[
string
]
interface
{}{
"a"
:
"dst_obj1_obj2_a"
,
},
"obj3"
:
map
[
string
]
interface
{}{
"e"
:
"dst_obj1_obj3_e"
,
},
},
"inline_str_1"
:
"src_inline_1"
,
"inline_str_2"
:
"src_inline_2"
,
"slice"
:
[]
interface
{}{
"src_s1"
,
"src_s2"
},
},
map
[
string
]
interface
{}{
"a"
:
"dst_a"
,
"field_not_extists"
:
"remove"
,
"obj1"
:
map
[
string
]
interface
{}{
"a"
:
"dst_obj1_a"
,
"obj2"
:
map
[
string
]
interface
{}{
"a"
:
"dst_obj1_obj2_a"
,
},
},
"inline_str_1"
:
"dst_inline_1"
,
"inline_str_2"
:
"dst_inline_2"
,
"slice"
:
[]
interface
{}{
"dst_s1"
,
"dst_s2"
,
"dst_s3"
},
},
map
[
string
]
interface
{}{
"a"
:
"dst_a"
,
"obj1"
:
map
[
string
]
interface
{}{
"a"
:
"dst_obj1_a"
,
"obj2"
:
map
[
string
]
interface
{}{
"a"
:
"dst_obj1_obj2_a"
,
},
},
"inline_str_1"
:
"dst_inline_1"
,
"inline_str_2"
:
"dst_inline_2"
,
"slice"
:
[]
interface
{}{
"dst_s1"
,
"dst_s2"
,
"dst_s3"
},
},
false
,
false
,
},
{
"keep src changed"
,
&
WalkConfig
{
Fields
:
map
[
string
]
FieldConfig
{
"obj1.a"
:
{
Fn
:
KeepSrc
},
...
...
@@ -96,6 +144,68 @@ func TestWalker_DataWalk(t *testing.T) {
"inline_str_2"
:
"src_inline_2"
,
"slice"
:
[]
interface
{}{
"dst_s1"
,
"src_s2"
,
"dst_s3"
},
},
true
,
false
,
},
{
"keep src not changed"
,
&
WalkConfig
{
Fields
:
map
[
string
]
FieldConfig
{
"obj1.a"
:
{
Fn
:
KeepSrc
},
"slice.1"
:
{
Fn
:
KeepSrc
},
"inline_str_1"
:
{
Fn
:
KeepSrc
},
"inline_str_2"
:
{
Fn
:
KeepSrc
},
},
},
map
[
string
]
interface
{}{
"a"
:
"src_a"
,
"b"
:
"src_b"
,
"obj1"
:
map
[
string
]
interface
{}{
"a"
:
"src_obj1_a"
,
"b"
:
"src_obj1_b"
,
"obj2"
:
map
[
string
]
interface
{}{
"a"
:
"dst_obj1_obj2_a"
,
},
"obj3"
:
map
[
string
]
interface
{}{
"e"
:
"dst_obj1_obj3_e"
,
},
},
"inline_str_1"
:
"src_inline_1"
,
"inline_str_2"
:
"src_inline_2"
,
"slice"
:
[]
interface
{}{
"src_s1"
,
"src_s2"
},
},
map
[
string
]
interface
{}{
"a"
:
"src_a"
,
"b"
:
"src_b"
,
"obj1"
:
map
[
string
]
interface
{}{
"a"
:
"src_obj1_a"
,
"b"
:
"src_obj1_b"
,
"obj2"
:
map
[
string
]
interface
{}{
"a"
:
"dst_obj1_obj2_a"
,
},
"obj3"
:
map
[
string
]
interface
{}{
"e"
:
"dst_obj1_obj3_e"
,
},
},
"inline_str_1"
:
"src_inline_1"
,
"inline_str_2"
:
"src_inline_2"
,
"slice"
:
[]
interface
{}{
"src_s1"
,
"src_s2"
},
},
map
[
string
]
interface
{}{
"a"
:
"src_a"
,
"b"
:
"src_b"
,
"obj1"
:
map
[
string
]
interface
{}{
"a"
:
"src_obj1_a"
,
"b"
:
"src_obj1_b"
,
"obj2"
:
map
[
string
]
interface
{}{
"a"
:
"dst_obj1_obj2_a"
,
},
"obj3"
:
map
[
string
]
interface
{}{
"e"
:
"dst_obj1_obj3_e"
,
},
},
"inline_str_1"
:
"src_inline_1"
,
"inline_str_2"
:
"src_inline_2"
,
"slice"
:
[]
interface
{}{
"src_s1"
,
"src_s2"
},
},
false
,
false
,
},
}
...
...
@@ -103,11 +213,12 @@ func TestWalker_DataWalk(t *testing.T) {
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
m
:=
NewWalker
(
s
,
tt
.
config
)
dst
:=
tt
.
dst
res
,
_
,
err
:=
m
.
DataWalk
(
context
.
Background
(),
dst
,
tt
.
src
)
assert
.
Equal
(
t
,
tt
.
res
,
res
)
res
,
chg
,
err
:=
m
.
DataWalk
(
context
.
Background
(),
dst
,
tt
.
src
)
if
tt
.
wantErr
{
require
.
Error
(
t
,
err
)
}
else
{
assert
.
Equal
(
t
,
tt
.
res
,
res
)
assert
.
Equal
(
t
,
tt
.
wantChanged
,
chg
)
require
.
NoError
(
t
,
err
)
}
})
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment