Skip to content
Snippets Groups Projects
Commit dd2a1e7f authored by Jan Semmelink's avatar Jan Semmelink
Browse files

Add another test case

parent 8f8cf91d
No related branches found
No related tags found
1 merge request!12One more change to detect when custom types (like time.Time) has their own parsers, then do not step into those structs.
This commit is part of merge request !12. Comments created here will be created in the context of that merge request.
package struct_utils_test package struct_utils_test
import ( import (
"fmt"
"testing" "testing"
"gitlab.com/uafrica/go-utils/struct_utils" "gitlab.com/uafrica/go-utils/struct_utils"
...@@ -61,11 +62,6 @@ func TestAnonymous(t *testing.T) { ...@@ -61,11 +62,6 @@ func TestAnonymous(t *testing.T) {
} }
func TestMapParams(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} ps := paramsStruct{ID: 123}
pm := struct_utils.MapParams(ps) pm := struct_utils.MapParams(ps)
if len(pm) != 1 || pm["id"] != "123" { if len(pm) != 1 || pm["id"] != "123" {
...@@ -79,4 +75,31 @@ func TestMapParams(t *testing.T) { ...@@ -79,4 +75,31 @@ func TestMapParams(t *testing.T) {
t.Fatalf("wrong params: %+v != %+v", ps, pm) t.Fatalf("wrong params: %+v != %+v", ps, pm)
} }
t.Logf("ps=%+v -> pm=%+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)
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment