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 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.
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)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment