Skip to content

Commit 0731de8

Browse files
committed
Replace all unnecessary context.Background() in tests with t.Context()
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
1 parent fec8fd7 commit 0731de8

20 files changed

+41
-52
lines changed

github/acc_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ func skipUnlessHasAppInstallations(t *testing.T) {
318318
t.Fatalf("failed to get test meta: %s", err)
319319
}
320320

321-
installations, _, err := meta.v3client.Organizations.ListInstallations(context.Background(), meta.name, nil)
321+
installations, _, err := meta.v3client.Organizations.ListInstallations(t.Context(), meta.name, nil)
322322
if err != nil {
323323
t.Fatalf("failed to list app installations: %s", err)
324324
}

github/config_test.go

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

33
import (
4-
"context"
54
"net/http"
65
"net/http/httptest"
76
"testing"
@@ -171,7 +170,7 @@ func TestAccConfigMeta(t *testing.T) {
171170
t.Fatalf("failed to return meta without error: %s", err.Error())
172171
}
173172

174-
ctx := context.Background()
173+
ctx := t.Context()
175174
client := meta.(*Owner).v3client
176175
_, _, err = client.Meta.Get(ctx)
177176
if err != nil {
@@ -191,7 +190,7 @@ func TestAccConfigMeta(t *testing.T) {
191190
t.Fatalf("failed to return meta without error: %s", err.Error())
192191
}
193192

194-
ctx := context.Background()
193+
ctx := t.Context()
195194
client := meta.(*Owner).v3client
196195
_, _, err = client.Meta.Get(ctx)
197196
if err != nil {
@@ -216,7 +215,7 @@ func TestAccConfigMeta(t *testing.T) {
216215
t.Fatalf("failed to return meta without error: %s", err.Error())
217216
}
218217

219-
ctx := context.Background()
218+
ctx := t.Context()
220219
client := meta.(*Owner).v3client
221220
_, _, err = client.Meta.Get(ctx)
222221
if err != nil {
@@ -242,7 +241,7 @@ func TestAccConfigMeta(t *testing.T) {
242241
GitHubServicesSha githubv4.String
243242
}
244243
}
245-
err = client.Query(context.Background(), &query, nil)
244+
err = client.Query(t.Context(), &query, nil)
246245
if err != nil {
247246
t.Fatalf("failed to validate returned client without error: %s", err.Error())
248247
}
@@ -261,7 +260,7 @@ func TestAccConfigMeta(t *testing.T) {
261260
t.Fatalf("failed to return meta without error: %s", err.Error())
262261
}
263262

264-
ctx := context.Background()
263+
ctx := t.Context()
265264
client := meta.(*Owner).v3client
266265
_, _, err = client.Organizations.Get(ctx, testAccConf.owner)
267266
if err != nil {
@@ -292,7 +291,7 @@ func TestAccConfigMeta(t *testing.T) {
292291
variables := map[string]any{
293292
"login": githubv4.String(testAccConf.owner),
294293
}
295-
err = client.Query(context.Background(), &query, variables)
294+
err = client.Query(t.Context(), &query, variables)
296295
if err != nil {
297296
t.Fatalf("failed to validate returned client without error: %s", err.Error())
298297
}

github/resource_github_actions_environment_secret_migration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ package github
4040
// t.Run(d.testName, func(t *testing.T) {
4141
// t.Parallel()
4242

43-
// got, err := resourceGithubActionsEnvironmentSecretStateUpgradeV0(context.Background(), d.rawState, nil)
43+
// got, err := resourceGithubActionsEnvironmentSecretStateUpgradeV0(t.Context(), d.rawState, nil)
4444
// if (err != nil) != d.shouldError {
4545
// t.Fatalf("unexpected error state")
4646
// }

github/resource_github_actions_environment_secret_test.go

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

33
import (
4-
"context"
54
"encoding/base64"
65
"fmt"
76
"net/url"
@@ -342,7 +341,7 @@ resource "github_actions_environment_secret" "test" {
342341
}
343342
client := meta.v3client
344343
owner := meta.name
345-
ctx := context.Background()
344+
ctx := t.Context()
346345

347346
escapedEnvName := url.PathEscape(envName)
348347

@@ -438,7 +437,7 @@ resource "github_actions_environment_secret" "test" {
438437
}
439438
client := meta.v3client
440439
owner := meta.name
441-
ctx := context.Background()
440+
ctx := t.Context()
442441

443442
escapedEnvName := url.PathEscape(envName)
444443

github/resource_github_actions_environment_variable_migration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ package github
4040
// t.Run(d.testName, func(t *testing.T) {
4141
// t.Parallel()
4242

43-
// got, err := resourceGithubActionsEnvironmentVariableStateUpgradeV0(context.Background(), d.rawState, nil)
43+
// got, err := resourceGithubActionsEnvironmentVariableStateUpgradeV0(t.Context(), d.rawState, nil)
4444
// if (err != nil) != d.shouldError {
4545
// t.Fatalf("unexpected error state")
4646
// }

github/resource_github_actions_environment_variable_test.go

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

33
import (
4-
"context"
54
"fmt"
65
"net/url"
76
"regexp"
@@ -434,7 +433,7 @@ resource "github_actions_environment_variable" "test" {
434433
}
435434
client := meta.v3client
436435
owner := meta.name
437-
ctx := context.Background()
436+
ctx := t.Context()
438437

439438
_, err = client.Actions.CreateEnvVariable(ctx, owner, repoName, url.PathEscape(envName), &github.ActionsVariable{
440439
Name: varName,
@@ -453,7 +452,7 @@ resource "github_actions_environment_variable" "test" {
453452
}
454453
client := meta.v3client
455454
owner := meta.name
456-
ctx := context.Background()
455+
ctx := t.Context()
457456

458457
_, err = client.Actions.DeleteEnvVariable(ctx, owner, repoName, url.PathEscape(envName), varName)
459458
return err

github/resource_github_actions_organization_secret_migration_test.go

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

33
import (
4-
"context"
54
"reflect"
65
"testing"
76
)
@@ -62,7 +61,7 @@ func Test_resourceGithubActionsOrganizationSecretStateUpgradeV0(t *testing.T) {
6261
t.Run(d.testName, func(t *testing.T) {
6362
t.Parallel()
6463

65-
got, err := resourceGithubActionsOrganizationSecretStateUpgradeV0(context.Background(), d.rawState, nil)
64+
got, err := resourceGithubActionsOrganizationSecretStateUpgradeV0(t.Context(), d.rawState, nil)
6665
if (err != nil) != d.shouldError {
6766
t.Fatalf("unexpected error state")
6867
}

github/resource_github_actions_organization_secret_test.go

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

33
import (
4-
"context"
54
"encoding/base64"
65
"fmt"
76
"regexp"
@@ -455,7 +454,7 @@ resource "github_actions_organization_secret" "test" {
455454
}
456455
client := meta.v3client
457456
owner := meta.name
458-
ctx := context.Background()
457+
ctx := t.Context()
459458

460459
keyID, _, err := getOrganizationPublicKeyDetails(ctx, meta)
461460
if err != nil {
@@ -533,7 +532,7 @@ resource "github_actions_organization_secret" "test" {
533532
}
534533
client := meta.v3client
535534
owner := meta.name
536-
ctx := context.Background()
535+
ctx := t.Context()
537536

538537
keyID, _, err := getOrganizationPublicKeyDetails(ctx, meta)
539538
if err != nil {

github/resource_github_actions_organization_variable_test.go

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

33
import (
4-
"context"
54
"fmt"
65
"regexp"
76
"testing"
@@ -356,7 +355,7 @@ resource "github_actions_organization_variable" "test" {
356355
}
357356
client := meta.v3client
358357
owner := meta.name
359-
ctx := context.Background()
358+
ctx := t.Context()
360359

361360
_, err = client.Actions.CreateOrgVariable(ctx, owner, &github.ActionsVariable{
362361
Name: varName,
@@ -376,7 +375,7 @@ resource "github_actions_organization_variable" "test" {
376375
}
377376
client := meta.v3client
378377
owner := meta.name
379-
ctx := context.Background()
378+
ctx := t.Context()
380379

381380
_, err = client.Actions.DeleteOrgVariable(ctx, owner, varName)
382381
return err

github/resource_github_actions_secret_migration_test.go

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

33
import (
4-
"context"
54
"reflect"
65
"testing"
76
)
@@ -62,7 +61,7 @@ func Test_resourceGithubActionsSecretStateUpgradeV0(t *testing.T) {
6261
t.Run(d.testName, func(t *testing.T) {
6362
t.Parallel()
6463

65-
got, err := resourceGithubActionsSecretStateUpgradeV0(context.Background(), d.rawState, nil)
64+
got, err := resourceGithubActionsSecretStateUpgradeV0(t.Context(), d.rawState, nil)
6665
if (err != nil) != d.shouldError {
6766
t.Fatalf("unexpected error state")
6867
}
@@ -111,7 +110,7 @@ func Test_resourceGithubActionsSecretStateUpgradeV0(t *testing.T) {
111110
// t.Run(d.testName, func(t *testing.T) {
112111
// t.Parallel()
113112

114-
// got, err := resourceGithubActionsSecretStateUpgradeV1(context.Background(), d.rawState, nil)
113+
// got, err := resourceGithubActionsSecretStateUpgradeV1(t.Context(), d.rawState, nil)
115114
// if (err != nil) != d.shouldError {
116115
// t.Fatalf("unexpected error state")
117116
// }

0 commit comments

Comments
 (0)