diff --git a/struct_utils/map_params_test.go b/struct_utils/map_params_test.go index a0d539e562cd65f831473c0231cdec542a7729a5..7fd5aeea9aa7a9f2bfa6eeb46b39d714560f32fe 100644 --- a/struct_utils/map_params_test.go +++ b/struct_utils/map_params_test.go @@ -1,6 +1,7 @@ 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) }