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 gofumpt linter #1293

Merged
merged 3 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -22,6 +22,7 @@ linters:
- goconst # Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false]
- gocyclo # Computes and checks the cyclomatic complexity of functions [fast: true, auto-fix: false]
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification [fast: true, auto-fix: true]
- gofumpt # Gofumpt checks whether code was gofumpt-ed. [fast: true, auto-fix: true]
- goheader # Checks is file header matches to pattern [fast: true, auto-fix: false]
- goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt. [fast: true, auto-fix: true]
- gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod. [fast: true, auto-fix: false]
Expand Down Expand Up @@ -73,7 +74,6 @@ linters:
- godot # Check if comments end in a period [fast: true, auto-fix: true]
- godox # Tool for detection of FIXME, TODO and other comment keywords [fast: true, auto-fix: false]
- goerr113 # Golang linter to check the errors handling expressions [fast: false, auto-fix: false]
- gofumpt # Gofumpt checks whether code was gofumpt-ed. [fast: true, auto-fix: true]
- gomnd # An analyzer to detect magic numbers. [fast: true, auto-fix: false]
- gosec #(gas): Inspects source code for security problems [fast: false, auto-fix: false]
- lll # Reports long lines [fast: true, auto-fix: false]
Expand Down
3 changes: 2 additions & 1 deletion scaleway/data_source_account_ssh_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ func TestAccScalewayDataSourceAccountSSHKey_Basic(t *testing.T) {
testAccCheckScalewayAccountSSHKeyExists(tt, "data.scaleway_account_ssh_key.stg"),
resource.TestCheckResourceAttr("data.scaleway_account_ssh_key.stg", "name", sshKeyName),
resource.TestCheckResourceAttr("data.scaleway_account_ssh_key.stg", "public_key", dataSourceAccountSSHKey),
)},
),
},
},
})
}
3 changes: 1 addition & 2 deletions scaleway/data_source_baremetal_offer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestAccScalewayDataSourceBaremetalOffer_Basic(t *testing.T) {
resource.TestCheckResourceAttr("data.scaleway_baremetal_offer.test2", "include_disabled", "false"),
resource.TestCheckResourceAttr("data.scaleway_baremetal_offer.test2", "bandwidth", "1000000000"),
resource.TestCheckResourceAttr("data.scaleway_baremetal_offer.test2", "commercial_range", "aluminium"),
//resource.TestCheckResourceAttr("data.scaleway_baremetal_offer.test2", "stock", "available"), // skipping this as stocks vary too much
// resource.TestCheckResourceAttr("data.scaleway_baremetal_offer.test2", "stock", "available"), // skipping this as stocks vary too much
resource.TestCheckResourceAttr("data.scaleway_baremetal_offer.test2", "cpu.0.name", "AMD Ryzen PRO 3600"),
resource.TestCheckResourceAttr("data.scaleway_baremetal_offer.test2", "cpu.0.core_count", "6"),
resource.TestCheckResourceAttr("data.scaleway_baremetal_offer.test2", "cpu.0.frequency", "3600"),
Expand Down Expand Up @@ -81,7 +81,6 @@ func testAccCheckScalewayBaremetalOfferExists(tt *TestTools, n string) resource.
resp, err := baremetalAPI.ListOffers(&baremetal.ListOffersRequest{
Zone: zone,
}, scw.WithAllPages())

if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion scaleway/data_source_object_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestAccScalewayDataSourceObjectStorage_Basic(t *testing.T) {
tt := NewTestTools(t)
defer tt.Cleanup()
bucketName := sdkacctest.RandomWithPrefix("test-acc-scaleway-object-bucket")
//resourceName := "data.scaleway_object_bucket.main"
// resourceName := "data.scaleway_object_bucket.main"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: tt.ProviderFactories,
Expand Down
8 changes: 3 additions & 5 deletions scaleway/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ import (
"golang.org/x/xerrors"
)

var (
// DefaultWaitRetryInterval is used to set the retry interval to 0 during acceptance tests
DefaultWaitRetryInterval *time.Duration
)
// DefaultWaitRetryInterval is used to set the retry interval to 0 during acceptance tests
var DefaultWaitRetryInterval *time.Duration

// RegionalID represents an ID that is linked with a region, eg fr-par/11111111-1111-1111-1111-111111111111
type RegionalID struct {
Expand Down Expand Up @@ -244,7 +242,7 @@ func is403Error(err error) bool {

// is409Error return true is err is an HTTP 409 error
func is409Error(err error) bool {
//check transient error
// check transient error
transientStateError := &scw.TransientStateError{}
return isHTTPCodeError(err, http.StatusConflict) || xerrors.As(err, &transientStateError)
}
Expand Down
15 changes: 10 additions & 5 deletions scaleway/helpers_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ func sanitizeVolumeMap(serverName string, volumes map[string]*instance.VolumeSer

func preparePrivateNIC(
ctx context.Context, data interface{},
server *instance.Server, vpcAPI *vpc.API) ([]*instance.CreatePrivateNICRequest, error) {
server *instance.Server, vpcAPI *vpc.API,
) ([]*instance.CreatePrivateNICRequest, error) {
if data == nil {
return nil, nil
}
Expand All @@ -292,7 +293,8 @@ func preparePrivateNIC(
query := &instance.CreatePrivateNICRequest{
Zone: currentPN.Zone,
ServerID: server.ID,
PrivateNetworkID: currentPN.ID}
PrivateNetworkID: currentPN.ID,
}
res = append(res, query)
}
}
Expand All @@ -311,7 +313,8 @@ func newPrivateNICHandler(ctx context.Context, api *instance.API, server string,
handler := &privateNICsHandler{
instanceAPI: api,
serverID: server,
zone: zone}
zone: zone,
}
return handler, handler.flatPrivateNICs()
}

Expand Down Expand Up @@ -343,7 +346,8 @@ func (ph *privateNICsHandler) detach(ctx context.Context, o interface{}, timeout
err = ph.instanceAPI.DeletePrivateNIC(&instance.DeletePrivateNICRequest{
PrivateNicID: expandID(p.ID),
Zone: ph.zone,
ServerID: ph.serverID},
ServerID: ph.serverID,
},
scw.WithContext(ctx))
if err != nil {
return err
Expand All @@ -362,7 +366,8 @@ func (ph *privateNICsHandler) attach(ctx context.Context, n interface{}, timeout
pn, err := ph.instanceAPI.CreatePrivateNIC(&instance.CreatePrivateNICRequest{
Zone: ph.zone,
ServerID: ph.serverID,
PrivateNetworkID: privateNetworkID})
PrivateNetworkID: privateNetworkID,
})
if err != nil {
return err
}
Expand Down
3 changes: 0 additions & 3 deletions scaleway/helpers_k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ func waitK8SClusterDeleted(ctx context.Context, k8sAPI *k8s.API, region scw.Regi
Timeout: scw.TimeDurationPtr(timeout),
RetryInterval: &retryInterval,
}, scw.WithContext(ctx))

if err != nil {
if is404Error(err) {
return nil
Expand All @@ -140,7 +139,6 @@ func waitK8SPoolReady(ctx context.Context, k8sAPI *k8s.API, region scw.Region, p
Timeout: scw.TimeDurationPtr(timeout),
RetryInterval: &retryInterval,
}, scw.WithContext(ctx))

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -177,7 +175,6 @@ func getNodes(ctx context.Context, k8sAPI *k8s.API, pool *k8s.Pool) ([]map[strin
}

nodes, err := k8sAPI.ListNodes(req, scw.WithAllPages(), scw.WithContext(ctx))

if err != nil {
return nil, err
}
Expand Down
8 changes: 5 additions & 3 deletions scaleway/helpers_lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,15 @@ func expandLbACL(i interface{}) *lbSDK.ACL {
Action: expandLbACLAction(rawRule["action"]),
}

//remove http filter values if we do not pass any http filter
// remove http filter values if we do not pass any http filter
if acl.Match.HTTPFilter == "" || acl.Match.HTTPFilter == lbSDK.ACLHTTPFilterACLHTTPFilterNone {
acl.Match.HTTPFilter = lbSDK.ACLHTTPFilterACLHTTPFilterNone
acl.Match.HTTPFilterValue = []*string{}
}

return acl
}

func flattenLbACLAction(action *lbSDK.ACLAction) interface{} {
return []map[string]interface{}{
{
Expand Down Expand Up @@ -151,6 +152,7 @@ func newPrivateNetwork(raw map[string]interface{}) *lbSDK.PrivateNetwork {

return pn
}

func privateNetworksToDetach(pns []*lbSDK.PrivateNetwork, updates interface{}) (map[string]bool, error) {
actions := make(map[string]bool, len(pns))
configs := make(map[string]*lbSDK.PrivateNetwork, len(pns))
Expand All @@ -159,7 +161,7 @@ func privateNetworksToDetach(pns []*lbSDK.PrivateNetwork, updates interface{}) (
actions[pn.PrivateNetworkID] = true
configs[pn.PrivateNetworkID] = pn
}
//check if private network still exist or is different
// check if private network still exist or is different
for _, pn := range updates.([]interface{}) {
r := pn.(map[string]interface{})
_, pnID, err := parseZonedID(r["private_network_id"].(string))
Expand Down Expand Up @@ -226,7 +228,7 @@ func expandLbACLMatch(raw interface{}) *lbSDK.ACLMatch {
}
rawMap := raw.([]interface{})[0].(map[string]interface{})

//scaleway api require ip subnet, so if we did not specify one, just put 0.0.0.0/0 instead
// scaleway api require ip subnet, so if we did not specify one, just put 0.0.0.0/0 instead
ipSubnet := expandSliceStringPtr(rawMap["ip_subnet"].([]interface{}))
if len(ipSubnet) == 0 {
ipSubnet = []*string{expandStringPtr("0.0.0.0/0")}
Expand Down
3 changes: 2 additions & 1 deletion scaleway/helpers_rdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ func expandLoadBalancer() []*rdb.EndpointSpec {
var res []*rdb.EndpointSpec

res = append(res, &rdb.EndpointSpec{
LoadBalancer: &rdb.EndpointSpecLoadBalancer{}})
LoadBalancer: &rdb.EndpointSpecLoadBalancer{},
})

return res
}
Expand Down
51 changes: 34 additions & 17 deletions scaleway/helpers_rdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,41 @@ func TestIsEndPointEqual(t *testing.T) {
{
name: "isEqualPrivateNetworkDetails",
A: &rdb.EndpointPrivateNetworkDetails{PrivateNetworkID: "6ba7b810-9dad-11d1-80b4-00c04fd430c8", ServiceIP: scw.IPNet{IPNet: net.IPNet{
IP: net.IPv4(1, 1, 1, 1), Mask: net.CIDRMask(24, 32)}}, Zone: scw.ZoneFrPar1},
IP: net.IPv4(1, 1, 1, 1), Mask: net.CIDRMask(24, 32),
}}, Zone: scw.ZoneFrPar1},
B: &rdb.EndpointPrivateNetworkDetails{PrivateNetworkID: "6ba7b810-9dad-11d1-80b4-00c04fd430c8", ServiceIP: scw.IPNet{IPNet: net.IPNet{
IP: net.IPv4(1, 1, 1, 1), Mask: net.CIDRMask(24, 32)}}, Zone: scw.ZoneFrPar1},
IP: net.IPv4(1, 1, 1, 1), Mask: net.CIDRMask(24, 32),
}}, Zone: scw.ZoneFrPar1},
expected: true,
},
{
name: "notEqualIP",
A: &rdb.EndpointPrivateNetworkDetails{PrivateNetworkID: "6ba7b810-9dad-11d1-80b4-00c04fd430c8", ServiceIP: scw.IPNet{IPNet: net.IPNet{
IP: net.IPv4(1, 1, 1, 1), Mask: net.CIDRMask(24, 32)}}, Zone: scw.ZoneFrPar1},
IP: net.IPv4(1, 1, 1, 1), Mask: net.CIDRMask(24, 32),
}}, Zone: scw.ZoneFrPar1},
B: &rdb.EndpointPrivateNetworkDetails{PrivateNetworkID: "6ba7b810-9dad-11d1-80b4-00c04fd430c8", ServiceIP: scw.IPNet{IPNet: net.IPNet{
IP: net.IPv4(1, 1, 1, 2), Mask: net.CIDRMask(24, 32)}}, Zone: scw.ZoneFrPar1},
IP: net.IPv4(1, 1, 1, 2), Mask: net.CIDRMask(24, 32),
}}, Zone: scw.ZoneFrPar1},
expected: false,
},
{
name: "notEqualZone",
A: &rdb.EndpointPrivateNetworkDetails{PrivateNetworkID: "6ba7b810-9dad-11d1-80b4-00c04fd430c8", ServiceIP: scw.IPNet{IPNet: net.IPNet{
IP: net.IPv4(1, 1, 1, 1), Mask: net.CIDRMask(24, 32)}}, Zone: scw.ZoneFrPar1},
IP: net.IPv4(1, 1, 1, 1), Mask: net.CIDRMask(24, 32),
}}, Zone: scw.ZoneFrPar1},
B: &rdb.EndpointPrivateNetworkDetails{PrivateNetworkID: "6ba7b810-9dad-11d1-80b4-00c04fd430c8", ServiceIP: scw.IPNet{IPNet: net.IPNet{
IP: net.IPv4(1, 1, 1, 1), Mask: net.CIDRMask(24, 32)}}, Zone: scw.ZoneFrPar2},
IP: net.IPv4(1, 1, 1, 1), Mask: net.CIDRMask(24, 32),
}}, Zone: scw.ZoneFrPar2},
expected: false,
},
{
name: "notEqualMask",
A: &rdb.EndpointPrivateNetworkDetails{PrivateNetworkID: "6ba7b810-9dad-11d1-80b4-00c04fd430c8", ServiceIP: scw.IPNet{IPNet: net.IPNet{
IP: net.IPv4(1, 1, 1, 1), Mask: net.CIDRMask(25, 32)}}, Zone: scw.ZoneFrPar1},
IP: net.IPv4(1, 1, 1, 1), Mask: net.CIDRMask(25, 32),
}}, Zone: scw.ZoneFrPar1},
B: &rdb.EndpointPrivateNetworkDetails{PrivateNetworkID: "6ba7b810-9dad-11d1-80b4-00c04fd430c8", ServiceIP: scw.IPNet{IPNet: net.IPNet{
IP: net.IPv4(1, 1, 1, 1), Mask: net.CIDRMask(24, 32)}}, Zone: scw.ZoneFrPar1},
IP: net.IPv4(1, 1, 1, 1), Mask: net.CIDRMask(24, 32),
}}, Zone: scw.ZoneFrPar1},
expected: false,
},
}
Expand All @@ -67,10 +75,13 @@ func TestEndpointsToRemove(t *testing.T) {
name: "removeAll",
Endpoints: []*rdb.Endpoint{{
ID: "6ba7b810-9dad-11d1-80b4-00c04fd430c1",
PrivateNetwork: &rdb.EndpointPrivateNetworkDetails{PrivateNetworkID: "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
PrivateNetwork: &rdb.EndpointPrivateNetworkDetails{
PrivateNetworkID: "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
ServiceIP: scw.IPNet{IPNet: net.IPNet{
IP: net.IPv4(1, 1, 1, 1), Mask: net.CIDRMask(24, 32)}},
Zone: scw.ZoneFrPar1},
IP: net.IPv4(1, 1, 1, 1), Mask: net.CIDRMask(24, 32),
}},
Zone: scw.ZoneFrPar1,
},
}},
Expected: map[string]bool{
"6ba7b810-9dad-11d1-80b4-00c04fd430c1": true,
Expand All @@ -80,10 +91,13 @@ func TestEndpointsToRemove(t *testing.T) {
name: "shouldUpdatePrivateNetwork",
Endpoints: []*rdb.Endpoint{{
ID: "6ba7b810-9dad-11d1-80b4-00c04fd430c1",
PrivateNetwork: &rdb.EndpointPrivateNetworkDetails{PrivateNetworkID: "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
PrivateNetwork: &rdb.EndpointPrivateNetworkDetails{
PrivateNetworkID: "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
ServiceIP: scw.IPNet{IPNet: net.IPNet{
IP: net.IPv4(1, 1, 1, 1), Mask: net.CIDRMask(24, 32)}},
Zone: scw.ZoneFrPar1},
IP: net.IPv4(1, 1, 1, 1), Mask: net.CIDRMask(24, 32),
}},
Zone: scw.ZoneFrPar1,
},
}},
Updates: []interface{}{map[string]interface{}{"pn_id": "fr-par-1/6ba7b810-9dad-11d1-80b4-00c04fd430c8", "ip_net": "192.168.1.43/24"}},
Expected: map[string]bool{
Expand All @@ -94,10 +108,13 @@ func TestEndpointsToRemove(t *testing.T) {
name: "shouldNotUpdatePrivateNetwork",
Endpoints: []*rdb.Endpoint{{
ID: "6ba7b810-9dad-11d1-80b4-00c04fd430c1",
PrivateNetwork: &rdb.EndpointPrivateNetworkDetails{PrivateNetworkID: "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
PrivateNetwork: &rdb.EndpointPrivateNetworkDetails{
PrivateNetworkID: "6ba7b810-9dad-11d1-80b4-00c04fd430c8",
ServiceIP: scw.IPNet{IPNet: net.IPNet{
IP: net.IPv4(1, 1, 1, 1), Mask: net.CIDRMask(24, 32)}},
Zone: scw.ZoneFrPar1},
IP: net.IPv4(1, 1, 1, 1), Mask: net.CIDRMask(24, 32),
}},
Zone: scw.ZoneFrPar1,
},
}},
Updates: []interface{}{map[string]interface{}{"pn_id": "fr-par-1/6ba7b810-9dad-11d1-80b4-00c04fd430c8", "ip_net": "1.1.1.1/24"}},
Expected: map[string]bool{
Expand Down
3 changes: 1 addition & 2 deletions scaleway/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import (
// logger is the implementation of the SDK Logger interface for this terraform plugin.
//
// cf. https://godoc.org/github.com/scaleway/scaleway-sdk-go/logger#Logger
type logger struct {
}
type logger struct{}

// l is the global logger singleton
var l = logger{}
Expand Down
6 changes: 2 additions & 4 deletions scaleway/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ import (
"github.com/stretchr/testify/require"
)

var (
// UpdateCassettes will update all cassettes of a given test
UpdateCassettes = flag.Bool("cassettes", os.Getenv("TF_UPDATE_CASSETTES") == "true", "Record Cassettes")
)
// UpdateCassettes will update all cassettes of a given test
var UpdateCassettes = flag.Bool("cassettes", os.Getenv("TF_UPDATE_CASSETTES") == "true", "Record Cassettes")

func testAccPreCheck(_ *testing.T) {}

Expand Down
3 changes: 2 additions & 1 deletion scaleway/resource_apple_silicon_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ func resourceScalewayAppleSiliconServer() *schema.Resource {
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
AppleSiliconM1Type}, false),
AppleSiliconM1Type,
}, false),
},
// Computed
"ip": {
Expand Down
8 changes: 5 additions & 3 deletions scaleway/resource_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ func resourceScalewayContainer() *schema.Resource {
Default: container.ContainerProtocolHTTP1.String(),
ValidateFunc: validation.StringInSlice([]string{
container.ContainerProtocolH2c.String(),
container.ContainerProtocolHTTP1.String()}, false),
container.ContainerProtocolHTTP1.String(),
}, false),
},
"port": {
Type: schema.TypeInt,
Expand Down Expand Up @@ -382,8 +383,9 @@ func resourceScalewayContainerDelete(ctx context.Context, d *schema.ResourceData
}

// check for container state
_, err = api.WaitForContainer(&container.WaitForContainerRequest{ContainerID: containerID,
Region: region,
_, err = api.WaitForContainer(&container.WaitForContainerRequest{
ContainerID: containerID,
Region: region,
}, scw.WithContext(ctx))
if err != nil {
return diag.Errorf("unexpected waiting container error: %s", err)
Expand Down
9 changes: 4 additions & 5 deletions scaleway/resource_container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ import (
container "github.com/scaleway/scaleway-sdk-go/api/container/v1beta1"
)

var (
testDockerIMG = ""
)
var testDockerIMG = ""

func init() {
testDockerIMGPtr := flag.String("test-image", os.Getenv("TF_TEST_DOCKER_IMG"), "Test image")
Expand All @@ -32,6 +30,7 @@ func init() {
}
l.Infof("start container registry with image: %s", testDockerIMG)
}

func TestAccScalewayContainer_Basic(t *testing.T) {
tt := NewTestTools(t)
defer tt.Cleanup()
Expand Down Expand Up @@ -299,8 +298,8 @@ func testConfigContainerNamespace(tt *TestTools, n string) resource.TestCheckFun
}
}

var imageTag = testDockerIMG + ":latest"
var scwTag = ns.RegistryEndpoint + "/alpine:test"
imageTag := testDockerIMG + ":latest"
scwTag := ns.RegistryEndpoint + "/alpine:test"

err = cli.ImageTag(ctx, imageTag, scwTag)
if err != nil {
Expand Down
Loading