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

Configure Feed

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

indexserver: only try decode the returned repos (#211)

We try to decode all repos we passed in. However, with fingerprints we
only get back a subset. So we need to handle EOF.

+27 -6
+17
cmd/zoekt-sourcegraph-indexserver/index_test.go
··· 81 81 continue 82 82 } 83 83 84 + want.CloneURL = sg.getCloneURL(got[0].IndexOptions.Name) 85 + 84 86 if d := cmp.Diff(*want, got[0].IndexOptions); d != "" { 85 87 t.Log("response", r) 86 88 t.Errorf("mismatch (-want +got):\n%s", d) 87 89 } 88 90 } 91 + 92 + // Special case our fingerprint API which doesn't return anything if the 93 + // repo hasn't changed. 94 + t.Run("unchanged", func(t *testing.T) { 95 + response = []byte(``) 96 + 97 + got, err := sg.GetIndexOptions(123) 98 + if err != nil { 99 + t.Fatalf("unexpected error: %v", err) 100 + } 101 + 102 + if len(got) != 0 { 103 + t.Fatalf("expected no options, got %v", got) 104 + } 105 + }) 89 106 } 90 107 91 108 func TestIndex(t *testing.T) {
+10 -6
cmd/zoekt-sourcegraph-indexserver/sg.go
··· 183 183 } 184 184 } 185 185 186 - opts := make([]indexOptionsItem, len(repos)) 187 186 dec := json.NewDecoder(resp.Body) 188 - for i := range opts { 189 - if err := dec.Decode(&opts[i]); err != nil { 190 - return nil, "", fmt.Errorf("error decoding body: %w", err) 187 + var opts []indexOptionsItem 188 + for { 189 + var opt indexOptionsItem 190 + err := dec.Decode(&opt) 191 + if err == io.EOF { 192 + break 191 193 } 192 - if opts[i].Name != "" { 193 - opts[i].CloneURL = s.getCloneURL(opts[i].Name) 194 + if err != nil { 195 + return nil, "", fmt.Errorf("error decoding body: %w", err) 194 196 } 197 + opt.CloneURL = s.getCloneURL(opt.Name) 198 + opts = append(opts, opt) 195 199 } 196 200 197 201 return opts, resp.Header.Get("X-Sourcegraph-Config-Fingerprint"), nil