Skip to content

Commit 04f1657

Browse files
committed
remove ginkgo T usage
1 parent 9fbf3e7 commit 04f1657

File tree

7 files changed

+26
-77
lines changed

7 files changed

+26
-77
lines changed

test/e2e/atlas_gov_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ var _ = Describe("Atlas for Government", Label("atlas-gov"), func() {
5858
By("Setting up cloud environment", func() {
5959
checkUpAWSEnvironment()
6060

61-
aws, err := cloud.NewAWSAction(ctx, GinkgoT())
61+
aws, err := cloud.NewAWSAction(ctx)
6262
Expect(err).ToNot(HaveOccurred())
6363
awsHelper = aws
6464
})

test/e2e/backup_config_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func backupConfigFlow(data *model.TestDataProvider, bucket string) {
222222

223223
func setupAWSResource(ctx context.Context, gen *helper.AwsResourcesGenerator, bucket, bucketPolicy, role string) {
224224
Expect(gen.CreateBucket(ctx, bucket)).To(Succeed())
225-
gen.Cleanup(func() {
225+
DeferCleanup(func(ctx SpecContext) {
226226
Expect(gen.EmptyBucket(ctx, bucket)).To(Succeed())
227227
Expect(gen.DeleteBucket(ctx, bucket)).To(Succeed())
228228
})
@@ -232,12 +232,12 @@ func setupAWSResource(ctx context.Context, gen *helper.AwsResourcesGenerator, bu
232232
})
233233
Expect(err).Should(BeNil())
234234
Expect(policyArn).ShouldNot(BeEmpty())
235-
gen.Cleanup(func() {
235+
DeferCleanup(func(ctx SpecContext) {
236236
Expect(gen.DeletePolicy(ctx, policyArn)).To(Succeed())
237237
})
238238

239239
Expect(gen.AttachRolePolicy(ctx, role, policyArn)).To(Succeed())
240-
gen.Cleanup(func() {
240+
DeferCleanup(func(ctx SpecContext) {
241241
Expect(gen.DetachRolePolicy(ctx, role, policyArn)).To(Succeed())
242242
})
243243
}

test/e2e/encryption_at_rest_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func fillKMSforAWS(ctx context.Context, userData *model.TestDataProvider, encAtR
198198
alias := fmt.Sprintf("%s-kms", userData.Project.Spec.Name)
199199

200200
Expect(encAtRest.AwsKms.Region).NotTo(Equal(""))
201-
awsAction, err := cloud.NewAWSAction(ctx, GinkgoT())
201+
awsAction, err := cloud.NewAWSAction(ctx)
202202
Expect(err).ToNot(HaveOccurred())
203203
CustomerMasterKeyID, err := awsAction.CreateKMS(ctx, alias, config.AWSRegionUS, atlasAccountArn, assumedRoleArn)
204204
Expect(err).ToNot(HaveOccurred())

test/e2e/private_link_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ func getPrivateLinkName(privateEndpointID string, providerName provider.Provider
287287
func prepareProviderAction(ctx context.Context) (*cloud.ProviderAction, error) {
288288
t := GinkgoT()
289289

290-
aws, err := cloud.NewAWSAction(ctx, t)
290+
aws, err := cloud.NewAWSAction(ctx)
291291
if err != nil {
292292
return nil, err
293293
}

test/helper/e2e/actions/cloud/aws.go

Lines changed: 19 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ import (
3131
kmstypes "github.com/aws/aws-sdk-go-v2/service/kms/types"
3232
"github.com/aws/aws-sdk-go-v2/service/sts"
3333
"github.com/aws/smithy-go"
34-
"github.com/onsi/ginkgo/v2/dsl/core"
34+
. "github.com/onsi/ginkgo/v2"
35+
. "github.com/onsi/gomega"
3536

3637
"github.com/mongodb/mongodb-atlas-kubernetes/v2/internal/pointer"
3738
awshelper "github.com/mongodb/mongodb-atlas-kubernetes/v2/test/helper/e2e/api/aws"
3839
)
3940

4041
type AwsAction struct {
41-
t core.GinkgoTInterface
4242
network *awsNetwork
4343

4444
cfg aws.Config
@@ -67,8 +67,6 @@ type statement struct {
6767
}
6868

6969
func (a *AwsAction) CreateKMS(ctx context.Context, alias, region, atlasAccountArn, assumedRoleArn string) (string, error) {
70-
a.t.Helper()
71-
7270
//kmsClient := kms.New(a.session, aws.NewConfig().WithRegion(region))
7371
kmsClient := kms.NewFromConfig(a.cfg, func(o *kms.Options) {
7472
o.Region = region
@@ -109,18 +107,14 @@ func (a *AwsAction) CreateKMS(ctx context.Context, alias, region, atlasAccountAr
109107
TargetKeyId: key.KeyMetadata.KeyId,
110108
})
111109

112-
if err != nil {
113-
a.t.Log(fmt.Sprintf("failed to create alias to key %s(%s): %s", alias, *key.KeyMetadata.KeyId, err))
114-
}
110+
Expect(err).NotTo(HaveOccurred())
115111

116-
a.t.Cleanup(func() {
112+
DeferCleanup(func(ctx SpecContext) error {
117113
_, err = kmsClient.ScheduleKeyDeletion(ctx, &kms.ScheduleKeyDeletionInput{
118114
KeyId: key.KeyMetadata.KeyId,
119115
PendingWindowInDays: aws.Int32(7), // this is the minimum possible and can be up to 24h longer than value set
120116
})
121-
if err != nil {
122-
a.t.Error(err)
123-
}
117+
return err
124118
})
125119

126120
return *key.KeyMetadata.KeyId, nil
@@ -206,8 +200,6 @@ func defaultKMSPolicy(atlasAccountArn, assumedRoleArn string, adminARNs []string
206200
}
207201

208202
func (a *AwsAction) GetAccountID(ctx context.Context) (string, error) {
209-
a.t.Helper()
210-
211203
stsClient := sts.NewFromConfig(a.cfg)
212204
identity, err := stsClient.GetCallerIdentity(ctx, &sts.GetCallerIdentityInput{})
213205
if err != nil {
@@ -218,8 +210,6 @@ func (a *AwsAction) GetAccountID(ctx context.Context) (string, error) {
218210
}
219211

220212
func (a *AwsAction) InitNetwork(ctx context.Context, vpcName, cidr, region string, subnets map[string]string, cleanup bool) (string, error) {
221-
a.t.Helper()
222-
223213
vpc, err := a.findVPC(ctx, vpcName, region)
224214
if err != nil {
225215
return "", err
@@ -233,11 +223,8 @@ func (a *AwsAction) InitNetwork(ctx context.Context, vpcName, cidr, region strin
233223
}
234224

235225
if cleanup {
236-
a.t.Cleanup(func() {
237-
err = a.deleteVPC(ctx, vpc, region)
238-
if err != nil {
239-
a.t.Error(err)
240-
}
226+
DeferCleanup(func(ctx SpecContext) error {
227+
return a.deleteVPC(ctx, vpc, region)
241228
})
242229
}
243230

@@ -259,11 +246,8 @@ func (a *AwsAction) InitNetwork(ctx context.Context, vpcName, cidr, region strin
259246
}
260247

261248
if cleanup {
262-
a.t.Cleanup(func() {
263-
err = a.deleteSubnet(ctx, subnetID, region)
264-
if err != nil {
265-
a.t.Error(err)
266-
}
249+
DeferCleanup(func(ctx SpecContext) error {
250+
return a.deleteSubnet(ctx, subnetID, region)
267251
})
268252
}
269253
}
@@ -281,8 +265,6 @@ func (a *AwsAction) InitNetwork(ctx context.Context, vpcName, cidr, region strin
281265
}
282266

283267
func (a *AwsAction) CreatePrivateEndpoint(ctx context.Context, serviceName, privateEndpointName, region string) (string, error) {
284-
a.t.Helper()
285-
286268
ec2Client := ec2.NewFromConfig(a.cfg, func(o *ec2.Options) {
287269
o.Region = region
288270
})
@@ -305,19 +287,19 @@ func (a *AwsAction) CreatePrivateEndpoint(ctx context.Context, serviceName, priv
305287
}
306288
vpcEndpointId := aws.ToString(result.VpcEndpoint.VpcEndpointId)
307289

308-
a.t.Cleanup(func() {
290+
DeferCleanup(func(ctx SpecContext) error {
309291
deleteInput := &ec2.DeleteVpcEndpointsInput{
310292
VpcEndpointIds: []string{vpcEndpointId},
311293
}
312294
_, err = ec2Client.DeleteVpcEndpoints(ctx, deleteInput)
313295
if err != nil {
314-
a.t.Error(err)
296+
return err
315297
}
316298

317299
timeout := 10 * time.Minute
318300
start := time.Now()
319301
for {
320-
a.t.Log(fmt.Sprintf("deleting VPC ID %q since %v", vpcEndpointId, time.Since(start)))
302+
fmt.Fprintf(GinkgoWriter, "deleting VPC ID %q since %v\n", vpcEndpointId, time.Since(start))
321303

322304
output, err := ec2Client.DescribeVpcEndpoints(ctx, &ec2.DescribeVpcEndpointsInput{
323305
VpcEndpointIds: []string{vpcEndpointId},
@@ -326,20 +308,17 @@ func (a *AwsAction) CreatePrivateEndpoint(ctx context.Context, serviceName, priv
326308
if err != nil {
327309
var apiErr *smithy.GenericAPIError
328310
if errors.As(err, &apiErr) && apiErr.Code == "InvalidVpcEndpointId.NotFound" {
329-
return
311+
return nil
330312
}
331-
332-
a.t.Error(err)
333-
return
313+
return err
334314
}
335315

336316
if len(output.VpcEndpoints) == 0 {
337-
return
317+
return nil
338318
}
339319

340320
if time.Since(start) > timeout {
341-
a.t.Error(errors.New("timeout waiting for deletion of vpc endpoints"))
342-
return
321+
return errors.New("timeout waiting for deletion of vpc endpoints")
343322
}
344323

345324
// we do know that deletion of VPC endpoints takes time
@@ -351,8 +330,6 @@ func (a *AwsAction) CreatePrivateEndpoint(ctx context.Context, serviceName, priv
351330
}
352331

353332
func (a *AwsAction) GetPrivateEndpoint(ctx context.Context, endpointID, region string) (ec2types.VpcEndpoint, error) {
354-
a.t.Helper()
355-
356333
ec2Client := ec2.NewFromConfig(a.cfg, func(o *ec2.Options) {
357334
o.Region = region
358335
})
@@ -370,8 +347,6 @@ func (a *AwsAction) GetPrivateEndpoint(ctx context.Context, endpointID, region s
370347
}
371348

372349
func (a *AwsAction) AcceptVpcPeeringConnection(ctx context.Context, connectionID, region string) error {
373-
a.t.Helper()
374-
375350
ec2Client := ec2.NewFromConfig(a.cfg, func(o *ec2.Options) {
376351
o.Region = region
377352
})
@@ -383,24 +358,20 @@ func (a *AwsAction) AcceptVpcPeeringConnection(ctx context.Context, connectionID
383358
},
384359
)
385360

386-
a.t.Cleanup(func() {
361+
DeferCleanup(func(ctx SpecContext) error {
387362
_, err = ec2Client.DeleteVpcPeeringConnection(
388363
ctx,
389364
&ec2.DeleteVpcPeeringConnectionInput{
390365
VpcPeeringConnectionId: aws.String(connectionID),
391366
},
392367
)
393-
if err != nil {
394-
a.t.Error(err)
395-
}
368+
return err
396369
})
397370

398371
return err
399372
}
400373

401374
func (a *AwsAction) findVPC(ctx context.Context, name, region string) (string, error) {
402-
a.t.Helper()
403-
404375
ec2Client := ec2.NewFromConfig(a.cfg, func(o *ec2.Options) {
405376
o.Region = region
406377
})
@@ -424,8 +395,6 @@ func (a *AwsAction) findVPC(ctx context.Context, name, region string) (string, e
424395
}
425396

426397
func (a *AwsAction) createVPC(ctx context.Context, name, cidr, region string) (string, error) {
427-
a.t.Helper()
428-
429398
ec2Client := ec2.NewFromConfig(a.cfg, func(o *ec2.Options) {
430399
o.Region = region
431400
})
@@ -464,8 +433,6 @@ func (a *AwsAction) createVPC(ctx context.Context, name, cidr, region string) (s
464433
}
465434

466435
func (a *AwsAction) deleteVPC(ctx context.Context, id, region string) error {
467-
a.t.Helper()
468-
469436
ec2Client := ec2.NewFromConfig(a.cfg, func(o *ec2.Options) {
470437
o.Region = region
471438
})
@@ -481,8 +448,6 @@ func (a *AwsAction) deleteVPC(ctx context.Context, id, region string) error {
481448
}
482449

483450
func (a *AwsAction) getSubnets(ctx context.Context, vpcID, region string) (map[string]string, error) {
484-
a.t.Helper()
485-
486451
ec2Client := ec2.NewFromConfig(a.cfg, func(o *ec2.Options) {
487452
o.Region = region
488453
})
@@ -511,8 +476,6 @@ func (a *AwsAction) getSubnets(ctx context.Context, vpcID, region string) (map[s
511476
}
512477

513478
func (a *AwsAction) createSubnet(ctx context.Context, vpcID, name, cidr, region, az string) (string, error) {
514-
a.t.Helper()
515-
516479
ec2Client := ec2.NewFromConfig(a.cfg, func(o *ec2.Options) {
517480
o.Region = region
518481
})
@@ -541,8 +504,6 @@ func (a *AwsAction) createSubnet(ctx context.Context, vpcID, name, cidr, region,
541504
}
542505

543506
func (a *AwsAction) deleteSubnet(ctx context.Context, subnetID string, region string) error {
544-
a.t.Helper()
545-
546507
ec2Client := ec2.NewFromConfig(a.cfg, func(o *ec2.Options) {
547508
o.Region = region
548509
})
@@ -558,16 +519,12 @@ func (a *AwsAction) deleteSubnet(ctx context.Context, subnetID string, region st
558519
return nil
559520
}
560521

561-
func NewAWSAction(ctx context.Context, t core.GinkgoTInterface) (*AwsAction, error) {
562-
t.Helper()
563-
522+
func NewAWSAction(ctx context.Context) (*AwsAction, error) {
564523
cfg, err := config.LoadDefaultConfig(ctx)
565524
if err != nil {
566525
return nil, err
567526
}
568527
return &AwsAction{
569-
t: t,
570-
571528
cfg: cfg,
572529
}, nil
573530
}

test/helper/e2e/actions/project_flow.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func CreateProjectWithCloudProviderAccess(ctx context.Context, testData *model.T
108108
Expect(err).Should(BeNil())
109109
Expect(roleArn).ShouldNot(BeEmpty())
110110

111-
testData.AWSResourcesGenerator.Cleanup(func() {
111+
DeferCleanup(func(ctx SpecContext) {
112112
Expect(testData.AWSResourcesGenerator.DeleteIAMRole(ctx, atlasIAMRoleName)).To(Succeed())
113113
})
114114

test/helper/e2e/api/aws/aws_resources_generator.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ import (
2929
)
3030

3131
type AwsResourcesGenerator struct {
32-
t ginkgo.GinkgoTInterface
33-
3432
iamClient *iam.Client
3533
s3Client *s3.Client
3634
}
@@ -55,8 +53,6 @@ func NewAwsResourcesGenerator(ctx context.Context, t ginkgo.GinkgoTInterface, re
5553
}
5654

5755
return &AwsResourcesGenerator{
58-
t: t,
59-
6056
iamClient: iam.NewFromConfig(cfg),
6157
s3Client: s3.NewFromConfig(cfg),
6258
}
@@ -273,10 +269,6 @@ func (g *AwsResourcesGenerator) DeleteObject(ctx context.Context, bucketName, ob
273269
return nil
274270
}
275271

276-
func (g *AwsResourcesGenerator) Cleanup(task func()) {
277-
g.t.Cleanup(task)
278-
}
279-
280272
func CloudProviderAccessPolicy(atlasAWSAccountArn, atlasAssumedRoleExternalID string) IAMPolicy {
281273
policy := `{
282274
"Version":"2012-10-17",

0 commit comments

Comments
 (0)