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

Configure Feed

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

build: check that build for v16 matches golden shard

This is an extra check to ensure that across commits we still build the
same output. This will be useful in the future when we support building
both v16 and whatever next we add.

Co-authored-by: Stefan Hengl <stefan@sourcegraph.com>

+75 -5
+4
build/builder.go
··· 205 205 finishedShards map[string]string 206 206 207 207 shardLogger io.WriteCloser 208 + 209 + // indexTime is set by tests for doing reproducible builds. 210 + indexTime time.Time 208 211 } 209 212 210 213 type finishedShard struct { ··· 673 676 if err != nil { 674 677 return nil, err 675 678 } 679 + shardBuilder.IndexTime = b.indexTime 676 680 return shardBuilder, nil 677 681 } 678 682
+59
build/builder_test.go
··· 2 2 3 3 import ( 4 4 "flag" 5 + "os" 6 + "path/filepath" 5 7 "testing" 8 + "time" 6 9 7 10 "github.com/google/go-cmp/cmp" 8 11 "github.com/google/go-cmp/cmp/cmpopts" 12 + "github.com/google/zoekt" 9 13 ) 14 + 15 + // ensure we don't regress on how we build v16 16 + func TestBuildv16(t *testing.T) { 17 + dir := t.TempDir() 18 + 19 + opts := Options{ 20 + IndexDir: dir, 21 + RepositoryDescription: zoekt.Repository{ 22 + Name: "repo", 23 + Source: "./testdata/repo/", 24 + }, 25 + DisableCTags: true, 26 + } 27 + opts.SetDefaults() 28 + 29 + b, err := NewBuilder(opts) 30 + if err != nil { 31 + t.Fatal(err) 32 + } 33 + b.indexTime, _ = time.Parse(time.RFC3339, "2018-07-06T18:44:45-07:00") 34 + 35 + for _, p := range []string{"main.go"} { 36 + blob, err := os.ReadFile(filepath.Join("../testdata/repo", p)) 37 + if err != nil { 38 + t.Fatal(err) 39 + } 40 + b.AddFile(p, blob) 41 + } 42 + 43 + if err := b.Finish(); err != nil { 44 + t.Fatal(err) 45 + } 46 + 47 + gotP := filepath.Join(dir, "repo_v16.00000.zoekt") 48 + wantP := filepath.Join("../testdata/shards", "repo_v16.00000.zoekt") 49 + 50 + // uncomment to update 51 + //err = os.Rename(gotP, wantP) 52 + //if err != nil { 53 + // t.Fatal(err) 54 + //} 55 + 56 + got, err := os.ReadFile(gotP) 57 + if err != nil { 58 + t.Fatal(err) 59 + } 60 + want, err := os.ReadFile(wantP) 61 + if err != nil { 62 + t.Fatal(err) 63 + } 64 + 65 + if d := cmp.Diff(want, got); d != "" { 66 + t.Errorf("mismatch (-want +got):\n%s", d) 67 + } 68 + } 10 69 11 70 func TestFlags(t *testing.T) { 12 71 cases := []struct {
+1 -4
build/e2e_test.go
··· 35 35 ) 36 36 37 37 func TestBasic(t *testing.T) { 38 - dir, err := ioutil.TempDir("", "") 39 - if err != nil { 40 - t.Fatalf("TempDir: %v", err) 41 - } 38 + dir := t.TempDir() 42 39 43 40 opts := Options{ 44 41 IndexDir: dir,
+5
indexbuilder.go
··· 23 23 "log" 24 24 "path/filepath" 25 25 "sort" 26 + "time" 26 27 "unicode/utf8" 27 28 ) 28 29 ··· 179 180 180 181 // languages codes 181 182 languages []byte 183 + 184 + // IndexTime will be used as the time if non-zero. Otherwise 185 + // time.Now(). This is useful for doing reproducible builds in tests. 186 + IndexTime time.Time 182 187 } 183 188 184 189 func (d *Repository) verify() error {
testdata/shards/repo_v16.00000.zoekt

This is a binary file and will not be displayed.

+6 -1
write.go
··· 147 147 w.Write(marshalDocSections(b.runeDocSections)) 148 148 toc.runeDocSections.end(w) 149 149 150 + indexTime := b.IndexTime 151 + if indexTime.IsZero() { 152 + indexTime = time.Now() 153 + } 154 + 150 155 if err := b.writeJSON(&IndexMetadata{ 151 156 IndexFormatVersion: IndexFormatVersion, 152 - IndexTime: time.Now(), 157 + IndexTime: indexTime, 153 158 IndexFeatureVersion: FeatureVersion, 154 159 PlainASCII: b.contentPostings.isPlainASCII && b.namePostings.isPlainASCII, 155 160 LanguageMap: b.languageMap,