-
Notifications
You must be signed in to change notification settings - Fork 0
/
seeder.go
69 lines (60 loc) · 1.65 KB
/
seeder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package tools
import (
"fmt"
"math/rand"
"github.com/icrowley/fake"
)
// Seeder generator of dummy data
type Seeder struct {
}
// Create geneate dummy building-data
func (s Seeder) Create() string {
return fmt.Sprintf(`{ "name": "building-%s","address": "address::%s","floors": ["floor-%s","floor-%s"] }`,
fake.DigitsN(12),
fake.DigitsN(15),
fake.DigitsN(5),
fake.DigitsN(5),
)
}
// CreateWithName geneate dummy building-data and with name
func (s Seeder) CreateWithName(name string) string {
return fmt.Sprintf(`{ "name": "%s","address": "address::%s","floors": ["floor-%s","floor-%s"] }`,
name,
fake.DigitsN(15),
fake.DigitsN(5),
fake.DigitsN(5),
)
}
// Update geneate dummy building-data with an ID from parameter
func (s Seeder) Update(pid int64, name string) string {
return fmt.Sprintf(`{ "id": %d, "name": "%s","address": "address::%s","floors": ["floor-%s","floor-%s"] }`,
pid,
name,
fake.DigitsN(15),
fake.DigitsN(5),
fake.DigitsN(5),
)
}
// CreateWithEmptyName geneate dummy building-data with empty name
func (s Seeder) CreateWithEmptyName() string {
return fmt.Sprintf(`{ "name": "","address": "address::%s","floors": ["floor-%s","floor-%s"] }`,
fake.DigitsN(15),
fake.DigitsN(5),
fake.DigitsN(5),
)
}
// CreateFloors generate random floor list
func (s Seeder) CreateFloors() []string {
var floors []string
t := rand.Intn(10) + 1
for i := 1; i <= t; i++ {
floors = append(floors, fmt.Sprintf("floor-%s", fake.DigitsN(15)))
}
return floors
}
// CreateMin geneate dummy building-data and with only name
func (s Seeder) CreateMin() string {
return fmt.Sprintf(`{ "name": "anonymous building %s" }`,
fake.DigitsN(15),
)
}