func TestFillStructRecursiveNoConfigNoDefaultTrivialValMap(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

	// init defaultValMap NoConfigNoDefault
	defaultValMap := map[string]reflect.Value{
		"loglevel":           reflect.ValueOf(""),
		"timeout":            reflect.ValueOf(parse.Duration(time.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
	check := &Configuration{}
	check.LogLevel = "INFO"
	check.Timeout = parse.Duration(time.Second)
	if !reflect.DeepEqual(config, check) {
		t.Errorf("Error :\nexpected \t%+v \ngot \t\t%+v\n", check, config)
	}
}
// Test fillStructRecursive on empty config with trivial valMap field and without default values on pointers
Test fillStructRecursive on empty config with trivial valMap field and without default values on pointers
// Test fillStructRecursive on empty config with trivial valMap field and without default values on pointers
func TestFillStructRecursiveNoConfigNoDefaultTrivialValMap(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
	defaultValMap := map[string]reflect.Value{
		"loglevel":           reflect.ValueOf(""),
		"timeout":            reflect.ValueOf(parse.Duration(time.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)
	}
	check := &Configuration{}
	check.LogLevel = "INFO"
	check.Timeout = parse.Duration(time.Second)
	if !reflect.DeepEqual(config, check) {
		t.Errorf("Error :\nexpected \t%+v \ngot \t\t%+v\n", check, config)
	}
}
func TestFillStructRecursiveNoConfigNoDefaultTrivialValMap ( 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 defaultValMap := map [ string ] reflect . Value { " " : reflect . ValueOf ( " " ) , " " : reflect . ValueOf ( parse . Duration ( time . 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 ) } check := & Configuration { } check . LogLevel = " " check . Timeout = parse . Duration ( time . Second ) if ! reflect . DeepEqual ( config , check ) { t . Errorf ( " \n \t \n \t \t \n " , check , config ) } }
Test fillStructRecursive on empty config with trivial valMap field and without default values on pointers
Test fillStructRecursive on empty config with trivial valMap field and without default values on pointers
// init parsers // init valMap // init defaultValMap NoConfigNoDefault // test // CHECK