Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix containedctx linter #1288

Merged
merged 1 commit into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ linters:
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers [fast: true, auto-fix: false]
- bidichk # Checks for dangerous unicode character sequences [fast: true, auto-fix: false]
- bodyclose # checks whether HTTP response body is closed successfully [fast: false, auto-fix: false]
- containedctx # containedctx is a linter that detects struct contained context.Context field [fast: true, auto-fix: false]
- deadcode # Finds unused code [fast: false, auto-fix: false]
- decorder # check declaration order and count of types, constants, variables and functions [fast: true, auto-fix: false]
- depguard # Go linter that checks if package imports are in a list of acceptable packages [fast: true, auto-fix: false]
Expand Down Expand Up @@ -56,7 +57,6 @@ linters:
- whitespace # Tool for detection of leading and trailing whitespace [fast: true, auto-fix: true]

disable:
- containedctx # containedctx is a linter that detects struct contained context.Context field [fast: true, auto-fix: false]
- contextcheck # check the function whether use a non-inherited context [fast: false, auto-fix: false]
- cyclop # checks function and package cyclomatic complexity [fast: false, auto-fix: false]
- dupl # Tool for code clone detection [fast: true, auto-fix: false]
Expand Down
12 changes: 5 additions & 7 deletions scaleway/helpers_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ func preparePrivateNIC(
}

type privateNICsHandler struct {
ctx context.Context
instanceAPI *instance.API
serverID string
privateNICsMap map[string]*instance.PrivateNIC
Expand All @@ -310,7 +309,6 @@ type privateNICsHandler struct {

func newPrivateNICHandler(ctx context.Context, api *instance.API, server string, zone scw.Zone) (*privateNICsHandler, error) {
handler := &privateNICsHandler{
ctx: ctx,
instanceAPI: api,
serverID: server,
zone: zone}
Expand All @@ -331,13 +329,13 @@ func (ph *privateNICsHandler) flatPrivateNICs() error {
return nil
}

func (ph *privateNICsHandler) detach(o interface{}, timeout time.Duration) error {
func (ph *privateNICsHandler) detach(ctx context.Context, o interface{}, timeout time.Duration) error {
oPtr := expandStringPtr(o)
if oPtr != nil && len(*oPtr) > 0 {
idPN := expandID(*oPtr)
// check if old private network still exist on instance server
if p, ok := ph.privateNICsMap[idPN]; ok {
_, err := waitForPrivateNIC(ph.ctx, ph.instanceAPI, ph.zone, ph.serverID, expandID(p.ID), timeout)
_, err := waitForPrivateNIC(ctx, ph.instanceAPI, ph.zone, ph.serverID, expandID(p.ID), timeout)
if err != nil {
return err
}
Expand All @@ -346,7 +344,7 @@ func (ph *privateNICsHandler) detach(o interface{}, timeout time.Duration) error
PrivateNicID: expandID(p.ID),
Zone: ph.zone,
ServerID: ph.serverID},
scw.WithContext(ph.ctx))
scw.WithContext(ctx))
if err != nil {
return err
}
Expand All @@ -356,7 +354,7 @@ func (ph *privateNICsHandler) detach(o interface{}, timeout time.Duration) error
return nil
}

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

_, err = waitForPrivateNIC(ph.ctx, ph.instanceAPI, ph.zone, ph.serverID, pn.PrivateNic.ID, timeout)
_, err = waitForPrivateNIC(ctx, ph.instanceAPI, ph.zone, ph.serverID, pn.PrivateNic.ID, timeout)
if err != nil {
return err
}
Expand Down
2 changes: 0 additions & 2 deletions scaleway/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ type TestTools struct {
Meta *Meta
ProviderFactories map[string]func() (*schema.Provider, error)
Cleanup func()
ctx context.Context
}

func NewTestTools(t *testing.T) *TestTools {
Expand Down Expand Up @@ -115,6 +114,5 @@ func NewTestTools(t *testing.T) *TestTools {
},
},
Cleanup: cleanup,
ctx: ctx,
}
}
6 changes: 3 additions & 3 deletions scaleway/resource_instance_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -848,11 +848,11 @@ func resourceScalewayInstanceServerUpdate(ctx context.Context, d *schema.Resourc
return diag.FromErr(err)
}

err = ph.detach(o, d.Timeout(schema.TimeoutUpdate))
err = ph.detach(ctx, o, d.Timeout(schema.TimeoutUpdate))
if err != nil {
diag.FromErr(err)
}
err = ph.attach(n, d.Timeout(schema.TimeoutUpdate))
err = ph.attach(ctx, n, d.Timeout(schema.TimeoutUpdate))
if err != nil {
diag.FromErr(err)
}
Expand All @@ -870,7 +870,7 @@ func resourceScalewayInstanceServerUpdate(ctx context.Context, d *schema.Resourc
return diag.FromErr(err)
}

err = ph.detach(pn["pn_id"], d.Timeout(schema.TimeoutUpdate))
err = ph.detach(ctx, pn["pn_id"], d.Timeout(schema.TimeoutUpdate))
if err != nil {
diag.FromErr(err)
}
Expand Down
7 changes: 5 additions & 2 deletions scaleway/resource_object_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ func TestAccScalewayObjectBucket_Cors_Delete(t *testing.T) {
}
tt := NewTestTools(t)
defer tt.Cleanup()
ctx := context.Background()

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

func testAccCheckScalewayObjectBucketCors(tt *TestTools, n string, corsRules []*s3.CORSRule) resource.TestCheckFunc {
return func(s *terraform.State) error {
ctx := context.Background()

rs := s.RootModule().Resources[n]
bucketName := rs.Primary.Attributes["name"]
s3Client, err := newS3ClientFromMeta(tt.Meta)
if err != nil {
return err
}

_, err = s3Client.HeadBucketWithContext(tt.ctx, &s3.HeadBucketInput{
_, err = s3Client.HeadBucketWithContext(ctx, &s3.HeadBucketInput{
Bucket: scw.StringPtr(bucketName),
})
if err != nil {
Expand Down