func TestList(t *testing.T) {
	var rows = []struct {
		hosts  []string
		re     string
		ldList []string
		expect []string
	}{
		{
			[]string{"www.google.com", "127.0.0.1", "hostA", "hostB", "hostC"},
			"",
			[]string{"hostB"}, // hostB is lameduck.
			[]string{"www.google.com", "127.0.0.1", "hostA", "hostC"},
		},
		{
			[]string{"www.google.com", "127.0.0.1", "hostA", "hostB", "hostC"},
			".*",
			nil,
			[]string{"www.google.com", "127.0.0.1", "hostA", "hostB", "hostC"},
		},
		{
			[]string{"www.google.com", "127.0.0.1", "hostA", "hostB", "hostC"},
			"host.*",
			[]string{"hostC"}, // hostC is lameduck.
			[]string{"hostA", "hostB"},
		},
		{
			[]string{"www.google.com", "127.0.0.1", "hostA", "hostB", "hostC"},
			"empty.*",
			nil,
			[]string{},
		},
	}

	for id, r := range rows {
		targetsDef := &targets.TargetsDef{
			Regex: proto.String(r.re),
			Type: &targets.TargetsDef_HostNames{
				HostNames: strings.Join(r.hosts, ","),
			},
		}
		bt, err := targets.New(targetsDef, &mockLDLister{r.ldList}, nil, nil, nil)
		if err != nil {
			t.Fatalf("Unexpected error building targets: %v", err)
		}
		got := bt.List()

		// Got \subset Expected
		missing := getMissing(got, r.expect)
		if len(missing) != 0 {
			t.Error("In test row ", id, ": Got unexpected hosts: ", missing)
		}
		// Expected \subset Got
		missing = getMissing(r.expect, got)
		if len(missing) != 0 {
			t.Error("In test row ", id, ": Expected hosts: ", missing)
		}
	}
}
// TestList does not test the targets.New function, and is specifically testing
// the implementation of targets.targets directly
TestList does not test the targets.New function, and is specifically testing
the implementation of targets.targets directly
// TestList does not test the targets . New function and is specifically testing // the implementation of targets . targets directly
func TestList(t *testing.T) {
	var rows = []struct {
		hosts  []string
		re     string
		ldList []string
		expect []string
	}{
		{
			[]string{"www.google.com", "127.0.0.1", "hostA", "hostB", "hostC"},
			"",
			[]string{"hostB"}, 
			[]string{"www.google.com", "127.0.0.1", "hostA", "hostC"},
		},
		{
			[]string{"www.google.com", "127.0.0.1", "hostA", "hostB", "hostC"},
			".*",
			nil,
			[]string{"www.google.com", "127.0.0.1", "hostA", "hostB", "hostC"},
		},
		{
			[]string{"www.google.com", "127.0.0.1", "hostA", "hostB", "hostC"},
			"host.*",
			[]string{"hostC"}, 
			[]string{"hostA", "hostB"},
		},
		{
			[]string{"www.google.com", "127.0.0.1", "hostA", "hostB", "hostC"},
			"empty.*",
			nil,
			[]string{},
		},
	}
	for id, r := range rows {
		targetsDef := &targets.TargetsDef{
			Regex: proto.String(r.re),
			Type: &targets.TargetsDef_HostNames{
				HostNames: strings.Join(r.hosts, ","),
			},
		}
		bt, err := targets.New(targetsDef, &mockLDLister{r.ldList}, nil, nil, nil)
		if err != nil {
			t.Fatalf("Unexpected error building targets: %v", err)
		}
		got := bt.List()
		missing := getMissing(got, r.expect)
		if len(missing) != 0 {
			t.Error("In test row ", id, ": Got unexpected hosts: ", missing)
		}
		missing = getMissing(r.expect, got)
		if len(missing) != 0 {
			t.Error("In test row ", id, ": Expected hosts: ", missing)
		}
	}
}
func TestList ( t * testing . T ) { var rows = [ ] struct { hosts [ ] string re string ldList [ ] string expect [ ] string } { { [ ] string { " " , " " , " " , " " , " " } , " " , [ ] string { " " } , [ ] string { " " , " " , " " , " " } , } , { [ ] string { " " , " " , " " , " " , " " } , " " , nil , [ ] string { " " , " " , " " , " " , " " } , } , { [ ] string { " " , " " , " " , " " , " " } , " " , [ ] string { " " } , [ ] string { " " , " " } , } , { [ ] string { " " , " " , " " , " " , " " } , " " , nil , [ ] string { } , } , } for id , r := range rows { targetsDef := & targets . TargetsDef { Regex : proto . String ( r . re ) , Type : & targets . TargetsDef_HostNames { HostNames : strings . Join ( r . hosts , " " ) , } , } bt , err := targets . New ( targetsDef , & mockLDLister { r . ldList } , nil , nil , nil ) if err != nil { t . Fatalf ( " " , err ) } got := bt . List ( ) missing := getMissing ( got , r . expect ) if len ( missing ) != 0 { t . Error ( " " , id , " " , missing ) } missing = getMissing ( r . expect , got ) if len ( missing ) != 0 { t . Error ( " " , id , " " , missing ) } } }
TestList does not test the targets.New function, and is specifically testing
the implementation of targets.targets directly
TestList does not test the targets . New function and is specifically testing the implementation of targets . targets directly
// hostB is lameduck. // hostC is lameduck. // Got \subset Expected // Expected \subset Got