-
Notifications
You must be signed in to change notification settings - Fork 204
/
simulation_views_v5.go
142 lines (112 loc) · 4.76 KB
/
simulation_views_v5.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
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
140
141
142
package v2
import (
"github.com/SpectoLabs/hoverfly/core/interfaces"
)
type SimulationViewV5 struct {
DataViewV5 `json:"data"`
MetaView `json:"meta"`
}
type DataViewV5 struct {
RequestResponsePairs []RequestMatcherResponsePairViewV5 `json:"pairs"`
GlobalActions GlobalActionsView `json:"globalActions"`
GlobalLiterals []GlobalLiteralViewV5 `json:"literals,omitempty"`
GlobalVariables []GlobalVariableViewV5 `json:"variables,omitempty"`
}
type RequestMatcherResponsePairViewV5 struct {
RequestMatcher RequestMatcherViewV5 `json:"request"`
Response ResponseDetailsViewV5 `json:"response"`
}
// RequestDetailsView is used when marshalling and unmarshalling RequestDetails
type RequestMatcherViewV5 struct {
Path []MatcherViewV5 `json:"path,omitempty"`
Method []MatcherViewV5 `json:"method,omitempty"`
Destination []MatcherViewV5 `json:"destination,omitempty"`
Scheme []MatcherViewV5 `json:"scheme,omitempty"`
Body []MatcherViewV5 `json:"body,omitempty"`
Headers map[string][]MatcherViewV5 `json:"headers,omitempty"`
Query *QueryMatcherViewV5 `json:"query,omitempty"`
RequiresState map[string]string `json:"requiresState,omitempty"`
}
type QueryMatcherViewV5 map[string][]MatcherViewV5
type MatcherViewV5 struct {
Matcher string `json:"matcher"`
Value interface{} `json:"value"`
Config map[string]interface{} `json:"config,omitempty"`
DoMatch *MatcherViewV5 `json:"doMatch,omitempty"`
}
type GlobalVariableViewV5 struct {
Name string `json:"name"`
Function string `json:"function"`
Arguments []interface{} `json:"arguments,omitempty"`
}
type GlobalLiteralViewV5 struct {
Name string `json:"name"`
Value interface{} `json:"value"`
}
func NewMatcherView(matcher string, value interface{}) MatcherViewV5 {
return MatcherViewV5{
Matcher: matcher,
Value: value,
}
}
// Gets Response - required for interfaces.RequestResponsePairView
func (this RequestMatcherResponsePairViewV5) GetResponse() interfaces.Response { return this.Response }
type ResponseDetailsViewV5 struct {
Status int `json:"status"`
Body string `json:"body"`
BodyFile string `json:"bodyFile,omitempty"`
EncodedBody bool `json:"encodedBody"`
Headers map[string][]string `json:"headers,omitempty"`
Templated bool `json:"templated"`
TransitionsState map[string]string `json:"transitionsState,omitempty"`
RemovesState []string `json:"removesState,omitempty"`
FixedDelay int `json:"fixedDelay,omitempty"`
LogNormalDelay *LogNormalDelayOptions `json:"logNormalDelay,omitempty"`
PostServeAction string `json:"postServeAction,omitempty"`
}
// Gets Status - required for interfaces.Response
func (this ResponseDetailsViewV5) GetStatus() int { return this.Status }
// Gets Body - required for interfaces.Response
func (this ResponseDetailsViewV5) GetBody() string { return this.Body }
// Gets BodyFile - required for interfaces.Response
func (this ResponseDetailsViewV5) GetBodyFile() string { return this.BodyFile }
// Gets EncodedBody - required for interfaces.Response
func (this ResponseDetailsViewV5) GetEncodedBody() bool { return this.EncodedBody }
func (this ResponseDetailsViewV5) GetTemplated() bool { return this.Templated }
func (this ResponseDetailsViewV5) GetTransitionsState() map[string]string {
return this.TransitionsState
}
func (this ResponseDetailsViewV5) GetRemovesState() []string { return this.RemovesState }
// Gets Headers - required for interfaces.Response
func (this ResponseDetailsViewV5) GetHeaders() map[string][]string { return this.Headers }
// Gets FixedDelay - required for interfaces.Response
func (this ResponseDetailsViewV5) GetFixedDelay() int { return this.FixedDelay }
// Gets LogNormalDelay - required for interfaces.Response
// The trick here to return nil with the right type to compare later.
func (this ResponseDetailsViewV5) GetLogNormalDelay() interfaces.ResponseDelay {
if this.LogNormalDelay != nil {
return this.LogNormalDelay
}
return nil
}
func (this ResponseDetailsViewV5) GetPostServeAction() string {
return this.PostServeAction
}
type LogNormalDelayOptions struct {
Min int `json:"min"`
Max int `json:"max"`
Mean int `json:"mean"`
Median int `json:"median"`
}
func (l *LogNormalDelayOptions) GetMin() int {
return l.Min
}
func (l *LogNormalDelayOptions) GetMax() int {
return l.Max
}
func (l *LogNormalDelayOptions) GetMean() int {
return l.Mean
}
func (l *LogNormalDelayOptions) GetMedian() int {
return l.Median
}