-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
139 lines (124 loc) · 2.48 KB
/
example_test.go
File metadata and controls
139 lines (124 loc) · 2.48 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package feign_test
import (
"encoding/json"
"os"
"time"
"github.com/google/uuid"
"github.com/icrowley/fake"
"github.com/mbranch/feign"
)
func Example_struct() {
type person struct {
Name string
Age int
Skills map[string]bool
}
var p person
feign.Seed(0)
feign.MustFill(&p)
output(p)
// Output:
// {
// "Name": "sVedgmJqWUdRj",
// "Age": 22264,
// "Skills": {
// " DMYkESUcXArFAGg": true,
// "HbMLpzQAnthAG": false,
// "IgFoyZenboACW": true,
// "osB": false,
// "pSb": true
// }
// }
}
func Example_fillers() {
type customer struct {
ID uuid.UUID
Email string
Disabled bool
}
var c customer
fake.Seed(0)
feign.Seed(0)
feign.MustFill(&c, func(path string) (interface{}, bool) {
switch path {
case ".Email":
return fake.EmailAddress(), true
default:
return nil, false
}
})
output(c)
// Output:
// {
// "ID": "fa12f92a-fbe0-0f85-08d0-e83bab9cf8ce",
// "Email": "TeresaMiller@Zazio.edu",
// "Disabled": true
// }
}
func Example_int() {
var i int
feign.Seed(0)
feign.MustFill(&i)
output(i)
// Output:
// 12282
}
func Example_string() {
var s string
feign.Seed(0)
feign.MustFill(&s)
output(s)
// Output:
// "sVedgmJqWUdRj"
}
func Example_nested() {
type OrderItem struct {
ProductID int
Name string
PriceFractional int
Attributes map[string]string
}
type Order struct {
ID uuid.UUID
Items []OrderItem
Created time.Time
}
var o Order
feign.Seed(1)
feign.MustFill(&o, func(path string) (interface{}, bool) {
switch path {
case ".Items.PriceFractional":
return 100 + ((feign.Rand().Int63() % 400) * 25), true
default:
return nil, false
}
})
output(o)
// Output:
// {
// "ID": "210fc7bb-8186-39ac-48a4-c6afa2f1581a",
// "Items": [
// {
// "ProductID": 23701,
// "Name": "SCX",
// "PriceFractional": 2875,
// "Attributes": {
// "AmTgVjiMDy": "AGsItGVGGRRDeTRPTNinYcyJ",
// "EYAua wti": "NPFhIvN",
// "IN NY": "XAnZHdKrMfWYLFocFYszCG eZj",
// "TKvBqWJBscgSE": "IsJqDvttR",
// "gTivDxUcOYVZwJCZbf": "PHPGGhoQQQoCFcgJCLF",
// "hrzeTWVmkCrTDsmwcpWKwcxnzDyOyqx": "e",
// "kdflCVbJoFXdsTMGBEdXryjTFQrd": "QW"
// }
// }
// ],
// "Created": "0073-06-09T21:30:44.650537874Z"
// }
}
// output prints the json value to stdout.
func output(v interface{}) {
e := json.NewEncoder(os.Stdout)
e.SetIndent("", " ")
_ = e.Encode(v)
}