aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--misc/random_bugs/create_random_bugs.go60
-rw-r--r--misc/random_bugs/main.go2
-rw-r--r--tests/read_bugs_test.go2
3 files changed, 56 insertions, 8 deletions
diff --git a/misc/random_bugs/create_random_bugs.go b/misc/random_bugs/create_random_bugs.go
index 46ca7964..87845b3c 100644
--- a/misc/random_bugs/create_random_bugs.go
+++ b/misc/random_bugs/create_random_bugs.go
@@ -29,11 +29,26 @@ func DefaultOptions() Options {
}
}
-func GenerateRandomBugs(repo repository.Repo, opts Options) {
- GenerateRandomBugsWithSeed(repo, opts, time.Now().UnixNano())
+func CommitRandomBugs(repo repository.Repo, opts Options) {
+ CommitRandomBugsWithSeed(repo, opts, time.Now().UnixNano())
}
-func GenerateRandomBugsWithSeed(repo repository.Repo, opts Options, seed int64) {
+func CommitRandomBugsWithSeed(repo repository.Repo, opts Options, seed int64) {
+ bugs := GenerateRandomBugsWithSeed(opts, seed)
+
+ for _, b := range bugs {
+ err := b.Commit(repo)
+ if err != nil {
+ panic(err)
+ }
+ }
+}
+
+func GenerateRandomBugs(opts Options) []*bug.Bug {
+ return GenerateRandomBugsWithSeed(opts, time.Now().UnixNano())
+}
+
+func GenerateRandomBugsWithSeed(opts Options, seed int64) []*bug.Bug {
rand.Seed(seed)
fake.Seed(seed)
@@ -46,6 +61,8 @@ func GenerateRandomBugsWithSeed(repo repository.Repo, opts Options, seed int64)
operations.Close,
}
+ result := make([]*bug.Bug, opts.BugNumber)
+
for i := 0; i < opts.BugNumber; i++ {
addedLabels = []string{}
@@ -61,11 +78,42 @@ func GenerateRandomBugsWithSeed(repo repository.Repo, opts Options, seed int64)
opsGenerators[index](b, randomPerson(opts.PersonNumber))
}
- err = b.Commit(repo)
- if err != nil {
- panic(err)
+ result[i] = b
+ }
+
+ return result
+}
+
+func GenerateRandomOperationPacks(packNumber int, opNumber int) []*bug.OperationPack {
+ return GenerateRandomOperationPacksWithSeed(packNumber, opNumber, time.Now().UnixNano())
+}
+
+func GenerateRandomOperationPacksWithSeed(packNumber int, opNumber int, seed int64) []*bug.OperationPack {
+ // Note: this is a bit crude, only generate a Create + Comments
+
+ rand.Seed(seed)
+ fake.Seed(seed)
+
+ result := make([]*bug.OperationPack, packNumber)
+
+ for i := 0; i < packNumber; i++ {
+ opp := &bug.OperationPack{}
+
+ var op bug.Operation
+
+ op = operations.NewCreateOp(randomPerson(5), fake.Sentence(), paragraphs(), nil)
+
+ opp.Append(op)
+
+ for j := 0; j < opNumber-1; j++ {
+ op = operations.NewAddCommentOp(randomPerson(5), paragraphs(), nil)
+ opp.Append(op)
}
+
+ result[i] = opp
}
+
+ return result
}
func person() bug.Person {
diff --git a/misc/random_bugs/main.go b/misc/random_bugs/main.go
index 7211548e..31b12e45 100644
--- a/misc/random_bugs/main.go
+++ b/misc/random_bugs/main.go
@@ -24,5 +24,5 @@ func main() {
panic(err)
}
- rb.GenerateRandomBugs(repo, rb.DefaultOptions())
+ rb.CommitRandomBugs(repo, rb.DefaultOptions())
}
diff --git a/tests/read_bugs_test.go b/tests/read_bugs_test.go
index e0f708a5..b4513bb4 100644
--- a/tests/read_bugs_test.go
+++ b/tests/read_bugs_test.go
@@ -16,7 +16,7 @@ func createFilledRepo(bugNumber int) repository.Repo {
options.BugNumber = bugNumber
- random_bugs.GenerateRandomBugsWithSeed(repo, options, seed)
+ random_bugs.CommitRandomBugsWithSeed(repo, options, seed)
return repo
}