Skip to content

Commit f1dc7ec

Browse files
committed
added testdata generator
1 parent b763a02 commit f1dc7ec

File tree

2 files changed

+45
-35
lines changed

2 files changed

+45
-35
lines changed

init.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"log"
6+
"math/rand"
7+
"runtime"
8+
9+
"github.com/alash3al/libsrchx"
10+
"github.com/icrowley/fake"
11+
)
12+
13+
func init() {
14+
var err error
15+
flag.Parse()
16+
17+
runtime.GOMAXPROCS(*flagWorkers)
18+
19+
store, err = srchx.NewStore(*flagEngine, *flagStoragePath)
20+
if err != nil {
21+
log.Fatal(err)
22+
}
23+
24+
if *flagGenFakeData > 0 {
25+
go func() {
26+
ndx, _ := store.GetIndex("test/fake")
27+
fake.SetLang("en")
28+
for i := 0; i < *flagGenFakeData; i++ {
29+
ndx.Put(map[string]interface{}{
30+
"full_name": fake.FullName(),
31+
"country": fake.Country(),
32+
"brand": fake.Brand(),
33+
"email": fake.EmailAddress(),
34+
"ip": fake.IPv4(),
35+
"industry": fake.Industry(),
36+
"age": rand.Intn(100),
37+
"salary": rand.Intn(20) * 1000,
38+
"power": rand.Intn(10),
39+
"family": rand.Intn(10),
40+
})
41+
}
42+
}()
43+
}
44+
}

vars.go

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@ package main
22

33
import (
44
"flag"
5-
"log"
6-
"math/rand"
75
"os"
86
"path"
97
"runtime"
108

11-
"github.com/icrowley/fake"
12-
139
"github.com/alash3al/libsrchx"
1410
)
1511

@@ -18,39 +14,9 @@ var (
1814
flagEngine = flag.String("engine", "boltdb", "the engine to be used as a backend")
1915
flagStoragePath = flag.String("storage", path.Join(path.Dir(os.Args[0]), "data"), "the storage path")
2016
flagWorkers = flag.Int("workers", runtime.NumCPU(), "number of workers to be used")
17+
flagGenFakeData = flag.Int("testdata", 0, "this will generate a `test/fake` collection with fake data just for testing")
2118
)
2219

2320
var (
2421
store *srchx.Store
2522
)
26-
27-
func init() {
28-
var err error
29-
flag.Parse()
30-
31-
runtime.GOMAXPROCS(*flagWorkers)
32-
33-
store, err = srchx.NewStore(*flagEngine, *flagStoragePath)
34-
if err != nil {
35-
log.Fatal(err)
36-
}
37-
38-
go func() {
39-
ndx, _ := store.GetIndex("test/fake")
40-
fake.SetLang("en")
41-
for i := 0; i < 100000; i++ {
42-
ndx.Put(map[string]interface{}{
43-
"full_name": fake.FullName(),
44-
"country": fake.Country(),
45-
"brand": fake.Brand(),
46-
"email": fake.EmailAddress(),
47-
"ip": fake.IPv4(),
48-
"industry": fake.Industry(),
49-
"age": rand.Intn(100),
50-
"salary": rand.Intn(20) * 1000,
51-
"power": rand.Intn(10),
52-
"family": rand.Intn(10),
53-
})
54-
}
55-
}()
56-
}

0 commit comments

Comments
 (0)