Skip to content

Commit 9fe788e

Browse files
committed
added golanglintci file credits to the hashicorp azurerm provider, makefile is set to lint with the file, also added goimports and gofmt -s for simplifying code, and removed if else chains with switch
1 parent f57c17d commit 9fe788e

File tree

96 files changed

+325
-234
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+325
-234
lines changed

.golangci.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
run:
2+
deadline: 10m10s
3+
modules-download-mode: vendor
4+
5+
issues:
6+
max-per-linter: 0
7+
max-same-issues: 0
8+
9+
linters:
10+
disable-all: true
11+
enable:
12+
- deadcode
13+
- errcheck
14+
- gocritic
15+
- gofmt
16+
- goimports
17+
- gosimple
18+
- govet
19+
- ineffassign
20+
- interfacer
21+
- nakedret
22+
- misspell
23+
- staticcheck
24+
- structcheck
25+
- typecheck
26+
- unused
27+
- unconvert
28+
- varcheck
29+
- vet
30+
- vetshadow
31+
- whitespace
32+
33+
linters-settings:
34+
errcheck:
35+
ignore: github.com/hashicorp/terraform-plugin-sdk/helper/schema:ForceNew|Set,fmt:.*,io:Close

Makefile

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
default: build
22

3-
test:
3+
test: lint
44
@echo "==> Running tests..."
55
@gotestsum --format short-verbose --raw-command go test -v -json -short -coverprofile=coverage.txt ./...
66

@@ -26,35 +26,40 @@ coverage-int: int
2626

2727
int-build: int build
2828

29-
build: lint test fmt
29+
build: lint test
3030
@echo "==> Building source code with go build..."
3131
@go build -mod vendor -v -o terraform-provider-databricks
3232

33-
lint:
33+
lint: fmt
3434
@echo "==> Linting source code with golangci-lint..."
35-
@golangci-lint run --skip-dirs-use-default --timeout 5m --build-tags=azure
36-
@golangci-lint run --skip-dirs-use-default --timeout 5m --build-tags=aws
35+
@golangci-lint run --skip-dirs-use-default --timeout 5m
3736

38-
fmt: lint
37+
fmt:
3938
@echo "==> Formatting source code with gofmt..."
39+
@goimports -w client
40+
@goimports -w databricks
41+
@goimports -w main.go
42+
@gofmt -s -w client
43+
@gofmt -s -w databricks
44+
@gofmt -s -w main.go
4045
@go fmt ./...
4146

4247
vendor:
4348
@echo "==> Filling vendor folder with library code..."
4449
@go mod vendor
4550

4651
# INTEGRATION TESTING WITH AZURE
47-
terraform-acc-azure: fmt
52+
terraform-acc-azure: lint
4853
@echo "==> Running Terraform Acceptance Tests for Azure..."
4954
@CLOUD_ENV="azure" TF_ACC=1 gotestsum --format short-verbose --raw-command go test -v -json -tags=azure -short -coverprofile=coverage.out ./...
5055

5156
# INTEGRATION TESTING WITH AWS
52-
terraform-acc-aws: fmt
57+
terraform-acc-aws: lint
5358
@echo "==> Running Terraform Acceptance Tests for AWS..."
5459
@CLOUD_ENV="aws" TF_ACC=1 gotestsum --format short-verbose --raw-command go test -v -json -short -coverprofile=coverage.out -run 'TestAccAws' ./...
5560

5661
# INTEGRATION TESTING WITH AWS
57-
terraform-acc-mws: fmt
62+
terraform-acc-mws: lint
5863
@echo "==> Running Terraform Acceptance Tests for Multiple Workspace APIs on AWS..."
5964
@/bin/bash integration-environment-mws/run.sh
6065

client/model/notebook.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package model
22

3-
// Language is a custom type for langauge types in Databricks notebooks
3+
// Language is a custom type for language types in Databricks notebooks
44
type Language string
55

66
// ObjectType is a custom type for object types in Databricks workspaces
@@ -17,7 +17,7 @@ const (
1717
DBC ExportFormat = "DBC"
1818
)
1919

20-
// Different types of langauge formats available on Databricks
20+
// Different types of language formats available on Databricks
2121
const (
2222
Scala Language = "SCALA"
2323
Python Language = "PYTHON"

client/service/client.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (c *DBApiClientConfig) Setup() {
8989
retryMaximumDuration := 5 * time.Minute
9090
c.client = &retryablehttp.Client{
9191
HTTPClient: &http.Client{
92-
Timeout: time.Duration(time.Duration(c.TimeoutSeconds) * time.Second),
92+
Timeout: time.Duration(c.TimeoutSeconds) * time.Second,
9393
Transport: &http.Transport{
9494
TLSClientConfig: &tls.Config{
9595
InsecureSkipVerify: c.InsecureSkipVerify,
@@ -292,7 +292,6 @@ func PerformQuery(config *DBApiClientConfig, method, path string, apiVersion str
292292
}
293293
requestURL += "?" + params.Encode()
294294
auditGetPayload(requestURL, secretsMask)
295-
296295
} else {
297296
if marshalJSON {
298297
bodyBytes, err := json.Marshal(data)
@@ -303,7 +302,6 @@ func PerformQuery(config *DBApiClientConfig, method, path string, apiVersion str
303302
requestBody = bodyBytes
304303
} else {
305304
requestBody = []byte(data.(string))
306-
307305
}
308306
auditNonGetPayload(method, requestURL, data, secretsMask)
309307
}

client/service/clusters.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package service
33
import (
44
"encoding/json"
55
"errors"
6-
"github.com/databrickslabs/databricks-terraform/client/model"
76
"log"
87
"net/http"
98
"time"
9+
10+
"github.com/databrickslabs/databricks-terraform/client/model"
1011
)
1112

1213
// ClustersAPI is a struct that contains the Databricks api client to perform queries

client/service/clusters_integration_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package service
22

33
import (
4-
"github.com/databrickslabs/databricks-terraform/client/model"
5-
"github.com/stretchr/testify/assert"
64
"reflect"
75
"testing"
6+
7+
"github.com/databrickslabs/databricks-terraform/client/model"
8+
"github.com/stretchr/testify/assert"
89
)
910

1011
func TestListClustersIntegration(t *testing.T) {
@@ -72,5 +73,4 @@ func TestListClustersIntegration(t *testing.T) {
7273
clusterReadInfo, err = client.Clusters().Get(clusterInfo.ClusterID)
7374
assert.NoError(t, err, err)
7475
assert.True(t, clusterReadInfo.State == model.ClusterStateRunning)
75-
7676
}

client/service/clusters_test.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package service
22

33
import (
4-
"github.com/databrickslabs/databricks-terraform/client/model"
54
"net/http"
65
"testing"
76
"time"
7+
8+
"github.com/databrickslabs/databricks-terraform/client/model"
89
)
910

1011
func TestClustersAPI_Create(t *testing.T) {
@@ -226,7 +227,6 @@ func TestClustersAPI_Get(t *testing.T) {
226227
}
227228

228229
func TestClustersAPI_List(t *testing.T) {
229-
230230
tests := []struct {
231231
name string
232232
response string
@@ -302,7 +302,6 @@ func TestClustersAPI_List(t *testing.T) {
302302
}
303303

304304
func TestClustersAPI_ListZones(t *testing.T) {
305-
306305
tests := []struct {
307306
name string
308307
response string
@@ -351,7 +350,6 @@ func TestClustersAPI_ListZones(t *testing.T) {
351350
}
352351

353352
func TestClustersAPI_ListNodeTypes(t *testing.T) {
354-
355353
tests := []struct {
356354
name string
357355
response string

client/service/commands.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import (
44
"encoding/json"
55
"errors"
66
"fmt"
7-
"github.com/databrickslabs/databricks-terraform/client/model"
87
"log"
98
"net/http"
109
"time"
10+
11+
"github.com/databrickslabs/databricks-terraform/client/model"
1112
)
1213

1314
// CommandsAPI exposes the Context & Commands API
@@ -16,17 +17,17 @@ type CommandsAPI struct {
1617
}
1718

1819
// Execute creates a spark context and executes a command and then closes context
19-
func (a CommandsAPI) Execute(clusterID, langauge, commandStr string) (model.Command, error) {
20+
func (a CommandsAPI) Execute(clusterID, language, commandStr string) (model.Command, error) {
2021
var resp model.Command
21-
context, err := a.createContext(langauge, clusterID)
22+
context, err := a.createContext(language, clusterID)
2223
if err != nil {
2324
return resp, err
2425
}
2526
err = a.waitForContextReady(context, clusterID, 1, 10)
2627
if err != nil {
2728
return resp, err
2829
}
29-
commandID, err := a.createCommand(context, clusterID, langauge, commandStr)
30+
commandID, err := a.createCommand(context, clusterID, language, commandStr)
3031
if err != nil {
3132
return resp, err
3233
}

client/service/commands_integration_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package service
22

33
import (
4+
"testing"
5+
46
"github.com/databrickslabs/databricks-terraform/client/model"
57
"github.com/stretchr/testify/assert"
6-
"testing"
78
)
89

910
func TestContext(t *testing.T) {

client/service/commands_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package service
22

33
import (
4-
"github.com/databrickslabs/databricks-terraform/client/model"
54
"net/http"
65
"testing"
6+
7+
"github.com/databrickslabs/databricks-terraform/client/model"
78
)
89

910
func TestCommandsAPI_Execute(t *testing.T) {

client/service/dbfs.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package service
33
import (
44
"encoding/base64"
55
"encoding/json"
6-
"github.com/databrickslabs/databricks-terraform/client/model"
76
"log"
87
"net/http"
8+
9+
"github.com/databrickslabs/databricks-terraform/client/model"
910
)
1011

1112
// DBFSAPI exposes the DBFS API
@@ -53,7 +54,7 @@ func (a DBFSAPI) Read(path string) (string, error) {
5354
}
5455

5556
bytesFetched = append(bytesFetched, bytes...)
56-
offSet = offSet + length
57+
offSet += length
5758
}
5859
resp := base64.StdEncoding.EncodeToString(bytesFetched)
5960
return resp, nil
@@ -92,7 +93,7 @@ func (a DBFSAPI) Copy(src string, tgt string, client *DBApiClient, overwrite boo
9293
return err
9394
}
9495

95-
offSet = offSet + length
96+
offSet += length
9697
}
9798

9899
return err
@@ -287,7 +288,7 @@ func split(buf []byte, lim int) [][]byte {
287288
chunks = append(chunks, chunk)
288289
}
289290
if len(buf) > 0 {
290-
chunks = append(chunks, buf[:])
291+
chunks = append(chunks, buf)
291292
}
292293
return chunks
293294
}

client/service/dbfs_integration_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ package service
33
import (
44
"bytes"
55
"encoding/base64"
6-
"github.com/stretchr/testify/assert"
76
"testing"
7+
8+
"github.com/stretchr/testify/assert"
89
)
910

1011
func GenString(times int) []byte {

client/service/groups.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import (
44
"encoding/json"
55
"errors"
66
"fmt"
7-
"github.com/databrickslabs/databricks-terraform/client/model"
87
"log"
98
"net/http"
109
"sort"
10+
11+
"github.com/databrickslabs/databricks-terraform/client/model"
1112
)
1213

1314
// GroupsAPI exposes the scim groups API
@@ -77,7 +78,7 @@ func (a GroupsAPI) Read(groupID string) (model.Group, error) {
7778
}
7879
groups = append(groups, inheritedGroupFull)
7980
}
80-
inherited, unInherited, err := a.getInheritedAndNonInheritedRoles(group, groups)
81+
inherited, unInherited := a.getInheritedAndNonInheritedRoles(group, groups)
8182
group.InheritedRoles = inherited
8283
group.UnInheritedRoles = unInherited
8384

@@ -154,7 +155,7 @@ func (a GroupsAPI) Delete(groupID string) error {
154155
return err
155156
}
156157

157-
func (a GroupsAPI) getInheritedAndNonInheritedRoles(group model.Group, groups []model.Group) (inherited []model.RoleListItem, unInherited []model.RoleListItem, err error) {
158+
func (a GroupsAPI) getInheritedAndNonInheritedRoles(group model.Group, groups []model.Group) (inherited []model.RoleListItem, unInherited []model.RoleListItem) {
158159
allRoles := group.Roles
159160
var inheritedRoles []model.RoleListItem
160161
inheritedRolesKeys := []string{}
@@ -175,5 +176,5 @@ func (a GroupsAPI) getInheritedAndNonInheritedRoles(group model.Group, groups []
175176
unInherited = append(unInherited, role)
176177
}
177178
}
178-
return inherited, unInherited, nil
179+
return inherited, unInherited
179180
}

client/service/groups_integration_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package service
22

33
import (
44
"fmt"
5+
"testing"
6+
57
"github.com/databrickslabs/databricks-terraform/client/model"
68
"github.com/stretchr/testify/assert"
7-
"testing"
89
)
910

1011
func TestFmt(t *testing.T) {
@@ -110,5 +111,4 @@ func TestReadInheritedRolesFromGroup(t *testing.T) {
110111
}
111112
return false
112113
}(myTestGroupInfo.InheritedRoles, myTestRole))
113-
114114
}

client/service/groups_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package service
22

33
import (
4-
"github.com/databrickslabs/databricks-terraform/client/model"
54
"net/http"
65
"testing"
6+
7+
"github.com/databrickslabs/databricks-terraform/client/model"
78
)
89

910
func TestScimGroupAPI_Create(t *testing.T) {

client/service/instance_pools.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package service
22

33
import (
44
"encoding/json"
5-
"github.com/databrickslabs/databricks-terraform/client/model"
65
"net/http"
6+
7+
"github.com/databrickslabs/databricks-terraform/client/model"
78
)
89

910
// InstancePoolsAPI exposes the instance pools api

0 commit comments

Comments
 (0)