Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bobgroup-go-utils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bob Public Utils
bobgroup-go-utils
Commits
dd2a1e7f
Commit
dd2a1e7f
authored
3 years ago
by
Jan Semmelink
Browse files
Options
Downloads
Patches
Plain Diff
Add another test case
parent
8f8cf91d
Branches
18-use-scan-for-param-values
No related tags found
1 merge request
!12
One more change to detect when custom types (like time.Time) has their own parsers, then do not step into those structs.
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
struct_utils/map_params_test.go
+28
-5
28 additions, 5 deletions
struct_utils/map_params_test.go
with
28 additions
and
5 deletions
struct_utils/map_params_test.go
+
28
−
5
View file @
dd2a1e7f
package
struct_utils_test
import
(
"fmt"
"testing"
"gitlab.com/uafrica/go-utils/struct_utils"
...
...
@@ -61,11 +62,6 @@ func TestAnonymous(t *testing.T) {
}
func
TestMapParams
(
t
*
testing
.
T
)
{
type
paramsStruct
struct
{
ID
int64
`json:"id,omitempty"`
IDs
[]
int64
`json:"ids,omitempty"`
}
ps
:=
paramsStruct
{
ID
:
123
}
pm
:=
struct_utils
.
MapParams
(
ps
)
if
len
(
pm
)
!=
1
||
pm
[
"id"
]
!=
"123"
{
...
...
@@ -79,4 +75,31 @@ func TestMapParams(t *testing.T) {
t
.
Fatalf
(
"wrong params: %+v != %+v"
,
ps
,
pm
)
}
t
.
Logf
(
"ps=%+v -> pm=%+v"
,
ps
,
pm
)
ps
=
paramsStruct
{
X1
:
xtype
{
1
},
X3
:
&
xtype
{
3
}}
pm
=
struct_utils
.
MapParams
(
ps
)
if
len
(
pm
)
!=
2
||
pm
[
"x1"
]
!=
">>1<<"
||
pm
[
"x3"
]
!=
">>3<<"
{
t
.
Fatalf
(
"wrong params: %+v != %+v"
,
ps
,
pm
)
}
t
.
Logf
(
"ps=%+v -> pm=%+v"
,
ps
,
pm
)
}
type
paramsStruct
struct
{
ID
int64
`json:"id,omitempty"`
IDs
[]
int64
`json:"ids,omitempty"`
X1
xtype
`json:"x1,omitempty"`
X2
xtype
`json:"x2,omitempty"`
X3
*
xtype
`json:"x3,omitempty"`
X4
*
xtype
`json:"x4,omitempty"`
}
type
xtype
struct
{
xvalue
int
}
func
(
x
xtype
)
String
()
string
{
if
x
.
xvalue
==
0
{
return
""
}
return
fmt
.
Sprintf
(
">>%d<<"
,
x
.
xvalue
)
}
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