// Test fillStructRecursive on not-empty struc with only one pointer under pointer valmap field and with default values on pointers
Test fillStructRecursive on not-empty struc with only one pointer under pointer valmap field and with default values on pointers
// Test fillStructRecursive on not - empty struc with only one pointer under pointer valmap field and with default values on pointers
func TestFillStructRecursiveInitConfigAllDefaultPointerUnderPointerValmap(t *testing.T) {
	config := newConfiguration()
	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{}
	boolParser.SetValue(true)
	valMap["owner.name"] = &boolParser
	checkDefaultStr := "DefaultOwnerNamePointer"
	checkDefaultDob, _ := time.Parse(time.RFC3339, "1979-05-27T07:32:00Z")
	checkDob, _ := time.Parse(time.RFC3339, "1993-09-12T07:32:00Z")
	defaultValMap := map[string]reflect.Value{
		"loglevel":           reflect.ValueOf("DEBUG"),
		"timeout":            reflect.ValueOf(parse.Duration(time.Second)),
		"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: checkDefaultDob, 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(&checkDefaultStr),
		"owner.dob":          reflect.ValueOf(checkDob),
		"owner.rate":         reflect.ValueOf(float64(0.999)),
		"owner.servers":      reflect.ValueOf(*new([]ServerInfo)),
	}
	if err := fillStructRecursive(reflect.ValueOf(config), defaultValMap, valMap, ""); err != nil {
		t.Fatal(err)
	}
	check := &Configuration{
		Name:     "initName",
		LogLevel: "DEBUG",
		Timeout:  parse.Duration(time.Second),
		Owner: &OwnerInfo{
			Name:        &checkDefaultStr,
			DateOfBirth: checkDob,
			Rate:        0.999,
		},
	}
	if !reflect.DeepEqual(config, check) {
		fmt.Printf("expected\t: %+v\ngot\t\t\t: %+v\n", check.Db, config.Db)
		fmt.Printf("expected\t: %+v\ngot\t\t\t: %+v\n", check.Owner, config.Owner)
		fmt.Printf("expected\t: %+v\tgot\t\t\t: %+v\n", *check.Owner.Name, *config.Owner.Name)
		t.Errorf("Error :\nexpected \t%+v \ngot \t\t%+v\n", check, config)
	}
}
func TestFillStructRecursiveInitConfigAllDefaultPointerUnderPointerValmap ( t * testing . T ) { config := newConfiguration ( ) 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 { } boolParser . SetValue ( true ) valMap [ " " ] = & boolParser checkDefaultStr := " " checkDefaultDob , _ := time . Parse ( time . RFC3339 , " " ) checkDob , _ := time . Parse ( time . RFC3339 , " " ) defaultValMap := map [ string ] reflect . Value { " " : reflect . ValueOf ( " " ) , " " : reflect . ValueOf ( parse . Duration ( time . Second ) ) , " " : 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 : checkDefaultDob , 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 ( & checkDefaultStr ) , " " : reflect . ValueOf ( checkDob ) , " " : reflect . ValueOf ( float64 ( 0.999 ) ) , " " : reflect . ValueOf ( * new ( [ ] ServerInfo ) ) , } if err := fillStructRecursive ( reflect . ValueOf ( config ) , defaultValMap , valMap , " " ) ; err != nil { t . Fatal ( err ) } check := & Configuration { Name : " " , LogLevel : " " , Timeout : parse . Duration ( time . Second ) , Owner : & OwnerInfo { Name : & checkDefaultStr , DateOfBirth : checkDob , Rate : 0.999 , } , } if ! reflect . DeepEqual ( config , check ) { fmt . Printf ( " \t \n \t \t \t \n " , check . Db , config . Db ) fmt . Printf ( " \t \n \t \t \t \n " , check . Owner , config . Owner ) fmt . Printf ( " \t \t \t \t \t \n " , * check . Owner . Name , * config . Owner . Name ) t . Errorf ( " \n \t \n \t \t \n " , check , config ) } }
Test fillStructRecursive on not-empty struc with only one pointer under pointer valmap field and with default values on pointers
Test fillStructRecursive on not - empty struc with only one pointer under pointer valmap field and with default values on pointers
// init parsers // init valMap // init defaultValMap InitConfigAllDefault from TestGetDefaultValueAll // test // CHECK