Skip to content

Commit 3aca0e0

Browse files
authored
chore: fix containedctx linter (#1288)
1 parent 07e11d4 commit 3aca0e0

5 files changed

+14
-15
lines changed

.golangci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ linters:
66
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers [fast: true, auto-fix: false]
77
- bidichk # Checks for dangerous unicode character sequences [fast: true, auto-fix: false]
88
- bodyclose # checks whether HTTP response body is closed successfully [fast: false, auto-fix: false]
9+
- containedctx # containedctx is a linter that detects struct contained context.Context field [fast: true, auto-fix: false]
910
- deadcode # Finds unused code [fast: false, auto-fix: false]
1011
- decorder # check declaration order and count of types, constants, variables and functions [fast: true, auto-fix: false]
1112
- depguard # Go linter that checks if package imports are in a list of acceptable packages [fast: true, auto-fix: false]
@@ -56,7 +57,6 @@ linters:
5657
- whitespace # Tool for detection of leading and trailing whitespace [fast: true, auto-fix: true]
5758

5859
disable:
59-
- containedctx # containedctx is a linter that detects struct contained context.Context field [fast: true, auto-fix: false]
6060
- contextcheck # check the function whether use a non-inherited context [fast: false, auto-fix: false]
6161
- cyclop # checks function and package cyclomatic complexity [fast: false, auto-fix: false]
6262
- dupl # Tool for code clone detection [fast: true, auto-fix: false]

scaleway/helpers_instance.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,6 @@ func preparePrivateNIC(
301301
}
302302

303303
type privateNICsHandler struct {
304-
ctx context.Context
305304
instanceAPI *instance.API
306305
serverID string
307306
privateNICsMap map[string]*instance.PrivateNIC
@@ -310,7 +309,6 @@ type privateNICsHandler struct {
310309

311310
func newPrivateNICHandler(ctx context.Context, api *instance.API, server string, zone scw.Zone) (*privateNICsHandler, error) {
312311
handler := &privateNICsHandler{
313-
ctx: ctx,
314312
instanceAPI: api,
315313
serverID: server,
316314
zone: zone}
@@ -331,13 +329,13 @@ func (ph *privateNICsHandler) flatPrivateNICs() error {
331329
return nil
332330
}
333331

334-
func (ph *privateNICsHandler) detach(o interface{}, timeout time.Duration) error {
332+
func (ph *privateNICsHandler) detach(ctx context.Context, o interface{}, timeout time.Duration) error {
335333
oPtr := expandStringPtr(o)
336334
if oPtr != nil && len(*oPtr) > 0 {
337335
idPN := expandID(*oPtr)
338336
// check if old private network still exist on instance server
339337
if p, ok := ph.privateNICsMap[idPN]; ok {
340-
_, err := waitForPrivateNIC(ph.ctx, ph.instanceAPI, ph.zone, ph.serverID, expandID(p.ID), timeout)
338+
_, err := waitForPrivateNIC(ctx, ph.instanceAPI, ph.zone, ph.serverID, expandID(p.ID), timeout)
341339
if err != nil {
342340
return err
343341
}
@@ -346,7 +344,7 @@ func (ph *privateNICsHandler) detach(o interface{}, timeout time.Duration) error
346344
PrivateNicID: expandID(p.ID),
347345
Zone: ph.zone,
348346
ServerID: ph.serverID},
349-
scw.WithContext(ph.ctx))
347+
scw.WithContext(ctx))
350348
if err != nil {
351349
return err
352350
}
@@ -356,7 +354,7 @@ func (ph *privateNICsHandler) detach(o interface{}, timeout time.Duration) error
356354
return nil
357355
}
358356

359-
func (ph *privateNICsHandler) attach(n interface{}, timeout time.Duration) error {
357+
func (ph *privateNICsHandler) attach(ctx context.Context, n interface{}, timeout time.Duration) error {
360358
if nPtr := expandStringPtr(n); nPtr != nil {
361359
// check if new private network was already attached on instance server
362360
privateNetworkID := expandID(*nPtr)
@@ -369,7 +367,7 @@ func (ph *privateNICsHandler) attach(n interface{}, timeout time.Duration) error
369367
return err
370368
}
371369

372-
_, err = waitForPrivateNIC(ph.ctx, ph.instanceAPI, ph.zone, ph.serverID, pn.PrivateNic.ID, timeout)
370+
_, err = waitForPrivateNIC(ctx, ph.instanceAPI, ph.zone, ph.serverID, pn.PrivateNic.ID, timeout)
373371
if err != nil {
374372
return err
375373
}

scaleway/provider_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ type TestTools struct {
8383
Meta *Meta
8484
ProviderFactories map[string]func() (*schema.Provider, error)
8585
Cleanup func()
86-
ctx context.Context
8786
}
8887

8988
func NewTestTools(t *testing.T) *TestTools {
@@ -115,6 +114,5 @@ func NewTestTools(t *testing.T) *TestTools {
115114
},
116115
},
117116
Cleanup: cleanup,
118-
ctx: ctx,
119117
}
120118
}

scaleway/resource_instance_server.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -848,11 +848,11 @@ func resourceScalewayInstanceServerUpdate(ctx context.Context, d *schema.Resourc
848848
return diag.FromErr(err)
849849
}
850850

851-
err = ph.detach(o, d.Timeout(schema.TimeoutUpdate))
851+
err = ph.detach(ctx, o, d.Timeout(schema.TimeoutUpdate))
852852
if err != nil {
853853
diag.FromErr(err)
854854
}
855-
err = ph.attach(n, d.Timeout(schema.TimeoutUpdate))
855+
err = ph.attach(ctx, n, d.Timeout(schema.TimeoutUpdate))
856856
if err != nil {
857857
diag.FromErr(err)
858858
}
@@ -870,7 +870,7 @@ func resourceScalewayInstanceServerUpdate(ctx context.Context, d *schema.Resourc
870870
return diag.FromErr(err)
871871
}
872872

873-
err = ph.detach(pn["pn_id"], d.Timeout(schema.TimeoutUpdate))
873+
err = ph.detach(ctx, pn["pn_id"], d.Timeout(schema.TimeoutUpdate))
874874
if err != nil {
875875
diag.FromErr(err)
876876
}

scaleway/resource_object_bucket_test.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ func TestAccScalewayObjectBucket_Cors_Delete(t *testing.T) {
504504
}
505505
tt := NewTestTools(t)
506506
defer tt.Cleanup()
507+
ctx := context.Background()
507508

508509
resourceName := "scaleway_object_bucket.bucket"
509510
bucketName := sdkacctest.RandomWithPrefix("test-acc-scaleway-object-bucket-cors-delete")
@@ -518,7 +519,7 @@ func TestAccScalewayObjectBucket_Cors_Delete(t *testing.T) {
518519
if err != nil {
519520
return err
520521
}
521-
_, err = conn.DeleteBucketCorsWithContext(tt.ctx, &s3.DeleteBucketCorsInput{
522+
_, err = conn.DeleteBucketCorsWithContext(ctx, &s3.DeleteBucketCorsInput{
522523
Bucket: scw.StringPtr(rs.Primary.Attributes["name"]),
523524
})
524525
if err != nil && !isS3Err(err, ErrCodeNoSuchCORSConfiguration, "") {
@@ -588,14 +589,16 @@ func TestAccScalewayObjectBucket_Cors_EmptyOrigin(t *testing.T) {
588589

589590
func testAccCheckScalewayObjectBucketCors(tt *TestTools, n string, corsRules []*s3.CORSRule) resource.TestCheckFunc {
590591
return func(s *terraform.State) error {
592+
ctx := context.Background()
593+
591594
rs := s.RootModule().Resources[n]
592595
bucketName := rs.Primary.Attributes["name"]
593596
s3Client, err := newS3ClientFromMeta(tt.Meta)
594597
if err != nil {
595598
return err
596599
}
597600

598-
_, err = s3Client.HeadBucketWithContext(tt.ctx, &s3.HeadBucketInput{
601+
_, err = s3Client.HeadBucketWithContext(ctx, &s3.HeadBucketInput{
599602
Bucket: scw.StringPtr(bucketName),
600603
})
601604
if err != nil {

0 commit comments

Comments
 (0)