fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

web: e2e test for RPC (#602)

This would of caught the nil panic which was fixed in the last commit.

Test Plan: go test

+91
+15
stream/client.go
··· 103 103 } 104 104 } 105 105 } 106 + 107 + // WithSearcher returns Streamer composed of s and the streaming client. All 108 + // non-streaming calls will go via s, while streaming calls will go via the 109 + // streaming client. 110 + func (c *Client) WithSearcher(s zoekt.Searcher) zoekt.Streamer { 111 + return &streamer{ 112 + Searcher: s, 113 + Client: c, 114 + } 115 + } 116 + 117 + type streamer struct { 118 + zoekt.Searcher 119 + *Client 120 + }
+76
web/e2e_test.go
··· 24 24 "net/http" 25 25 "net/http/httptest" 26 26 "reflect" 27 + "sort" 27 28 "strings" 28 29 "testing" 29 30 "time" ··· 31 32 "github.com/google/go-cmp/cmp" 32 33 "github.com/sourcegraph/zoekt" 33 34 "github.com/sourcegraph/zoekt/query" 35 + "github.com/sourcegraph/zoekt/rpc" 36 + "github.com/sourcegraph/zoekt/stream" 34 37 ) 35 38 36 39 // TODO(hanwen): cut & paste from ../ . Should create internal test ··· 955 958 t.Fatal("empty result in response") 956 959 } 957 960 } 961 + 962 + func TestRPC(t *testing.T) { 963 + b, err := zoekt.NewIndexBuilder(&zoekt.Repository{ 964 + Name: "name", 965 + URL: "repo-url", 966 + CommitURLTemplate: "{{.Version}}", 967 + FileURLTemplate: "file-url", 968 + LineFragmentTemplate: "#line", 969 + Branches: []zoekt.RepositoryBranch{{Name: "master", Version: "1234"}}, 970 + }) 971 + if err != nil { 972 + t.Fatalf("NewIndexBuilder: %v", err) 973 + } 974 + if err := b.Add(zoekt.Document{ 975 + Name: "f2", 976 + Content: []byte("to carry water in the no later bla"), 977 + // --------------0123456789012345678901234567890123 978 + // --------------0 1 2 3 979 + Branches: []string{"master"}, 980 + }); err != nil { 981 + t.Fatalf("Add: %v", err) 982 + } 983 + 984 + s := searcherForTest(t, b) 985 + srv := Server{ 986 + Searcher: s, 987 + RPC: true, 988 + Top: Top, 989 + } 990 + 991 + mux, err := NewMux(&srv) 992 + if err != nil { 993 + t.Fatalf("NewMux: %v", err) 994 + } 995 + 996 + ts := httptest.NewServer(mux) 997 + defer ts.Close() 998 + 999 + endpoint := ts.Listener.Addr().String() 1000 + 1001 + client := stream.NewClient("http://"+endpoint, nil).WithSearcher(rpc.Client(endpoint)) 1002 + 1003 + ctx := context.Background() 1004 + q := &query.Substring{Pattern: "water"} 1005 + opts := &zoekt.SearchOptions{ChunkMatches: true} 1006 + opts.SetDefaults() 1007 + results, err := client.Search(ctx, q, opts) 1008 + if err != nil { 1009 + t.Fatal(err) 1010 + } 1011 + 1012 + assertResults(t, results.Files, "f2: to carry water in the no later bla") 1013 + 1014 + // TODO grpc, List, StreamSearch 1015 + } 1016 + 1017 + func assertResults(t *testing.T, files []zoekt.FileMatch, want string) { 1018 + t.Helper() 1019 + 1020 + var lines []string 1021 + for _, fm := range files { 1022 + for _, cm := range fm.ChunkMatches { 1023 + lines = append(lines, fmt.Sprintf("%s: %s", fm.FileName, string(cm.Content))) 1024 + } 1025 + } 1026 + sort.Strings(lines) 1027 + got := strings.TrimSpace(strings.Join(lines, "\n")) 1028 + want = strings.TrimSpace(want) 1029 + 1030 + if d := cmp.Diff(want, got); d != "" { 1031 + t.Fatalf("unexpected results (-want, +got):\n%s", d) 1032 + } 1033 + }