diff options
author | Michael Muré <michael.mure@consensys.net> | 2019-02-01 12:22:00 +0100 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2019-03-01 22:40:22 +0100 |
commit | 56c6147eb6012252cf0b723b9eb6d1e841fc2f94 (patch) | |
tree | cce638adbf4a7d5b424fe9682cafc2fea5c64785 /misc/random_bugs | |
parent | 14b240af8fef269d2c1d5dde2fff192b656c50f3 (diff) | |
download | git-bug-56c6147eb6012252cf0b723b9eb6d1e841fc2f94.tar.gz |
identity: more refactoring progress
Diffstat (limited to 'misc/random_bugs')
-rw-r--r-- | misc/random_bugs/create_random_bugs.go | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/misc/random_bugs/create_random_bugs.go b/misc/random_bugs/create_random_bugs.go index 085e89f0..0657c808 100644 --- a/misc/random_bugs/create_random_bugs.go +++ b/misc/random_bugs/create_random_bugs.go @@ -34,7 +34,9 @@ func CommitRandomBugs(repo repository.ClockedRepo, opts Options) { } func CommitRandomBugsWithSeed(repo repository.ClockedRepo, opts Options, seed int64) { - bugs := GenerateRandomBugsWithSeed(opts, seed) + generateRandomPersons(repo, opts.PersonNumber) + + bugs := generateRandomBugsWithSeed(opts, seed) for _, b := range bugs { err := b.Commit(repo) @@ -44,11 +46,7 @@ func CommitRandomBugsWithSeed(repo repository.ClockedRepo, opts Options, seed in } } -func GenerateRandomBugs(opts Options) []*bug.Bug { - return GenerateRandomBugsWithSeed(opts, time.Now().UnixNano()) -} - -func GenerateRandomBugsWithSeed(opts Options, seed int64) []*bug.Bug { +func generateRandomBugsWithSeed(opts Options, seed int64) []*bug.Bug { rand.Seed(seed) fake.Seed(seed) @@ -67,7 +65,7 @@ func GenerateRandomBugsWithSeed(opts Options, seed int64) []*bug.Bug { addedLabels = []string{} b, _, err := bug.Create( - randomPerson(opts.PersonNumber), + randomPerson(), time.Now().Unix(), fake.Sentence(), paragraphs(), @@ -85,7 +83,7 @@ func GenerateRandomBugsWithSeed(opts Options, seed int64) []*bug.Bug { for j := 0; j < nOps; j++ { index := rand.Intn(len(opsGenerators)) - opsGenerators[index](b, randomPerson(opts.PersonNumber)) + opsGenerators[index](b, randomPerson()) } result[i] = b @@ -101,6 +99,9 @@ func GenerateRandomOperationPacks(packNumber int, opNumber int) []*bug.Operation func GenerateRandomOperationPacksWithSeed(packNumber int, opNumber int, seed int64) []*bug.OperationPack { // Note: this is a bit crude, only generate a Create + Comments + panic("this piece of code needs to be updated to make sure that the identities " + + "are properly commit before usage. That is, generateRandomPersons() need to be called.") + rand.Seed(seed) fake.Seed(seed) @@ -112,7 +113,7 @@ func GenerateRandomOperationPacksWithSeed(packNumber int, opNumber int, seed int var op bug.Operation op = bug.NewCreateOp( - randomPerson(5), + randomPerson(), time.Now().Unix(), fake.Sentence(), paragraphs(), @@ -123,7 +124,7 @@ func GenerateRandomOperationPacksWithSeed(packNumber int, opNumber int, seed int for j := 0; j < opNumber-1; j++ { op = bug.NewAddCommentOp( - randomPerson(5), + randomPerson(), time.Now().Unix(), paragraphs(), nil, @@ -143,15 +144,20 @@ func person() identity.Interface { var persons []identity.Interface -func randomPerson(personNumber int) identity.Interface { - if len(persons) == 0 { - persons = make([]identity.Interface, personNumber) - for i := range persons { - persons[i] = person() +func generateRandomPersons(repo repository.ClockedRepo, n int) { + persons = make([]identity.Interface, n) + for i := range persons { + p := person() + err := p.Commit(repo) + if err != nil { + panic(err) } + persons[i] = p } +} - index := rand.Intn(personNumber) +func randomPerson() identity.Interface { + index := rand.Intn(len(persons)) return persons[index] } |