func TestFillStructRecursiveNoConfigAllDefaultSomeValmap(t *testing.T) {
	config := &Configuration{}

	// init parsers
	parsers := map[reflect.Type]parse.Parser{
		reflect.TypeOf([]ServerInfo{}): &sliceServerValue{},
	}
	var boolParser parse.BoolValue
	parsers[reflect.TypeOf(true)] = &boolParser
	var intParser parse.IntValue
	parsers[reflect.TypeOf(1)] = &intParser
	var int64Parser parse.Int64Value
	parsers[reflect.TypeOf(int64(1))] = &int64Parser
	var uintParser parse.UintValue
	parsers[reflect.TypeOf(uint(1))] = &uintParser
	var uint64Parser parse.Uint64Value
	parsers[reflect.TypeOf(uint64(1))] = &uint64Parser
	var stringParser parse.StringValue
	parsers[reflect.TypeOf("")] = &stringParser
	var float64Parser parse.Float64Value
	parsers[reflect.TypeOf(float64(1.5))] = &float64Parser
	var durationParser parse.Duration
	parsers[reflect.TypeOf(parse.Duration(time.Second))] = &durationParser
	var timeParser parse.TimeValue
	parsers[reflect.TypeOf(time.Now())] = &timeParser

	// init valMap
	valMap := map[string]parse.Parser{}
	durationParser.SetValue(5 * parse.Duration(time.Second))
	valMap["timeout"] = &durationParser
	boolParser.SetValue(true)
	valMap["db"] = &boolParser
	timeParser.Set("2016-04-20T17:39:00Z")
	valMap["owner.dob"] = &timeParser
	float64Parser.SetValue(0.222)
	valMap["owner.rate"] = &float64Parser

	// init defaultValMap NoConfigAllDefault
	defaultStr := "DefaultOwnerNamePointer"
	defaultDob, _ := time.Parse(time.RFC3339, "1979-05-27T07:32:00Z")
	defaultValMap := map[string]reflect.Value{
		"loglevel":           reflect.ValueOf(""),
		"timeout":            reflect.ValueOf(parse.Duration(0)),
		"db":                 reflect.ValueOf(&DatabaseInfo{ServerInfo: ServerInfo{Watch: true, IP: "192.168.1.2", Load: 32, Load64: 64}, ConnectionMax: 3200000000, ConnectionMax64: 6400000000000000000}),
		"db.watch":           reflect.ValueOf(true),
		"db.ip":              reflect.ValueOf("192.168.1.2"),
		"db.load":            reflect.ValueOf(32),
		"db.load64":          reflect.ValueOf(int64(64)),
		"db.comax":           reflect.ValueOf(uint(3200000000)),
		"db.connectionmax64": reflect.ValueOf(uint64(6400000000000000000)),
		"owner":              reflect.ValueOf(&OwnerInfo{Name: nil, DateOfBirth: defaultDob, Rate: 0.111, Servers: []ServerInfo{{Watch: false, IP: "192.168.1.2", Load: 0, Load64: 0}, {Watch: false, IP: "192.168.1.3", Load: 0, Load64: 0}, {Watch: false, IP: "192.168.1.4", Load: 0, Load64: 0}}}),
		"owner.name":         reflect.ValueOf(&defaultStr),
		"owner.dob":          reflect.ValueOf(defaultDob),
		"owner.rate":         reflect.ValueOf(float64(0.111)),
		"owner.servers":      reflect.ValueOf([]ServerInfo{{Watch: false, IP: "192.168.1.2", Load: 0, Load64: 0}, {Watch: false, IP: "192.168.1.3", Load: 0, Load64: 0}, {Watch: false, IP: "192.168.1.4", Load: 0, Load64: 0}}),
	}
	// test
	if err := fillStructRecursive(reflect.ValueOf(config), defaultValMap, valMap, ""); err != nil {
		t.Fatal(err)
	}

	// CHECK
	check := &Configuration{}
	check.Timeout = 5 * parse.Duration(time.Second)
	check.Db = newDefaultPointersConfiguration().Db
	check.Owner = newDefaultPointersConfiguration().Owner
	check.Owner.DateOfBirth, _ = time.Parse(time.RFC3339, "2016-04-20T17:39:00Z")
	check.Owner.Rate = 0.222
	check.Owner.Name = nil
	if !reflect.DeepEqual(config, check) {
		if !reflect.DeepEqual(config.Owner, check.Owner) {
			t.Errorf("\nexpected\t: %+v\ngot\t\t\t: %+v", check.Owner, config.Owner)
		}
		t.Errorf("Error :\nexpected \t%+v \ngot \t\t%+v\n", check, config)
	}
}
// Test fillStructRecursive on empty config with some random valmap field and with default values on pointers
Test fillStructRecursive on empty config with some random valmap field and with default values on pointers
// Test fillStructRecursive on empty config with some random valmap field and with default values on pointers
func TestFillStructRecursiveNoConfigAllDefaultSomeValmap(t *testing.T) {
	config := &Configuration{}
	parsers := map[reflect.Type]parse.Parser{
		reflect.TypeOf([]ServerInfo{}): &sliceServerValue{},
	}
	var boolParser parse.BoolValue
	parsers[reflect.TypeOf(true)] = &boolParser
	var intParser parse.IntValue
	parsers[reflect.TypeOf(1)] = &intParser
	var int64Parser parse.Int64Value
	parsers[reflect.TypeOf(int64(1))] = &int64Parser
	var uintParser parse.UintValue
	parsers[reflect.TypeOf(uint(1))] = &uintParser
	var uint64Parser parse.Uint64Value
	parsers[reflect.TypeOf(uint64(1))] = &uint64Parser
	var stringParser parse.StringValue
	parsers[reflect.TypeOf("")] = &stringParser
	var float64Parser parse.Float64Value
	parsers[reflect.TypeOf(float64(1.5))] = &float64Parser
	var durationParser parse.Duration
	parsers[reflect.TypeOf(parse.Duration(time.Second))] = &durationParser
	var timeParser parse.TimeValue
	parsers[reflect.TypeOf(time.Now())] = &timeParser
	valMap := map[string]parse.Parser{}
	durationParser.SetValue(5 * parse.Duration(time.Second))
	valMap["timeout"] = &durationParser
	boolParser.SetValue(true)
	valMap["db"] = &boolParser
	timeParser.Set("2016-04-20T17:39:00Z")
	valMap["owner.dob"] = &timeParser
	float64Parser.SetValue(0.222)
	valMap["owner.rate"] = &float64Parser
	defaultStr := "DefaultOwnerNamePointer"
	defaultDob, _ := time.Parse(time.RFC3339, "1979-05-27T07:32:00Z")
	defaultValMap := map[string]reflect.Value{
		"loglevel":           reflect.ValueOf(""),
		"timeout":            reflect.ValueOf(parse.Duration(0)),
		"db":                 reflect.ValueOf(&DatabaseInfo{ServerInfo: ServerInfo{Watch: true, IP: "192.168.1.2", Load: 32, Load64: 64}, ConnectionMax: 3200000000, ConnectionMax64: 6400000000000000000}),
		"db.watch":           reflect.ValueOf(true),
		"db.ip":              reflect.ValueOf("192.168.1.2"),
		"db.load":            reflect.ValueOf(32),
		"db.load64":          reflect.ValueOf(int64(64)),
		"db.comax":           reflect.ValueOf(uint(3200000000)),
		"db.connectionmax64": reflect.ValueOf(uint64(6400000000000000000)),
		"owner":              reflect.ValueOf(&OwnerInfo{Name: nil, DateOfBirth: defaultDob, Rate: 0.111, Servers: []ServerInfo{{Watch: false, IP: "192.168.1.2", Load: 0, Load64: 0}, {Watch: false, IP: "192.168.1.3", Load: 0, Load64: 0}, {Watch: false, IP: "192.168.1.4", Load: 0, Load64: 0}}}),
		"owner.name":         reflect.ValueOf(&defaultStr),
		"owner.dob":          reflect.ValueOf(defaultDob),
		"owner.rate":         reflect.ValueOf(float64(0.111)),
		"owner.servers":      reflect.ValueOf([]ServerInfo{{Watch: false, IP: "192.168.1.2", Load: 0, Load64: 0}, {Watch: false, IP: "192.168.1.3", Load: 0, Load64: 0}, {Watch: false, IP: "192.168.1.4", Load: 0, Load64: 0}}),
	}
	if err := fillStructRecursive(reflect.ValueOf(config), defaultValMap, valMap, ""); err != nil {
		t.Fatal(err)
	}
	check := &Configuration{}
	check.Timeout = 5 * parse.Duration(time.Second)
	check.Db = newDefaultPointersConfiguration().Db
	check.Owner = newDefaultPointersConfiguration().Owner
	check.Owner.DateOfBirth, _ = time.Parse(time.RFC3339, "2016-04-20T17:39:00Z")
	check.Owner.Rate = 0.222
	check.Owner.Name = nil
	if !reflect.DeepEqual(config, check) {
		if !reflect.DeepEqual(config.Owner, check.Owner) {
			t.Errorf("\nexpected\t: %+v\ngot\t\t\t: %+v", check.Owner, config.Owner)
		}
		t.Errorf("Error :\nexpected \t%+v \ngot \t\t%+v\n", check, config)
	}
}
func TestFillStructRecursiveNoConfigAllDefaultSomeValmap ( t * testing . T ) { config := & Configuration { } parsers := map [ reflect . Type ] parse . Parser { reflect . TypeOf ( [ ] ServerInfo { } ) : & sliceServerValue { } , } var boolParser parse . BoolValue parsers [ reflect . TypeOf ( true ) ] = & boolParser var intParser parse . IntValue parsers [ reflect . TypeOf ( 1 ) ] = & intParser var int64Parser parse . Int64Value parsers [ reflect . TypeOf ( int64 ( 1 ) ) ] = & int64Parser var uintParser parse . UintValue parsers [ reflect . TypeOf ( uint ( 1 ) ) ] = & uintParser var uint64Parser parse . Uint64Value parsers [ reflect . TypeOf ( uint64 ( 1 ) ) ] = & uint64Parser var stringParser parse . StringValue parsers [ reflect . TypeOf ( " " ) ] = & stringParser var float64Parser parse . Float64Value parsers [ reflect . TypeOf ( float64 ( 1.5 ) ) ] = & float64Parser var durationParser parse . Duration parsers [ reflect . TypeOf ( parse . Duration ( time . Second ) ) ] = & durationParser var timeParser parse . TimeValue parsers [ reflect . TypeOf ( time . Now ( ) ) ] = & timeParser valMap := map [ string ] parse . Parser { } durationParser . SetValue ( 5 * parse . Duration ( time . Second ) ) valMap [ " " ] = & durationParser boolParser . SetValue ( true ) valMap [ " " ] = & boolParser timeParser . Set ( " " ) valMap [ " " ] = & timeParser float64Parser . SetValue ( 0.222 ) valMap [ " " ] = & float64Parser defaultStr := " " defaultDob , _ := time . Parse ( time . RFC3339 , " " ) defaultValMap := map [ string ] reflect . Value { " " : reflect . ValueOf ( " " ) , " " : reflect . ValueOf ( parse . Duration ( 0 ) ) , " " : reflect . ValueOf ( & DatabaseInfo { ServerInfo : ServerInfo { Watch : true , IP : " " , Load : 32 , Load64 : 64 } , ConnectionMax : 3200000000 , ConnectionMax64 : 6400000000000000000 } ) , " " : reflect . ValueOf ( true ) , " " : reflect . ValueOf ( " " ) , " " : reflect . ValueOf ( 32 ) , " " : reflect . ValueOf ( int64 ( 64 ) ) , " " : reflect . ValueOf ( uint ( 3200000000 ) ) , " " : reflect . ValueOf ( uint64 ( 6400000000000000000 ) ) , " " : reflect . ValueOf ( & OwnerInfo { Name : nil , DateOfBirth : defaultDob , Rate : 0.111 , Servers : [ ] ServerInfo { { Watch : false , IP : " " , Load : 0 , Load64 : 0 } , { Watch : false , IP : " " , Load : 0 , Load64 : 0 } , { Watch : false , IP : " " , Load : 0 , Load64 : 0 } } } ) , " " : reflect . ValueOf ( & defaultStr ) , " " : reflect . ValueOf ( defaultDob ) , " " : reflect . ValueOf ( float64 ( 0.111 ) ) , " " : reflect . ValueOf ( [ ] ServerInfo { { Watch : false , IP : " " , Load : 0 , Load64 : 0 } , { Watch : false , IP : " " , Load : 0 , Load64 : 0 } , { Watch : false , IP : " " , Load : 0 , Load64 : 0 } } ) , } if err := fillStructRecursive ( reflect . ValueOf ( config ) , defaultValMap , valMap , " " ) ; err != nil { t . Fatal ( err ) } check := & Configuration { } check . Timeout = 5 * parse . Duration ( time . Second ) check . Db = newDefaultPointersConfiguration ( ) . Db check . Owner = newDefaultPointersConfiguration ( ) . Owner check . Owner . DateOfBirth , _ = time . Parse ( time . RFC3339 , " " ) check . Owner . Rate = 0.222 check . Owner . Name = nil if ! reflect . DeepEqual ( config , check ) { if ! reflect . DeepEqual ( config . Owner , check . Owner ) { t . Errorf ( " \n \t \n \t \t \t " , check . Owner , config . Owner ) } t . Errorf ( " \n \t \n \t \t \n " , check , config ) } }
Test fillStructRecursive on empty config with some random valmap field and with default values on pointers
Test fillStructRecursive on empty config with some random valmap field and with default values on pointers
// init parsers // init valMap // init defaultValMap NoConfigAllDefault // test // CHECK