@@ -19,6 +19,7 @@ import (
19
19
20
20
"github.com/aws-controllers-k8s/runtime/pkg/compare"
21
21
"github.com/aws/aws-sdk-go/aws"
22
+ "github.com/stretchr/testify/require"
22
23
23
24
"github.com/aws-controllers-k8s/dynamodb-controller/apis/v1alpha1"
24
25
)
@@ -147,6 +148,124 @@ func Test_customPreCompare(t *testing.T) {
147
148
t .Errorf ("b.Spec.ProvisionedThroughput should be nil, but got %+v" , a .ko .Spec .ProvisionedThroughput )
148
149
}
149
150
})
151
+
152
+ t .Run ("GSI ProvisionedThroughput should be equal when nil and 0 capacity" , func (t * testing.T ) {
153
+ a := & resource {ko : & v1alpha1.Table {
154
+ Spec : v1alpha1.TableSpec {
155
+ BillingMode : aws .String (string (v1alpha1 .BillingMode_PAY_PER_REQUEST )),
156
+ ProvisionedThroughput : & v1alpha1.ProvisionedThroughput {},
157
+ GlobalSecondaryIndexes : []* v1alpha1.GlobalSecondaryIndex {
158
+ {
159
+ IndexName : aws .String ("index1" ),
160
+ KeySchema : []* v1alpha1.KeySchemaElement {
161
+ {
162
+ AttributeName : aws .String ("id" ),
163
+ KeyType : aws .String ("HASH" ),
164
+ },
165
+ {
166
+ AttributeName : aws .String ("email" ),
167
+ KeyType : aws .String ("RANGE" ),
168
+ },
169
+ },
170
+ Projection : & v1alpha1.Projection {
171
+ ProjectionType : aws .String ("ALL" ),
172
+ },
173
+ ProvisionedThroughput : nil ,
174
+ },
175
+ },
176
+ },
177
+ }}
178
+
179
+ b := & resource {ko : & v1alpha1.Table {
180
+ Spec : v1alpha1.TableSpec {
181
+ BillingMode : aws .String (string (v1alpha1 .BillingMode_PAY_PER_REQUEST )),
182
+ ProvisionedThroughput : & v1alpha1.ProvisionedThroughput {},
183
+ GlobalSecondaryIndexes : []* v1alpha1.GlobalSecondaryIndex {
184
+ {
185
+ IndexName : aws .String ("index1" ),
186
+ KeySchema : []* v1alpha1.KeySchemaElement {
187
+ {
188
+ AttributeName : aws .String ("id" ),
189
+ KeyType : aws .String ("HASH" ),
190
+ },
191
+ {
192
+ AttributeName : aws .String ("email" ),
193
+ KeyType : aws .String ("RANGE" ),
194
+ },
195
+ },
196
+ Projection : & v1alpha1.Projection {
197
+ ProjectionType : aws .String ("ALL" ),
198
+ },
199
+ ProvisionedThroughput : & v1alpha1.ProvisionedThroughput {
200
+ ReadCapacityUnits : aws .Int64 (0 ),
201
+ WriteCapacityUnits : aws .Int64 (0 ),
202
+ },
203
+ },
204
+ },
205
+ },
206
+ }}
207
+ delta := & compare.Delta {}
208
+ customPreCompare (delta , a , b )
209
+ require .False (t , delta .DifferentAt ("Spec.GlobalSecondaryIndexes" ))
210
+
211
+ // the following case should not happen, just in case
212
+ c := & resource {ko : & v1alpha1.Table {
213
+ Spec : v1alpha1.TableSpec {
214
+ BillingMode : aws .String (string (v1alpha1 .BillingMode_PAY_PER_REQUEST )),
215
+ ProvisionedThroughput : & v1alpha1.ProvisionedThroughput {},
216
+ GlobalSecondaryIndexes : []* v1alpha1.GlobalSecondaryIndex {
217
+ {
218
+ IndexName : aws .String ("index1" ),
219
+ KeySchema : []* v1alpha1.KeySchemaElement {
220
+ {
221
+ AttributeName : aws .String ("id" ),
222
+ KeyType : aws .String ("HASH" ),
223
+ },
224
+ {
225
+ AttributeName : aws .String ("email" ),
226
+ KeyType : aws .String ("RANGE" ),
227
+ },
228
+ },
229
+ Projection : & v1alpha1.Projection {
230
+ ProjectionType : aws .String ("ALL" ),
231
+ },
232
+ ProvisionedThroughput : nil ,
233
+ },
234
+ },
235
+ },
236
+ }}
237
+
238
+ d := & resource {ko : & v1alpha1.Table {
239
+ Spec : v1alpha1.TableSpec {
240
+ BillingMode : aws .String (string (v1alpha1 .BillingMode_PAY_PER_REQUEST )),
241
+ ProvisionedThroughput : & v1alpha1.ProvisionedThroughput {},
242
+ GlobalSecondaryIndexes : []* v1alpha1.GlobalSecondaryIndex {
243
+ {
244
+ IndexName : aws .String ("index1" ),
245
+ KeySchema : []* v1alpha1.KeySchemaElement {
246
+ {
247
+ AttributeName : aws .String ("id" ),
248
+ KeyType : aws .String ("HASH" ),
249
+ },
250
+ {
251
+ AttributeName : aws .String ("email" ),
252
+ KeyType : aws .String ("RANGE" ),
253
+ },
254
+ },
255
+ Projection : & v1alpha1.Projection {
256
+ ProjectionType : aws .String ("ALL" ),
257
+ },
258
+ ProvisionedThroughput : & v1alpha1.ProvisionedThroughput {
259
+ ReadCapacityUnits : aws .Int64 (0 ),
260
+ WriteCapacityUnits : aws .Int64 (0 ),
261
+ },
262
+ },
263
+ },
264
+ },
265
+ }}
266
+ customPreCompare (delta , c , d )
267
+ require .False (t , delta .DifferentAt ("Spec.GlobalSecondaryIndexes" ))
268
+ })
150
269
}
151
270
152
271
func Test_newResourceDelta_customDeltaFunction_AttributeDefinitions (t * testing.T ) {
0 commit comments