-
Notifications
You must be signed in to change notification settings - Fork 17
/
Capture.go
232 lines (195 loc) · 4.55 KB
/
Capture.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
package assertions
import (
_init_ "github.com/aws/aws-cdk-go/awscdk/v2/jsii"
_jsii_ "github.com/aws/jsii-runtime-go/runtime"
)
// Capture values while matching templates.
//
// Using an instance of this class within a Matcher will capture the matching value.
// The `as*()` APIs on the instance can be used to get the captured value.
//
// Example:
// // Given a template -
// // {
// // "Resources": {
// // "MyBar": {
// // "Type": "Foo::Bar",
// // "Properties": {
// // "Fred": "Flob",
// // }
// // },
// // "MyBaz": {
// // "Type": "Foo::Bar",
// // "Properties": {
// // "Fred": "Quib",
// // }
// // }
// // }
// // }
//
// fredCapture := awscdk.NewCapture()
// template.HasResourceProperties(jsii.String("Foo::Bar"), map[string]capture{
// "Fred": fredCapture,
// })
//
// fredCapture.AsString() // returns "Flob"
// fredCapture.Next() // returns true
// fredCapture.AsString()
//
type Capture interface {
Matcher
// A name for the matcher.
//
// This is collected as part of the result and may be presented to the user.
Name() *string
// Retrieve the captured value as an array.
//
// An error is generated if no value is captured or if the value is not an array.
AsArray() *[]interface{}
// Retrieve the captured value as a boolean.
//
// An error is generated if no value is captured or if the value is not a boolean.
AsBoolean() *bool
// Retrieve the captured value as a number.
//
// An error is generated if no value is captured or if the value is not a number.
AsNumber() *float64
// Retrieve the captured value as a JSON object.
//
// An error is generated if no value is captured or if the value is not an object.
AsObject() *map[string]interface{}
// Retrieve the captured value as a string.
//
// An error is generated if no value is captured or if the value is not a string.
AsString() *string
// When multiple results are captured, move the iterator to the next result.
//
// Returns: true if another capture is present, false otherwise.
Next() *bool
// Test whether a target matches the provided pattern.
//
// Every Matcher must implement this method.
// This method will be invoked by the assertions framework. Do not call this method directly.
Test(actual interface{}) MatchResult
}
// The jsii proxy struct for Capture
type jsiiProxy_Capture struct {
jsiiProxy_Matcher
}
func (j *jsiiProxy_Capture) Name() *string {
var returns *string
_jsii_.Get(
j,
"name",
&returns,
)
return returns
}
// Initialize a new capture.
func NewCapture(pattern interface{}) Capture {
_init_.Initialize()
j := jsiiProxy_Capture{}
_jsii_.Create(
"aws-cdk-lib.assertions.Capture",
[]interface{}{pattern},
&j,
)
return &j
}
// Initialize a new capture.
func NewCapture_Override(c Capture, pattern interface{}) {
_init_.Initialize()
_jsii_.Create(
"aws-cdk-lib.assertions.Capture",
[]interface{}{pattern},
c,
)
}
// Check whether the provided object is a subtype of the `IMatcher`.
func Capture_IsMatcher(x interface{}) *bool {
_init_.Initialize()
if err := validateCapture_IsMatcherParameters(x); err != nil {
panic(err)
}
var returns *bool
_jsii_.StaticInvoke(
"aws-cdk-lib.assertions.Capture",
"isMatcher",
[]interface{}{x},
&returns,
)
return returns
}
func (c *jsiiProxy_Capture) AsArray() *[]interface{} {
var returns *[]interface{}
_jsii_.Invoke(
c,
"asArray",
nil, // no parameters
&returns,
)
return returns
}
func (c *jsiiProxy_Capture) AsBoolean() *bool {
var returns *bool
_jsii_.Invoke(
c,
"asBoolean",
nil, // no parameters
&returns,
)
return returns
}
func (c *jsiiProxy_Capture) AsNumber() *float64 {
var returns *float64
_jsii_.Invoke(
c,
"asNumber",
nil, // no parameters
&returns,
)
return returns
}
func (c *jsiiProxy_Capture) AsObject() *map[string]interface{} {
var returns *map[string]interface{}
_jsii_.Invoke(
c,
"asObject",
nil, // no parameters
&returns,
)
return returns
}
func (c *jsiiProxy_Capture) AsString() *string {
var returns *string
_jsii_.Invoke(
c,
"asString",
nil, // no parameters
&returns,
)
return returns
}
func (c *jsiiProxy_Capture) Next() *bool {
var returns *bool
_jsii_.Invoke(
c,
"next",
nil, // no parameters
&returns,
)
return returns
}
func (c *jsiiProxy_Capture) Test(actual interface{}) MatchResult {
if err := c.validateTestParameters(actual); err != nil {
panic(err)
}
var returns MatchResult
_jsii_.Invoke(
c,
"test",
[]interface{}{actual},
&returns,
)
return returns
}