// Test fillStructRecursive on empty config without valmap and without default values pointers
Test fillStructRecursive on empty config without valmap and without default values pointers
// Test fillStructRecursive on empty config without valmap and without default values pointers
func TestFillStructRecursiveNoConfigAllDefaultNoValmap(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{}
	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{}
	if !reflect.DeepEqual(config, check) {
		t.Errorf("Error :\nexpected \t%+v \ngot \t\t%+v\n", check, config)
	}
}
func TestFillStructRecursiveNoConfigAllDefaultNoValmap ( 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 { } 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 { } if ! reflect . DeepEqual ( config , check ) { t . Errorf ( " \n \t \n \t \t \n " , check , config ) } }
Test fillStructRecursive on empty config without valmap and without default values pointers
Test fillStructRecursive on empty config without valmap and without default values pointers
// init parsers // init valMap // init defaultValMap NoConfigAllDefault // test // CHECK