func TestFillStructRecursiveNoConfigNoDefaultAllValmap(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{}
	stringParser.SetValue("INFO")
	valMap["loglevel"] = &stringParser
	durationParser.SetValue(parse.Duration(time.Second))
	valMap["timeout"] = &durationParser
	boolParser.SetValue(true)
	valMap["db"] = &boolParser
	valMap["db.watch"] = &boolParser
	valmapDcIP := parse.StringValue("192.168.0.1")
	valMap["db.ip"] = &valmapDcIP
	intParser.SetValue(-1)
	valMap["db.load"] = &intParser
	int64Parser.SetValue(int64(-164))
	valMap["db.load64"] = &int64Parser
	uintParser.SetValue(uint(2))
	valMap["db.comax"] = &uintParser
	uint64Parser.SetValue(uint64(264))
	valMap["db.connectionmax64"] = &uint64Parser
	valMap["owner"] = &boolParser
	valMap["owner.name"] = &boolParser
	timeParser.Set("2016-04-20T17:39:00Z")
	valMap["owner.dob"] = &timeParser
	float64Parser.SetValue(0.222)
	valMap["owner.rate"] = &float64Parser
	valmapOwnerServers := sliceServerValue{
		ServerInfo{IP: "1.0.0.1"},
	}
	valMap["owner.servers"] = &valmapOwnerServers

	// init defaultValMap NoConfigNoDefault
	defaultValMap := map[string]reflect.Value{
		"loglevel":           reflect.ValueOf(""),
		"timeout":            reflect.ValueOf(parse.Duration(0)),
		"db":                 reflect.ValueOf(&DatabaseInfo{}),
		"db.watch":           reflect.ValueOf(false),
		"db.ip":              reflect.ValueOf(""),
		"db.load":            reflect.ValueOf(0),
		"db.load64":          reflect.ValueOf(int64(0)),
		"db.comax":           reflect.ValueOf(uint(0)),
		"db.connectionmax64": reflect.ValueOf(uint64(0)),
		"owner":              reflect.ValueOf(&OwnerInfo{}),
		"owner.name":         reflect.ValueOf(new(string)),
		"owner.dob":          reflect.ValueOf(time.Time{}),
		"owner.rate":         reflect.ValueOf(float64(0)),
		"owner.servers":      reflect.ValueOf(*new([]ServerInfo)),
	}

	// test
	if err := fillStructRecursive(reflect.ValueOf(config), defaultValMap, valMap, ""); err != nil {
		t.Fatal(err)
	}

	// CHECK
	checkDob, _ := time.Parse(time.RFC3339, "2016-04-20T17:39:00Z")
	check := &Configuration{
		LogLevel: "INFO",
		Timeout:  parse.Duration(time.Second),
		Db: &DatabaseInfo{
			ServerInfo: ServerInfo{
				Watch:  true,
				IP:     "192.168.0.1",
				Load:   -1,
				Load64: int64(-164),
			},
			ConnectionMax:   uint(2),
			ConnectionMax64: uint64(264),
		},
		Owner: &OwnerInfo{
			Name:        new(string),
			DateOfBirth: checkDob,
			Rate:        float64(0.222),
			Servers:     []ServerInfo{{IP: "1.0.0.1"}},
		},
	}

	if !reflect.DeepEqual(config, check) {
		t.Errorf("Error :\nexpected \t%+v \ngot \t\t%+v\n", check, config)
	}
}
// Test fillStructRecursive on empty config with all valmap field but without default values on pointers
Test fillStructRecursive on empty config with all valmap field but without default values on pointers
// Test fillStructRecursive on empty config with all valmap field but without default values on pointers
func TestFillStructRecursiveNoConfigNoDefaultAllValmap(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{}
	stringParser.SetValue("INFO")
	valMap["loglevel"] = &stringParser
	durationParser.SetValue(parse.Duration(time.Second))
	valMap["timeout"] = &durationParser
	boolParser.SetValue(true)
	valMap["db"] = &boolParser
	valMap["db.watch"] = &boolParser
	valmapDcIP := parse.StringValue("192.168.0.1")
	valMap["db.ip"] = &valmapDcIP
	intParser.SetValue(-1)
	valMap["db.load"] = &intParser
	int64Parser.SetValue(int64(-164))
	valMap["db.load64"] = &int64Parser
	uintParser.SetValue(uint(2))
	valMap["db.comax"] = &uintParser
	uint64Parser.SetValue(uint64(264))
	valMap["db.connectionmax64"] = &uint64Parser
	valMap["owner"] = &boolParser
	valMap["owner.name"] = &boolParser
	timeParser.Set("2016-04-20T17:39:00Z")
	valMap["owner.dob"] = &timeParser
	float64Parser.SetValue(0.222)
	valMap["owner.rate"] = &float64Parser
	valmapOwnerServers := sliceServerValue{
		ServerInfo{IP: "1.0.0.1"},
	}
	valMap["owner.servers"] = &valmapOwnerServers
	defaultValMap := map[string]reflect.Value{
		"loglevel":           reflect.ValueOf(""),
		"timeout":            reflect.ValueOf(parse.Duration(0)),
		"db":                 reflect.ValueOf(&DatabaseInfo{}),
		"db.watch":           reflect.ValueOf(false),
		"db.ip":              reflect.ValueOf(""),
		"db.load":            reflect.ValueOf(0),
		"db.load64":          reflect.ValueOf(int64(0)),
		"db.comax":           reflect.ValueOf(uint(0)),
		"db.connectionmax64": reflect.ValueOf(uint64(0)),
		"owner":              reflect.ValueOf(&OwnerInfo{}),
		"owner.name":         reflect.ValueOf(new(string)),
		"owner.dob":          reflect.ValueOf(time.Time{}),
		"owner.rate":         reflect.ValueOf(float64(0)),
		"owner.servers":      reflect.ValueOf(*new([]ServerInfo)),
	}
	if err := fillStructRecursive(reflect.ValueOf(config), defaultValMap, valMap, ""); err != nil {
		t.Fatal(err)
	}
	checkDob, _ := time.Parse(time.RFC3339, "2016-04-20T17:39:00Z")
	check := &Configuration{
		LogLevel: "INFO",
		Timeout:  parse.Duration(time.Second),
		Db: &DatabaseInfo{
			ServerInfo: ServerInfo{
				Watch:  true,
				IP:     "192.168.0.1",
				Load:   -1,
				Load64: int64(-164),
			},
			ConnectionMax:   uint(2),
			ConnectionMax64: uint64(264),
		},
		Owner: &OwnerInfo{
			Name:        new(string),
			DateOfBirth: checkDob,
			Rate:        float64(0.222),
			Servers:     []ServerInfo{{IP: "1.0.0.1"}},
		},
	}
	if !reflect.DeepEqual(config, check) {
		t.Errorf("Error :\nexpected \t%+v \ngot \t\t%+v\n", check, config)
	}
}
func TestFillStructRecursiveNoConfigNoDefaultAllValmap ( 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 { } stringParser . SetValue ( " " ) valMap [ " " ] = & stringParser durationParser . SetValue ( parse . Duration ( time . Second ) ) valMap [ " " ] = & durationParser boolParser . SetValue ( true ) valMap [ " " ] = & boolParser valMap [ " " ] = & boolParser valmapDcIP := parse . StringValue ( " " ) valMap [ " " ] = & valmapDcIP intParser . SetValue ( - 1 ) valMap [ " " ] = & intParser int64Parser . SetValue ( int64 ( - 164 ) ) valMap [ " " ] = & int64Parser uintParser . SetValue ( uint ( 2 ) ) valMap [ " " ] = & uintParser uint64Parser . SetValue ( uint64 ( 264 ) ) valMap [ " " ] = & uint64Parser valMap [ " " ] = & boolParser valMap [ " " ] = & boolParser timeParser . Set ( " " ) valMap [ " " ] = & timeParser float64Parser . SetValue ( 0.222 ) valMap [ " " ] = & float64Parser valmapOwnerServers := sliceServerValue { ServerInfo { IP : " " } , } valMap [ " " ] = & valmapOwnerServers defaultValMap := map [ string ] reflect . Value { " " : reflect . ValueOf ( " " ) , " " : reflect . ValueOf ( parse . Duration ( 0 ) ) , " " : reflect . ValueOf ( & DatabaseInfo { } ) , " " : reflect . ValueOf ( false ) , " " : reflect . ValueOf ( " " ) , " " : reflect . ValueOf ( 0 ) , " " : reflect . ValueOf ( int64 ( 0 ) ) , " " : reflect . ValueOf ( uint ( 0 ) ) , " " : reflect . ValueOf ( uint64 ( 0 ) ) , " " : reflect . ValueOf ( & OwnerInfo { } ) , " " : reflect . ValueOf ( new ( string ) ) , " " : reflect . ValueOf ( time . Time { } ) , " " : reflect . ValueOf ( float64 ( 0 ) ) , " " : reflect . ValueOf ( * new ( [ ] ServerInfo ) ) , } if err := fillStructRecursive ( reflect . ValueOf ( config ) , defaultValMap , valMap , " " ) ; err != nil { t . Fatal ( err ) } checkDob , _ := time . Parse ( time . RFC3339 , " " ) check := & Configuration { LogLevel : " " , Timeout : parse . Duration ( time . Second ) , Db : & DatabaseInfo { ServerInfo : ServerInfo { Watch : true , IP : " " , Load : - 1 , Load64 : int64 ( - 164 ) , } , ConnectionMax : uint ( 2 ) , ConnectionMax64 : uint64 ( 264 ) , } , Owner : & OwnerInfo { Name : new ( string ) , DateOfBirth : checkDob , Rate : float64 ( 0.222 ) , Servers : [ ] ServerInfo { { IP : " " } } , } , } if ! reflect . DeepEqual ( config , check ) { t . Errorf ( " \n \t \n \t \t \n " , check , config ) } }
Test fillStructRecursive on empty config with all valmap field but without default values on pointers
Test fillStructRecursive on empty config with all valmap field but without default values on pointers
// init parsers // init valMap // init defaultValMap NoConfigNoDefault // test // CHECK