Skip to content

Commit

Permalink
feat: use golangci lint action (#528)
Browse files Browse the repository at this point in the history
  • Loading branch information
gssbzn committed Aug 25, 2021
1 parent fced21d commit daafcf6
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 32 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/automated-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ jobs:
uses: actions/setup-go@v2
with:
go-version: 1.16
- name: Code Lint
run: make tools && make lint
- name: Website
run: make tools && make website-lint
- name: Test
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
name: golangci-lint
on:
push:
branches:
- master
pull_request:
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2.5.2
with:
version: v1.41.1
args: --timeout 5m0s
11 changes: 8 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ linters-settings:
settings:
mnd:
# don't include the "operation" and "assign"
checks: case,return
checks: [case,return]
funlen:
lines: 360
statements: 120
Expand Down Expand Up @@ -134,6 +134,11 @@ issues:
text: "SA1019:" # d.GetOkExists is deprecated: usage is discouraged due to undefined behaviors and may be removed in a future version of the SDK

run:
# which dirs to skip: they won't be analyzed;
tests: true
build-tags:
- e2e
- unit
- integration
skip-dirs:
- vendor
- internal/mocks
modules-download-mode: readonly
12 changes: 7 additions & 5 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
TEST?=$$(go list ./... | grep -v /integration-testing)
TEST?=$$(go list ./... | grep -v /integrationtesting)
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
PKG_NAME=mongodbatlas
WEBSITE_REPO=github.com/hashicorp/terraform-website

GOFLAGS=-mod=vendor
GOGC=10
GOOPTS="-p 2"

GITTAG=$(shell git describe --always --tags)
Expand Down Expand Up @@ -40,10 +39,13 @@ fmtcheck:
websitefmtcheck:
@sh -c "'$(CURDIR)/scripts/websitefmtcheck.sh'"

lint-fix:
@echo "==> Checking source code against linters..."
golangci-lint run --fix

lint:
@echo "==> Checking source code against linters..."
# https://github.com/golangci/golangci-lint/issues/337 fixing error
golangci-lint run ./$(PKG_NAME) -v --deadline=30m
golangci-lint run

tools: ## Install dev tools
@echo "==> Installing dependencies..."
Expand Down Expand Up @@ -82,4 +84,4 @@ endif

terratest: fmtcheck
@$(eval VERSION=acc)
go test $$(go list ./... | grep /integration-testing) -v -parallel 20 $(TESTARGS) -timeout 120m -cover -ldflags="$(LINKER_FLAGS)"
go test $$(go list ./... | grep /integrationtesting) -v -parallel 20 $(TESTARGS) -timeout 120m -cover -ldflags="$(LINKER_FLAGS)"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ We'd like to thank [Akshay Karle](https://github.com/akshaykarle) for writing th

# Running the integration tests

The integration tests helps the validation for resources interacting with third party providers (aws, azure or gcp) using terratest [environment setup details](integration-testing/README.md)
The integration tests helps the validation for resources interacting with third party providers (aws, azure or gcp) using terratest [environment setup details](integrationtesting/README.md)

```
cd integration-testing
cd integrationtesting
go test -tags=integration
```
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package integration_testing
package integrationtesting

import "os"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//go:build integration
// +build integration

package integration_testing
package integrationtesting

import (
"os"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package integration_testing
package integrationtesting

import (
"fmt"
Expand Down Expand Up @@ -86,5 +86,4 @@ func TestTerraformResourceMongoDBAtlasDataLake_basicAWS(t *testing.T) {
terraform.RunTerraformCommand(t, terraformOptionsSecond, "import", "mongodbatlas_data_lake.test", fmt.Sprintf("%s--%s--%s", projectID, lakeName, s3Bucket))

terraform.Plan(t, terraformOptionsSecond)

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//go:build integration
// +build integration

package integration_testing
package integrationtesting

import (
"fmt"
Expand Down Expand Up @@ -81,5 +82,4 @@ func TestTerraformResourceMongoDBAtlasEncryptionAtRestWithRole_basicAWS(t *testi

// Run `terraform apply`. Fail the test if there are any errors.
terraform.InitAndApply(t, terraformOptionsSecond)

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package integration_testing
package integrationtesting

import (
"context"
Expand Down Expand Up @@ -73,7 +73,6 @@ func TestUpgradeNetworkContainerRegionsGCP(t *testing.T) {
terraform.RunTerraformCommand(t, terraformOptionsSecond, "import", "mongodbatlas_network_container.test", fmt.Sprintf("%s-%s", projectID, networkContainerID))
// Run `terraform apply`. Fail the test if there are any errors.
terraform.Plan(t, terraformOptionsSecond)

}

func TestUpgradeDatabaseUserLDAPAuthType(t *testing.T) {
Expand Down Expand Up @@ -128,12 +127,11 @@ func TestUpgradeDatabaseUserLDAPAuthType(t *testing.T) {
})

terraform.RunTerraformCommand(t, terraformOptionsSecond, "init", fmt.Sprintf("--plugin-dir=%s", localPluginPath))
//Remove states
// Remove states
terraform.RunTerraformCommand(t, terraformOptionsSecond, "import", "mongodbatlas_project.test", projectID)
terraform.RunTerraformCommand(t, terraformOptionsSecond, "import", "mongodbatlas_database_user.test", fmt.Sprintf("%s-%s-%s", projectID, userName, authDatabaseName))
// Run `terraform apply`. Fail the test if there are any errors.
terraform.Plan(t, terraformOptionsSecond)

}

func testAccGetMongoDBAtlasMajorVersion() string {
Expand Down Expand Up @@ -194,12 +192,11 @@ func TestUpgradeClusterDeprecationEBSVolume(t *testing.T) {
})

terraform.RunTerraformCommand(t, terraformOptionsSecond, "init", fmt.Sprintf("--plugin-dir=%s", localPluginPath))
//Remove states
// Remove states
terraform.RunTerraformCommand(t, terraformOptionsSecond, "import", "mongodbatlas_project.test", projectID)
terraform.RunTerraformCommand(t, terraformOptionsSecond, "import", "mongodbatlas_cluster.test", fmt.Sprintf("%s-%s", projectID, clusterNameOutput))
// Run `terraform apply`. Fail the test if there are any errors.
terraform.Plan(t, terraformOptionsSecond)

}

func TestUpgradePrivateEndpoint(t *testing.T) {
Expand Down Expand Up @@ -268,14 +265,13 @@ func TestUpgradePrivateEndpoint(t *testing.T) {
})

terraform.RunTerraformCommand(t, terraformOptionsSecond, "init")
//Remove states
// Remove states
terraform.RunTerraformCommand(t, terraformOptionsSecond, "import", "mongodbatlas_project.test", projectID)
terraform.RunTerraformCommand(t, terraformOptionsSecond, "import", "mongodbatlas_private_endpoint.test", fmt.Sprintf("%s-%s-%s-%s", projectID, privateEndpoint, "AWS", "us-east-1"))
terraform.RunTerraformCommand(t, terraformOptionsSecond, "import", "aws_vpc_endpoint.ptfe_service", vpcEndpoint)
terraform.RunTerraformCommand(t, terraformOptionsSecond, "import", "mongodbatlas_private_endpoint_interface_link.test", fmt.Sprintf("%s-%s-%s", projectID, privateEndpoint, vpcEndpoint))
// Run `terraform apply`. Fail the test if there are any errors.
terraform.Plan(t, terraformOptionsSecond)

}

func TestUpgradeProjectIPWhitelistDeprecation(t *testing.T) {
Expand Down Expand Up @@ -329,12 +325,11 @@ func TestUpgradeProjectIPWhitelistDeprecation(t *testing.T) {
})

terraform.RunTerraformCommand(t, terraformOptionsSecond, "init", fmt.Sprintf("--plugin-dir=%s", localPluginPath))
//Remove states
// Remove states
terraform.RunTerraformCommand(t, terraformOptionsSecond, "import", "mongodbatlas_project.test", projectID)
terraform.RunTerraformCommand(t, terraformOptionsSecond, "import", "mongodbatlas_project_ip_access_list.test", fmt.Sprintf("%s-%s", projectID, entry))
// Run `terraform apply`. Fail the test if there are any errors.
terraform.Plan(t, terraformOptionsSecond)

}

func TestUpgradeDesignIDState(t *testing.T) {
Expand Down Expand Up @@ -529,14 +524,13 @@ func TestUpgradePrivateLinkEndpointDeprecation(t *testing.T) {
})

terraform.RunTerraformCommand(t, terraformOptionsSecond, "init", fmt.Sprintf("--plugin-dir=%s", localPluginPath))
//Remove states
// Remove states
terraform.RunTerraformCommand(t, terraformOptionsSecond, "import", "mongodbatlas_project.test", projectID)
terraform.RunTerraformCommand(t, terraformOptionsSecond, "import", "mongodbatlas_privatelink_endpoint.test", fmt.Sprintf("%s-%s-%s-%s", projectID, privateEndpoint, "AWS", "us-east-1"))
terraform.RunTerraformCommand(t, terraformOptionsSecond, "import", "aws_vpc_endpoint.ptfe_service", vpcEndpoint)
terraform.RunTerraformCommand(t, terraformOptionsSecond, "import", "mongodbatlas_privatelink_endpoint_service.test", fmt.Sprintf("%s--%s--%s--%s", projectID, privateEndpoint, vpcEndpoint, "AWS"))
// Run `terraform apply`. Fail the test if there are any errors.
terraform.Plan(t, terraformOptionsSecond)

}

func TestUpgradeCloudBackupPolicies(t *testing.T) {
Expand Down Expand Up @@ -587,14 +581,13 @@ func TestUpgradeCloudBackupPolicies(t *testing.T) {
})

terraform.RunTerraformCommand(t, terraformOptionsSecond, "init", fmt.Sprintf("--plugin-dir=%s", localPluginPath))
//Remove states
// Remove states
terraform.RunTerraformCommand(t, terraformOptionsSecond, "import", "mongodbatlas_project.project_test", projectID)
terraform.RunTerraformCommand(t, terraformOptionsSecond, "import", "mongodbatlas_cluster.cluster_test", fmt.Sprintf("%s-%s", projectID, cluster))
terraform.RunTerraformCommand(t, terraformOptionsSecond, "import", "mongodbatlas_cloud_backup_schedule.test", fmt.Sprintf("%s-%s", projectID, cluster))
// Run `terraform apply`. Fail the test if there are any errors.

terraform.Plan(t, terraformOptionsSecond)

}

// This func means that the terraform state will be always clean to avoid error about resource already used
Expand Down

0 comments on commit daafcf6

Please sign in to comment.