Skip to content

Commit 0e824a9

Browse files
committed
Propagate ctx instead of context.Background() in two Context functions
FetchFilesFromInstanceContextE and GetStorageDNSStringContextE both take a ctx but were passing context.Background() to the call the migration rewrote, so cancellation and timeouts stopped at those boundaries. The old deprecated wrappers hid this; the migration made it explicit. Pass the real ctx and drop the now-inaccurate nolint directives.
1 parent a3dfb5f commit 0e824a9

3 files changed

Lines changed: 14 additions & 15 deletions

File tree

modules/aws/ec2-files.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,7 @@ func FetchFilesFromInstanceContextE(t testing.TestingT, ctx context.Context, aws
285285
FileNameFilters: filenameFilters,
286286
}
287287

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

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

modules/azure/storage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ func GetStorageDNSStringContextE(ctx context.Context, storageAccountName, resour
518518
}
519519

520520
if retval {
521-
storageSuffix, err2 := GetStorageURISuffixContextE(context.Background()) //nolint:contextcheck
521+
storageSuffix, err2 := GetStorageURISuffixContextE(ctx)
522522
if err2 != nil {
523523
return "", err2
524524
}

modules/terraform/count_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,23 @@ func TestGetResourceCountENoColor(t *testing.T) { //nolint:tparallel // subtests
4444
func runTestGetResourceCountE(t *testing.T, noColor bool) { //nolint:tparallel // subtests share mutable terraform options
4545
t.Helper()
4646
testCases := []struct {
47-
tfFuncToRun func(t ttesting.TestingT, options *terraform.Options) string
47+
tfFuncToRun func(t ttesting.TestingT, ctx context.Context, options *terraform.Options) string
4848
name string
4949
cntValue int
5050
expectedAdd int
5151
expectedChange int
5252
expectedDestroy int
5353
}{
54-
{name: "PlanZero", tfFuncToRun: terraform.InitAndPlan, cntValue: 0, expectedAdd: 0, expectedChange: 0, expectedDestroy: 0},
55-
{name: "ApplyZero", tfFuncToRun: terraform.InitAndApply, cntValue: 0, expectedAdd: 0, expectedChange: 0, expectedDestroy: 0},
56-
{name: "PlanAddResouce", tfFuncToRun: terraform.InitAndPlan, cntValue: 2, expectedAdd: 2, expectedChange: 0, expectedDestroy: 0},
57-
{name: "ApplyAddResouce", tfFuncToRun: terraform.InitAndApply, cntValue: 2, expectedAdd: 2, expectedChange: 0, expectedDestroy: 0},
58-
{name: "PlanNoOp", tfFuncToRun: terraform.InitAndApply, cntValue: 2, expectedAdd: 0, expectedChange: 0, expectedDestroy: 0},
59-
{name: "ApplyNoOp", tfFuncToRun: terraform.InitAndApply, cntValue: 2, expectedAdd: 0, expectedChange: 0, expectedDestroy: 0},
60-
{name: "PlanDestroyResource", tfFuncToRun: terraform.InitAndPlan, cntValue: 1, expectedAdd: 0, expectedChange: 0, expectedDestroy: 1},
61-
{name: "ApplyDestroyResource", tfFuncToRun: terraform.InitAndApply, cntValue: 1, expectedAdd: 0, expectedChange: 0, expectedDestroy: 1},
62-
{name: "Destroy", tfFuncToRun: terraform.Destroy, cntValue: 1, expectedAdd: 0, expectedChange: 0, expectedDestroy: 1},
63-
{name: "DestroyNoOp", tfFuncToRun: terraform.Destroy, cntValue: 1, expectedAdd: 0, expectedChange: 0, expectedDestroy: 0},
54+
{name: "PlanZero", tfFuncToRun: terraform.InitAndPlanContext, cntValue: 0, expectedAdd: 0, expectedChange: 0, expectedDestroy: 0},
55+
{name: "ApplyZero", tfFuncToRun: terraform.InitAndApplyContext, cntValue: 0, expectedAdd: 0, expectedChange: 0, expectedDestroy: 0},
56+
{name: "PlanAddResouce", tfFuncToRun: terraform.InitAndPlanContext, cntValue: 2, expectedAdd: 2, expectedChange: 0, expectedDestroy: 0},
57+
{name: "ApplyAddResouce", tfFuncToRun: terraform.InitAndApplyContext, cntValue: 2, expectedAdd: 2, expectedChange: 0, expectedDestroy: 0},
58+
{name: "PlanNoOp", tfFuncToRun: terraform.InitAndApplyContext, cntValue: 2, expectedAdd: 0, expectedChange: 0, expectedDestroy: 0},
59+
{name: "ApplyNoOp", tfFuncToRun: terraform.InitAndApplyContext, cntValue: 2, expectedAdd: 0, expectedChange: 0, expectedDestroy: 0},
60+
{name: "PlanDestroyResource", tfFuncToRun: terraform.InitAndPlanContext, cntValue: 1, expectedAdd: 0, expectedChange: 0, expectedDestroy: 1},
61+
{name: "ApplyDestroyResource", tfFuncToRun: terraform.InitAndApplyContext, cntValue: 1, expectedAdd: 0, expectedChange: 0, expectedDestroy: 1},
62+
{name: "Destroy", tfFuncToRun: terraform.DestroyContext, cntValue: 1, expectedAdd: 0, expectedChange: 0, expectedDestroy: 1},
63+
{name: "DestroyNoOp", tfFuncToRun: terraform.DestroyContext, cntValue: 1, expectedAdd: 0, expectedChange: 0, expectedDestroy: 0},
6464
}
6565

6666
testFolder, err := files.CopyTerraformFolderToTemp("../../test/fixtures/terraform-basic-configuration", t.Name())
@@ -78,7 +78,7 @@ func runTestGetResourceCountE(t *testing.T, noColor bool) { //nolint:tparallel /
7878
t.Run(tc.name,
7979
func(t *testing.T) {
8080
terraformOptions.Vars["cnt"] = tc.cntValue
81-
cnt, err := terraform.GetResourceCountE(t, tc.tfFuncToRun(t, terraformOptions))
81+
cnt, err := terraform.GetResourceCountE(t, tc.tfFuncToRun(t, context.Background(), terraformOptions))
8282
require.NoError(t, err)
8383
assert.Equal(t, tc.expectedAdd, cnt.Add)
8484
assert.Equal(t, tc.expectedChange, cnt.Change)

0 commit comments

Comments
 (0)