Exemplo n.º 1
0
func TestGetCategory(t *testing.T) {
	tests := []struct {
		analyzers []Analyzer
		expected  []string
	}{
		{nil, nil},
		{[]Analyzer{fakeAnalyzer{"Foo", nil, nil}}, []string{"Foo"}},
		{[]Analyzer{fakeAnalyzer{"", nil, nil}}, []string{""}},
		{
			[]Analyzer{
				fakeAnalyzer{"Foo", nil, nil},
				fakeAnalyzer{"Bar", nil, nil},
			},
			[]string{"Foo", "Bar"},
		},
	}

	for _, test := range tests {
		a := CreateAnalyzerService(test.analyzers, ctxpb.Stage_PRE_BUILD)

		in := &rpcpb.GetCategoryRequest{}
		resp, _ := a.GetCategory(nil, in)

		if !strings.Equal(resp.Category, test.expected) {
			t.Errorf("For analyzers %v: got %v, want %v", test.analyzers, resp.Category, test.expected)
		}
	}
}
Exemplo n.º 2
0
func TestGetServiceInfo(t *testing.T) {
	addr2, cleanup, err := testutil.CreatekRPCTestServer(&fakeDispatcher{[]string{"Foo", "Bar"}, nil}, "AnalyzerService")
	if err != nil {
		t.Fatalf("Registering analyzer service failed: %v", err)
	}
	defer cleanup()

	addr0, cleanup, err := testutil.CreatekRPCTestServer(&fakeDispatcher{nil, nil}, "AnalyzerService")
	if err != nil {
		t.Fatalf("Registering analyzer service failed: %v", err)
	}
	defer cleanup()

	addre, cleanup, err := testutil.CreatekRPCTestServer(&errDispatcher{}, "AnalyzerService")
	if err != nil {
		t.Fatalf("Registering analyzer service failed: %v", err)
	}
	defer cleanup()

	addrp, cleanup, err := testutil.CreatekRPCTestServer(&panicDispatcher{}, "AnalyzerService")
	if err != nil {
		t.Fatalf("Registering analyzer service failed: %v", err)
	}
	defer cleanup()

	tests := []struct {
		addrs  []string
		result map[string]strset.Set
	}{
		{[]string{addr0}, map[string]strset.Set{addr0: nil}},
		{[]string{addr2}, map[string]strset.Set{addr2: strset.New("Foo", "Bar")}},
		{[]string{addr0, addr2}, map[string]strset.Set{addr2: strset.New("Foo", "Bar"), addr0: nil}},
		{[]string{addrp, addr2}, map[string]strset.Set{addr2: strset.New("Foo", "Bar"), addrp: nil}},
		{[]string{addre, addr2}, map[string]strset.Set{addr2: strset.New("Foo", "Bar"), addre: nil}},
	}

	for _, test := range tests {
		driver := NewDriver(test.addrs, nil)
		info := driver.getAllServiceInfo()

		if len(test.result) != len(info) {
			t.Errorf("Incorrect number of results: got %v, want %v", info, test.result)
		}

		for addr, expectCats := range test.result {
			if !strset.Equal(info[strings.TrimPrefix(addr, "http://")].categories.ToSlice(), expectCats.ToSlice()) {
				t.Errorf("Incorrect categories for %s: got %v, want %v", addr, info[addr].categories, expectCats)
			}
		}
	}
}