1package tests
2
3import (
4 "testing"
5
6 "github.com/MichaelMure/git-bug/bug"
7 "github.com/MichaelMure/git-bug/misc/random_bugs"
8 "github.com/MichaelMure/git-bug/repository"
9 "github.com/MichaelMure/git-bug/util/test"
10)
11
12func CreateFilledRepo(bugNumber int) repository.ClockedRepo {
13 repo := test.CreateRepo(false)
14
15 var seed int64 = 42
16 options := random_bugs.DefaultOptions()
17
18 options.BugNumber = bugNumber
19
20 random_bugs.CommitRandomBugsWithSeed(repo, options, seed)
21 return repo
22}
23
24func TestReadBugs(t *testing.T) {
25 repo := CreateFilledRepo(15)
26 bugs := bug.ReadAllLocalBugs(repo)
27 for b := range bugs {
28 if b.Err != nil {
29 t.Fatal(b.Err)
30 }
31 }
32}
33
34func benchmarkReadBugs(bugNumber int, t *testing.B) {
35 repo := CreateFilledRepo(bugNumber)
36 t.ResetTimer()
37
38 for n := 0; n < t.N; n++ {
39 bugs := bug.ReadAllLocalBugs(repo)
40 for b := range bugs {
41 if b.Err != nil {
42 t.Fatal(b.Err)
43 }
44 }
45 }
46}
47
48func BenchmarkReadBugs5(b *testing.B) { benchmarkReadBugs(5, b) }
49func BenchmarkReadBugs25(b *testing.B) { benchmarkReadBugs(25, b) }
50func BenchmarkReadBugs150(b *testing.B) { benchmarkReadBugs(150, b) }