/
fixture.go
81 lines (77 loc) · 1.43 KB
/
fixture.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
70
71
72
73
74
75
76
77
78
79
80
81
package entity
import (
"github.com/openflagr/flagr/swagger_gen/models"
"gorm.io/gorm"
)
// GenFixtureFlag is a fixture
func GenFixtureFlag() Flag {
f := Flag{
Model: gorm.Model{ID: 100},
Key: "flag_key_100",
Description: "",
Enabled: true,
Segments: []Segment{GenFixtureSegment()},
Variants: []Variant{
{
Model: gorm.Model{ID: 300},
FlagID: 100,
Key: "control",
},
{
Model: gorm.Model{ID: 301},
FlagID: 100,
Key: "treatment",
Attachment: map[string]interface{}{
"value": "321",
},
},
},
Tags: []Tag{
{
Value: "tag1",
},
{
Value: "tag2",
},
},
}
f.PrepareEvaluation()
return f
}
// GenFixtureSegment is a fixture
func GenFixtureSegment() Segment {
s := Segment{
Model: gorm.Model{ID: 200},
FlagID: 100,
Description: "",
Rank: 0,
RolloutPercent: 100,
Constraints: []Constraint{
{
Model: gorm.Model{ID: 500},
SegmentID: 200,
Property: "dl_state",
Operator: models.ConstraintOperatorEQ,
Value: `"CA"`,
},
},
Distributions: []Distribution{
{
Model: gorm.Model{ID: 400},
SegmentID: 200,
VariantID: 300,
VariantKey: "control",
Percent: 50,
},
{
Model: gorm.Model{ID: 401},
SegmentID: 200,
VariantID: 301,
VariantKey: "treatment",
Percent: 50,
},
},
}
s.PrepareEvaluation()
return s
}