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

cleaned up the files and added golanglintci file #102

Merged
merged 3 commits into from
Jun 15, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 35 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
run:
deadline: 10m10s
modules-download-mode: vendor

issues:
max-per-linter: 0
max-same-issues: 0

linters:
disable-all: true
enable:
- deadcode
- errcheck
- gocritic
- gofmt
- goimports
- gosimple
- govet
- ineffassign
- interfacer
- nakedret
- misspell
- staticcheck
- structcheck
- typecheck
- unused
- unconvert
- varcheck
- vet
- vetshadow
- whitespace

linters-settings:
errcheck:
ignore: github.com/hashicorp/terraform-plugin-sdk/helper/schema:ForceNew|Set,fmt:.*,io:Close
23 changes: 14 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
default: build

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

Expand All @@ -26,35 +26,40 @@ coverage-int: int

int-build: int build

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

lint:
@echo "==> Linting source code with golangci-lint..."
@golangci-lint run --skip-dirs-use-default --timeout 5m --build-tags=azure
@golangci-lint run --skip-dirs-use-default --timeout 5m --build-tags=aws
@echo "==> Linting source code with golangci-lint make sure you run make fmt ..."
@golangci-lint run --skip-dirs-use-default --timeout 5m

fmt: lint
fmt:
@echo "==> Formatting source code with gofmt..."
@goimports -w client
@goimports -w databricks
@goimports -w main.go
@gofmt -s -w client
@gofmt -s -w databricks
@gofmt -s -w main.go
@go fmt ./...

vendor:
@echo "==> Filling vendor folder with library code..."
@go mod vendor

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

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

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

Expand Down
4 changes: 2 additions & 2 deletions client/model/notebook.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package model

// Language is a custom type for langauge types in Databricks notebooks
// Language is a custom type for language types in Databricks notebooks
type Language string

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

// Different types of langauge formats available on Databricks
// Different types of language formats available on Databricks
const (
Scala Language = "SCALA"
Python Language = "PYTHON"
Expand Down
4 changes: 1 addition & 3 deletions client/service/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (c *DBApiClientConfig) Setup() {
retryMaximumDuration := 5 * time.Minute
c.client = &retryablehttp.Client{
HTTPClient: &http.Client{
Timeout: time.Duration(time.Duration(c.TimeoutSeconds) * time.Second),
Timeout: time.Duration(c.TimeoutSeconds) * time.Second,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: c.InsecureSkipVerify,
Expand Down Expand Up @@ -292,7 +292,6 @@ func PerformQuery(config *DBApiClientConfig, method, path string, apiVersion str
}
requestURL += "?" + params.Encode()
auditGetPayload(requestURL, secretsMask)

} else {
if marshalJSON {
bodyBytes, err := json.Marshal(data)
Expand All @@ -303,7 +302,6 @@ func PerformQuery(config *DBApiClientConfig, method, path string, apiVersion str
requestBody = bodyBytes
} else {
requestBody = []byte(data.(string))

}
auditNonGetPayload(method, requestURL, data, secretsMask)
}
Expand Down
3 changes: 2 additions & 1 deletion client/service/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package service
import (
"encoding/json"
"errors"
"github.com/databrickslabs/databricks-terraform/client/model"
"log"
"net/http"
"time"

"github.com/databrickslabs/databricks-terraform/client/model"
)

// ClustersAPI is a struct that contains the Databricks api client to perform queries
Expand Down
6 changes: 3 additions & 3 deletions client/service/clusters_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package service

import (
"github.com/databrickslabs/databricks-terraform/client/model"
"github.com/stretchr/testify/assert"
"reflect"
"testing"

"github.com/databrickslabs/databricks-terraform/client/model"
"github.com/stretchr/testify/assert"
)

func TestListClustersIntegration(t *testing.T) {
Expand Down Expand Up @@ -72,5 +73,4 @@ func TestListClustersIntegration(t *testing.T) {
clusterReadInfo, err = client.Clusters().Get(clusterInfo.ClusterID)
assert.NoError(t, err, err)
assert.True(t, clusterReadInfo.State == model.ClusterStateRunning)

}
6 changes: 2 additions & 4 deletions client/service/clusters_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package service

import (
"github.com/databrickslabs/databricks-terraform/client/model"
"net/http"
"testing"
"time"

"github.com/databrickslabs/databricks-terraform/client/model"
)

func TestClustersAPI_Create(t *testing.T) {
Expand Down Expand Up @@ -226,7 +227,6 @@ func TestClustersAPI_Get(t *testing.T) {
}

func TestClustersAPI_List(t *testing.T) {

tests := []struct {
name string
response string
Expand Down Expand Up @@ -302,7 +302,6 @@ func TestClustersAPI_List(t *testing.T) {
}

func TestClustersAPI_ListZones(t *testing.T) {

tests := []struct {
name string
response string
Expand Down Expand Up @@ -351,7 +350,6 @@ func TestClustersAPI_ListZones(t *testing.T) {
}

func TestClustersAPI_ListNodeTypes(t *testing.T) {

tests := []struct {
name string
response string
Expand Down
9 changes: 5 additions & 4 deletions client/service/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/databrickslabs/databricks-terraform/client/model"
"log"
"net/http"
"time"

"github.com/databrickslabs/databricks-terraform/client/model"
)

// CommandsAPI exposes the Context & Commands API
Expand All @@ -16,17 +17,17 @@ type CommandsAPI struct {
}

// Execute creates a spark context and executes a command and then closes context
func (a CommandsAPI) Execute(clusterID, langauge, commandStr string) (model.Command, error) {
func (a CommandsAPI) Execute(clusterID, language, commandStr string) (model.Command, error) {
var resp model.Command
context, err := a.createContext(langauge, clusterID)
context, err := a.createContext(language, clusterID)
if err != nil {
return resp, err
}
err = a.waitForContextReady(context, clusterID, 1, 10)
if err != nil {
return resp, err
}
commandID, err := a.createCommand(context, clusterID, langauge, commandStr)
commandID, err := a.createCommand(context, clusterID, language, commandStr)
if err != nil {
return resp, err
}
Expand Down
3 changes: 2 additions & 1 deletion client/service/commands_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package service

import (
"testing"

"github.com/databrickslabs/databricks-terraform/client/model"
"github.com/stretchr/testify/assert"
"testing"
)

func TestContext(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion client/service/commands_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package service

import (
"github.com/databrickslabs/databricks-terraform/client/model"
"net/http"
"testing"

"github.com/databrickslabs/databricks-terraform/client/model"
)

func TestCommandsAPI_Execute(t *testing.T) {
Expand Down
9 changes: 5 additions & 4 deletions client/service/dbfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package service
import (
"encoding/base64"
"encoding/json"
"github.com/databrickslabs/databricks-terraform/client/model"
"log"
"net/http"

"github.com/databrickslabs/databricks-terraform/client/model"
)

// DBFSAPI exposes the DBFS API
Expand Down Expand Up @@ -53,7 +54,7 @@ func (a DBFSAPI) Read(path string) (string, error) {
}

bytesFetched = append(bytesFetched, bytes...)
offSet = offSet + length
offSet += length
}
resp := base64.StdEncoding.EncodeToString(bytesFetched)
return resp, nil
Expand Down Expand Up @@ -92,7 +93,7 @@ func (a DBFSAPI) Copy(src string, tgt string, client *DBApiClient, overwrite boo
return err
}

offSet = offSet + length
offSet += length
}

return err
Expand Down Expand Up @@ -287,7 +288,7 @@ func split(buf []byte, lim int) [][]byte {
chunks = append(chunks, chunk)
}
if len(buf) > 0 {
chunks = append(chunks, buf[:])
chunks = append(chunks, buf)
}
return chunks
}
3 changes: 2 additions & 1 deletion client/service/dbfs_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package service
import (
"bytes"
"encoding/base64"
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func GenString(times int) []byte {
Expand Down
9 changes: 5 additions & 4 deletions client/service/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/databrickslabs/databricks-terraform/client/model"
"log"
"net/http"
"sort"

"github.com/databrickslabs/databricks-terraform/client/model"
)

// GroupsAPI exposes the scim groups API
Expand Down Expand Up @@ -77,7 +78,7 @@ func (a GroupsAPI) Read(groupID string) (model.Group, error) {
}
groups = append(groups, inheritedGroupFull)
}
inherited, unInherited, err := a.getInheritedAndNonInheritedRoles(group, groups)
inherited, unInherited := a.getInheritedAndNonInheritedRoles(group, groups)
group.InheritedRoles = inherited
group.UnInheritedRoles = unInherited

Expand Down Expand Up @@ -154,7 +155,7 @@ func (a GroupsAPI) Delete(groupID string) error {
return err
}

func (a GroupsAPI) getInheritedAndNonInheritedRoles(group model.Group, groups []model.Group) (inherited []model.RoleListItem, unInherited []model.RoleListItem, err error) {
func (a GroupsAPI) getInheritedAndNonInheritedRoles(group model.Group, groups []model.Group) (inherited []model.RoleListItem, unInherited []model.RoleListItem) {
allRoles := group.Roles
var inheritedRoles []model.RoleListItem
inheritedRolesKeys := []string{}
Expand All @@ -175,5 +176,5 @@ func (a GroupsAPI) getInheritedAndNonInheritedRoles(group model.Group, groups []
unInherited = append(unInherited, role)
}
}
return inherited, unInherited, nil
return inherited, unInherited
}
4 changes: 2 additions & 2 deletions client/service/groups_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package service

import (
"fmt"
"testing"

"github.com/databrickslabs/databricks-terraform/client/model"
"github.com/stretchr/testify/assert"
"testing"
)

func TestFmt(t *testing.T) {
Expand Down Expand Up @@ -110,5 +111,4 @@ func TestReadInheritedRolesFromGroup(t *testing.T) {
}
return false
}(myTestGroupInfo.InheritedRoles, myTestRole))

}
3 changes: 2 additions & 1 deletion client/service/groups_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package service

import (
"github.com/databrickslabs/databricks-terraform/client/model"
"net/http"
"testing"

"github.com/databrickslabs/databricks-terraform/client/model"
)

func TestScimGroupAPI_Create(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion client/service/instance_pools.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package service

import (
"encoding/json"
"github.com/databrickslabs/databricks-terraform/client/model"
"net/http"

"github.com/databrickslabs/databricks-terraform/client/model"
)

// InstancePoolsAPI exposes the instance pools api
Expand Down