func TestParseArgsCustomFlag(t *testing.T) {
	// We assume that getTypesRecursive works well
	config := newConfiguration()
	flagMap := make(map[string]reflect.StructField)
	if err := getTypesRecursive(reflect.ValueOf(config), flagMap, ""); err != nil {
		t.Fatal(err)
	}

	// 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 args
	args := []string{
		"--owner.servers=127.0.0.1",
		"--owner.servers=1.0.0.1",
	}

	// test
	valMap, err := parseArgs(args, flagMap, parsers)
	if err != nil {
		t.Fatal(err)
	}

	// check
	check := map[string]parse.Parser{}
	checkOwnerServers := sliceServerValue{
		ServerInfo{IP: "127.0.0.1"},
		ServerInfo{IP: "1.0.0.1"},
	}
	check["owner.servers"] = &checkOwnerServers

	if len(check) != len(valMap) {
		t.Errorf("expected %d elements in valMap got %d", len(check), len(valMap))
	}

	for flag, parser := range valMap {
		if !reflect.DeepEqual(parser, check[flag]) {
			t.Errorf("Got %s expected %s\n", parser, check[flag])
		}
	}
}
// Test ParseArgs call Flag with custom parsers
Test ParseArgs call Flag with custom parsers
// Test ParseArgs call Flag with custom parsers
func TestParseArgsCustomFlag(t *testing.T) {
	config := newConfiguration()
	flagMap := make(map[string]reflect.StructField)
	if err := getTypesRecursive(reflect.ValueOf(config), flagMap, ""); err != nil {
		t.Fatal(err)
	}
	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
	args := []string{
		"--owner.servers=127.0.0.1",
		"--owner.servers=1.0.0.1",
	}
	valMap, err := parseArgs(args, flagMap, parsers)
	if err != nil {
		t.Fatal(err)
	}
	check := map[string]parse.Parser{}
	checkOwnerServers := sliceServerValue{
		ServerInfo{IP: "127.0.0.1"},
		ServerInfo{IP: "1.0.0.1"},
	}
	check["owner.servers"] = &checkOwnerServers
	if len(check) != len(valMap) {
		t.Errorf("expected %d elements in valMap got %d", len(check), len(valMap))
	}
	for flag, parser := range valMap {
		if !reflect.DeepEqual(parser, check[flag]) {
			t.Errorf("Got %s expected %s\n", parser, check[flag])
		}
	}
}
func TestParseArgsCustomFlag ( t * testing . T ) { config := newConfiguration ( ) flagMap := make ( map [ string ] reflect . StructField ) if err := getTypesRecursive ( reflect . ValueOf ( config ) , flagMap , " " ) ; err != nil { t . Fatal ( err ) } 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 args := [ ] string { " " , " " , } valMap , err := parseArgs ( args , flagMap , parsers ) if err != nil { t . Fatal ( err ) } check := map [ string ] parse . Parser { } checkOwnerServers := sliceServerValue { ServerInfo { IP : " " } , ServerInfo { IP : " " } , } check [ " " ] = & checkOwnerServers if len ( check ) != len ( valMap ) { t . Errorf ( " " , len ( check ) , len ( valMap ) ) } for flag , parser := range valMap { if ! reflect . DeepEqual ( parser , check [ flag ] ) { t . Errorf ( " \n " , parser , check [ flag ] ) } } }
Test ParseArgs call Flag with custom parsers
Test ParseArgs call Flag with custom parsers
// We assume that getTypesRecursive works well // init parsers // init args // test // check