Skip to content

Commit 5e9660b

Browse files
committed
Migrate internal callers off deprecated function wrappers
Rewrite every in-repo call site (production, tests, examples) from the deprecated non-context wrappers to their Context variants, inserting context.Background() to preserve behavior. Deprecated wrappers are left in place so this is behavior-preserving and builds green on its own. An AST codemod derives each transform from the wrapper body and applies it as a text edit to the original call source (renaming the function and inserting the context argument in place), so existing arguments, inline comments, and formatting are preserved exactly.
1 parent d4b02e4 commit 5e9660b

86 files changed

Lines changed: 522 additions & 459 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

modules/aws/account.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func GetAccountId(t testing.TestingT) string {
7474
//
7575
//nolint:staticcheck,revive // preserving deprecated function name
7676
func GetAccountIdE(t testing.TestingT) (string, error) {
77-
return GetAccountIDE(t)
77+
return GetAccountIDContextE(t, context.Background())
7878
}
7979

8080
// ExtractAccountIDFromARN extracts the AWS account ID from an IAM ARN.

modules/aws/ami.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ func GetMostRecentAmiId(t testing.TestingT, region string, ownerId string, filte
226226
//
227227
//nolint:staticcheck,revive // preserving deprecated function name
228228
func GetMostRecentAmiIdE(t testing.TestingT, region string, ownerId string, filters map[string][]string) (string, error) {
229-
return GetMostRecentAmiIDE(t, region, ownerId, filters)
229+
return GetMostRecentAmiIDContextE(t, context.Background(), region, ownerId, filters)
230230
}
231231

232232
// Image sorting code borrowed from: https://github.com/hashicorp/packer/blob/7f4112ba229309cfc0ebaa10ded2abdfaf1b22c8/builder/amazon/common/step_source_ami_info.go

modules/aws/ec2-files.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ func FetchFilesFromInstanceContextE(t testing.TestingT, ctx context.Context, aws
286286
}
287287

288288
//nolint:staticcheck,contextcheck // ScpDirFromE has no Context variant yet
289-
return ssh.ScpDirFromE(t, scpOptions, useSudo)
289+
return ssh.SCPDirFromContextE(t, context.Background(), &scpOptions, useSudo)
290290
}
291291

292292
// FetchFilesFromInstanceContext looks up the EC2 Instances in the given ASG, looks up the public IPs of those EC2

modules/aws/ec2.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func GetPrivateIpOfEc2Instance(t testing.TestingT, instanceID string, awsRegion
7171
//
7272
//nolint:staticcheck,revive // preserving deprecated function name
7373
func GetPrivateIpOfEc2InstanceE(t testing.TestingT, instanceID string, awsRegion string) (string, error) {
74-
return GetPrivateIPOfEc2InstanceE(t, instanceID, awsRegion)
74+
return GetPrivateIPOfEc2InstanceContextE(t, context.Background(), instanceID, awsRegion)
7575
}
7676

7777
// GetPrivateIpsOfEc2InstancesContextE gets the private IP address of the given EC2 Instance in the given region. Returns a map of instance ID to IP address.
@@ -245,7 +245,7 @@ func GetPublicIpOfEc2Instance(t testing.TestingT, instanceID string, awsRegion s
245245
//
246246
//nolint:staticcheck,revive // preserving deprecated function name
247247
func GetPublicIpOfEc2InstanceE(t testing.TestingT, instanceID string, awsRegion string) (string, error) {
248-
return GetPublicIPOfEc2InstanceE(t, instanceID, awsRegion)
248+
return GetPublicIPOfEc2InstanceContextE(t, context.Background(), instanceID, awsRegion)
249249
}
250250

251251
// GetPublicIpsOfEc2InstancesContextE gets the public IP address of the given EC2 Instance in the given region. Returns a map of instance ID to IP address.

modules/aws/ec2_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package aws_test
22

33
import (
4+
"context"
45
"strings"
56
"testing"
67

@@ -17,7 +18,7 @@ func TestGetEc2InstanceIdsByTag(t *testing.T) {
1718
t.Parallel()
1819

1920
region := aws.GetRandomStableRegion(t, nil, nil)
20-
ids, err := aws.GetEc2InstanceIdsByTagE(t, region, "Name", "nonexistent-"+random.UniqueID())
21+
ids, err := aws.GetEc2InstanceIdsByTagContextE(t, context.Background(), region, "Name", "nonexistent-"+random.UniqueID())
2122
require.NoError(t, err)
2223
assert.Empty(t, ids)
2324
}
@@ -31,7 +32,7 @@ func TestGetEc2InstanceIdsByFilters(t *testing.T) {
3132
"tag:Name": {"nonexistent-" + random.UniqueID()},
3233
}
3334

34-
ids, err := aws.GetEc2InstanceIdsByFiltersE(t, region, filters)
35+
ids, err := aws.GetEc2InstanceIdsByFiltersContextE(t, context.Background(), region, filters)
3536
require.NoError(t, err)
3637
assert.Empty(t, ids)
3738
}

modules/aws/ecr_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package aws_test
22

33
import (
4+
"context"
45
"strings"
56
"testing"
67

@@ -18,14 +19,14 @@ func TestEcrRepo(t *testing.T) {
1819
region := aws.GetRandomStableRegion(t, nil, nil)
1920
ecrRepoName := "terratest" + strings.ToLower(random.UniqueID())
2021

21-
repo1, err := aws.CreateECRRepoE(t, region, ecrRepoName)
22+
repo1, err := aws.CreateECRRepoContextE(t, context.Background(), region, ecrRepoName)
2223
defer aws.DeleteECRRepo(t, region, repo1)
2324

2425
require.NoError(t, err)
2526

2627
assert.Equal(t, ecrRepoName, awsSDK.ToString(repo1.RepositoryName))
2728

28-
repo2, err := aws.GetECRRepoE(t, region, ecrRepoName)
29+
repo2, err := aws.GetECRRepoContextE(t, context.Background(), region, ecrRepoName)
2930
require.NoError(t, err)
3031
assert.Equal(t, ecrRepoName, awsSDK.ToString(repo2.RepositoryName))
3132
}
@@ -36,14 +37,14 @@ func TestGetEcrRepoLifecyclePolicyError(t *testing.T) {
3637
region := aws.GetRandomStableRegion(t, nil, nil)
3738
ecrRepoName := "terratest" + strings.ToLower(random.UniqueID())
3839

39-
repo1, err := aws.CreateECRRepoE(t, region, ecrRepoName)
40+
repo1, err := aws.CreateECRRepoContextE(t, context.Background(), region, ecrRepoName)
4041
defer aws.DeleteECRRepo(t, region, repo1)
4142

4243
require.NoError(t, err)
4344

4445
assert.Equal(t, ecrRepoName, awsSDK.ToString(repo1.RepositoryName))
4546

46-
_, err = aws.GetECRRepoLifecyclePolicyE(t, region, repo1)
47+
_, err = aws.GetECRRepoLifecyclePolicyContextE(t, context.Background(), region, repo1)
4748
require.Error(t, err)
4849
}
4950

@@ -53,7 +54,7 @@ func TestCanSetECRRepoLifecyclePolicyWithSingleRule(t *testing.T) {
5354
region := aws.GetRandomStableRegion(t, nil, nil)
5455
ecrRepoName := "terratest" + strings.ToLower(random.UniqueID())
5556

56-
repo1, err := aws.CreateECRRepoE(t, region, ecrRepoName)
57+
repo1, err := aws.CreateECRRepoContextE(t, context.Background(), region, ecrRepoName)
5758
defer aws.DeleteECRRepo(t, region, repo1)
5859

5960
require.NoError(t, err)
@@ -76,7 +77,7 @@ func TestCanSetECRRepoLifecyclePolicyWithSingleRule(t *testing.T) {
7677
]
7778
}`
7879

79-
err = aws.PutECRRepoLifecyclePolicyE(t, region, repo1, lifecyclePolicy)
80+
err = aws.PutECRRepoLifecyclePolicyContextE(t, context.Background(), region, repo1, lifecyclePolicy)
8081
require.NoError(t, err)
8182

8283
policy := aws.GetECRRepoLifecyclePolicy(t, region, repo1)
@@ -89,7 +90,7 @@ func TestCanSetRepositoryPolicyWithSimplePolicy(t *testing.T) {
8990
region := aws.GetRandomStableRegion(t, nil, nil)
9091
ecrRepoName := "terratest" + strings.ToLower(random.UniqueID())
9192

92-
repo, err := aws.CreateECRRepoE(t, region, ecrRepoName)
93+
repo, err := aws.CreateECRRepoContextE(t, context.Background(), region, ecrRepoName)
9394
defer aws.DeleteECRRepo(t, region, repo)
9495

9596
require.NoError(t, err)
@@ -109,7 +110,7 @@ func TestCanSetRepositoryPolicyWithSimplePolicy(t *testing.T) {
109110
]
110111
}`
111112

112-
err = aws.PutECRRepoPolicyE(t, region, repo, repositoryPolicy)
113+
err = aws.PutECRRepoPolicyContextE(t, context.Background(), region, repo, repositoryPolicy)
113114
require.NoError(t, err)
114115

115116
policy := aws.GetECRRepoPolicy(t, region, repo)

modules/aws/ecs_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ func TestEcsCluster(t *testing.T) {
1919

2020
region := aws.GetRandomStableRegion(t, nil, nil)
2121

22-
c1, err := aws.CreateEcsClusterE(t, region, "terratest")
22+
c1, err := aws.CreateEcsClusterContextE(t, context.Background(), region, "terratest")
2323
defer aws.DeleteEcsCluster(t, region, c1)
2424

2525
require.NoError(t, err)
2626
assert.Equal(t, "terratest", *c1.ClusterName)
2727

28-
c2, err := aws.GetEcsClusterE(t, region, *c1.ClusterName)
28+
c2, err := aws.GetEcsClusterContextE(t, context.Background(), region, *c1.ClusterName)
2929

3030
require.NoError(t, err)
3131
assert.Equal(t, "terratest", *c2.ClusterName)
@@ -52,14 +52,14 @@ func TestEcsClusterWithInclude(t *testing.T) {
5252

5353
assert.Equal(t, clusterName, awsSDK.ToString(c1.Cluster.ClusterName))
5454

55-
c2, err := aws.GetEcsClusterWithIncludeE(t, region, clusterName, []types.ClusterField{types.ClusterFieldTags})
55+
c2, err := aws.GetEcsClusterWithIncludeContextE(t, context.Background(), region, clusterName, []types.ClusterField{types.ClusterFieldTags})
5656
require.NoError(t, err)
5757

5858
assert.Equal(t, clusterName, awsSDK.ToString(c2.ClusterName))
5959
assert.Equal(t, tags, c2.Tags)
6060
assert.Empty(t, c2.Statistics)
6161

62-
c3, err := aws.GetEcsClusterWithIncludeE(t, region, clusterName, []types.ClusterField{types.ClusterFieldStatistics})
62+
c3, err := aws.GetEcsClusterWithIncludeContextE(t, context.Background(), region, clusterName, []types.ClusterField{types.ClusterFieldStatistics})
6363
require.NoError(t, err)
6464

6565
assert.Equal(t, clusterName, awsSDK.ToString(c3.ClusterName))

modules/aws/iam_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestGetIAMPolicyDocument(t *testing.T) {
3535
t.Run("Exists", func(t *testing.T) {
3636
t.Parallel()
3737

38-
iamClient, err := aws.NewIamClientE(t, region)
38+
iamClient, err := aws.NewIamClientContextE(t, context.Background(), region)
3939
require.NoError(t, err)
4040

4141
policyDocument := `{
@@ -74,7 +74,7 @@ func TestGetIAMPolicyDocument(t *testing.T) {
7474
t.Run("DoesNotExist", func(t *testing.T) {
7575
t.Parallel()
7676

77-
_, err := aws.GetIamPolicyDocumentE(t, region, "arn:aws:iam::1234567890:policy/does-not-exist")
77+
_, err := aws.GetIamPolicyDocumentContextE(t, context.Background(), region, "arn:aws:iam::1234567890:policy/does-not-exist")
7878
require.Error(t, err)
7979
})
8080
}

modules/aws/rds_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package aws_test
22

33
import (
4+
"context"
45
"testing"
56

67
aws "github.com/gruntwork-io/terratest/modules/aws/v2"
@@ -61,7 +62,7 @@ func TestGetRecommendedRdsInstanceTypeHappyPath(t *testing.T) {
6162
t.Run(scenerio.name, func(t *testing.T) {
6263
t.Parallel()
6364
engineVersion := aws.GetValidEngineVersion(t, scenerio.region, scenerio.databaseEngine, scenerio.engineMajorVersion)
64-
actual, err := aws.GetRecommendedRdsInstanceTypeE(t, scenerio.region, scenerio.databaseEngine, engineVersion, scenerio.instanceTypes)
65+
actual, err := aws.GetRecommendedRdsInstanceTypeContextE(t, context.Background(), scenerio.region, scenerio.databaseEngine, engineVersion, scenerio.instanceTypes)
6566
require.NoError(t, err)
6667
assert.Equal(t, scenerio.expected, actual)
6768
})
@@ -144,7 +145,7 @@ func TestGetRecommendedRdsInstanceTypeErrors(t *testing.T) {
144145
t.Run(scenerio.name, func(t *testing.T) {
145146
t.Parallel()
146147

147-
_, err := aws.GetRecommendedRdsInstanceTypeE(t, scenerio.region, scenerio.databaseEngine, scenerio.databaseEngineVersion, scenerio.instanceTypes)
148+
_, err := aws.GetRecommendedRdsInstanceTypeContextE(t, context.Background(), scenerio.region, scenerio.databaseEngine, scenerio.databaseEngineVersion, scenerio.instanceTypes)
148149
assert.EqualError(t, err, aws.NoRdsInstanceTypeError{InstanceTypeOptions: scenerio.instanceTypes, DatabaseEngine: scenerio.databaseEngine, DatabaseEngineVersion: scenerio.databaseEngineVersion}.Error())
149150
})
150151
}

modules/aws/region_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package aws_test
22

33
import (
4+
"context"
45
"testing"
56

67
aws "github.com/gruntwork-io/terratest/modules/aws/v2"
@@ -64,7 +65,7 @@ func TestGetRandomRegionForService(t *testing.T) {
6465

6566
serviceName := "apigatewayv2"
6667

67-
regionsForService, _ := aws.GetRegionsForServiceE(t, serviceName)
68+
regionsForService, _ := aws.GetRegionsForServiceContextE(t, context.Background(), serviceName)
6869
randomRegionForService := aws.GetRandomRegionForService(t, serviceName)
6970

7071
assert.Contains(t, regionsForService, randomRegionForService)

0 commit comments

Comments
 (0)