Skip to content

Added golangci configuration and travis fix #248

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

Merged
merged 4 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
109 changes: 109 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
linters-settings:
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- octalLiteral
govet:
check-shadowing: true
golint:
min-confidence: 0
maligned:
suggest-new: true
depguard:
list-type: blacklist
packages:
# logging is allowed only by logutils.Log, logrus
# is allowed to use only in logutils package
- github.com/sirupsen/logrus
misspell:
locale: US
ignore-words:
- cancelled
lll:
# Default is 120. '\t' is counted as 1 character.
# set our project to 200, as things like v3_structs with inline comments end up being a touch long
# also, for anyone using vscode, use the following configs:
# "rewrap.wrappingColumn": 200 ... requires the rewrap plugin
# "editor.rulers": [200]
line-length: 200
nestif:
# minimal complexity of if statements to report, 5 by default
min-complexity: 7
gomnd:
settings:
mnd:
# don't include the "operation" and "assign"
checks: case,return
funlen:
lines: 360
statements: 120
linters:
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- errcheck
- funlen
- gocritic
- gofmt
- goimports
- golint
- gomnd
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- interfacer
- lll
- misspell
- nakedret
- nolintlint
- rowserrcheck
- scopelint
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unused
- varcheck
- whitespace
# don't enable:
# - gocyclo # we already have funlen lint
# - dupl # we have a lot of duplicate test cases
# - gochecknoinits # we need the init function for the provider
# - gochecknoglobals # we need some global variables
# - unparam # Forces to create global variables when one variable is repeated in different functions
# - goerr113 # It does not allow you to return an error, you need to save the error in a variable to do it
# - goconst
# - gocognit
issues:
exclude:
- composite literal uses unkeyed fields
- Using the variable on range scope .* in function literal
- declaration of ".*" shadows declaration at line .*
- only one cuddle assignment allowed before if statement
- func `testAccMongoDBAtlasCloudProviderSnapshotRestoreJobConfigPointInTime` is unused
exclude-rules:
- path: _test\.go
linters:
- testpackage
# part of the golangci govet package is picking up things that go vet doesn't. Seems flaky, shutting that specific error off

# Exclude some staticcheck messages
- linters:
- staticcheck
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;
skip-dirs:
- vendor
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ language: go
env:
global:
GOFLAGS=-mod=vendor

GOGC=10
GOOPTS="-p 2"
matrix:
fast_finish: true
allow_failures:
- go: tip
include:
- go: "1.13.x"
- go: "1.14.x"
name: "Code Lint"
script: make lint
- go: "1.13.x"
Expand Down
3 changes: 2 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ websitefmtcheck:

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

tools:
GO111MODULE=on go install github.com/client9/misspell/cmd/misspell
Expand Down
6 changes: 3 additions & 3 deletions mongodbatlas/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
matlasClient "go.mongodb.org/atlas/mongodbatlas"
)

//Config ...
// Config struct ...
type Config struct {
PublicKey string
PrivateKey string
}

//NewClient ...
// NewClient func...
func (c *Config) NewClient() interface{} {
// setup a transport to handle digest
transport := digest.NewTransport(c.PublicKey, c.PrivateKey)
Expand All @@ -25,6 +25,6 @@ func (c *Config) NewClient() interface{} {

client.Transport = logging.NewTransport("MongoDB Atlas", transport)

//Initialize the MongoDB Atlas API Client.
// Initialize the MongoDB Atlas API Client.
return matlasClient.NewClient(client)
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func dataSourceMongoDBAtlasAlertConfiguration() *schema.Resource {
}

func dataSourceMongoDBAtlasAlertConfigurationRead(d *schema.ResourceData, meta interface{}) error {
//Get client connection.
// Get client connection.
conn := meta.(*matlas.Client)
projectID := d.Get("project_id").(string)
alertID := d.Get("alert_configuration_id").(string)
Expand All @@ -197,18 +197,23 @@ func dataSourceMongoDBAtlasAlertConfigurationRead(d *schema.ResourceData, meta i
if err := d.Set("event_type", alert.EventTypeName); err != nil {
return fmt.Errorf(errorAlertConfSetting, "event_type", projectID, err)
}

if err := d.Set("created", alert.Created); err != nil {
return fmt.Errorf(errorAlertConfSetting, "created", projectID, err)
}

if err := d.Set("updated", alert.Updated); err != nil {
return fmt.Errorf(errorAlertConfSetting, "updated", projectID, err)
}

if err := d.Set("matcher", flattenAlertConfigurationMatchers(alert.Matchers)); err != nil {
return fmt.Errorf(errorAlertConfSetting, "matcher", projectID, err)
}

if err := d.Set("metric_threshold", flattenAlertConfigurationMetricThreshold(alert.MetricThreshold)); err != nil {
return fmt.Errorf(errorAlertConfSetting, "metric_threshold", projectID, err)
}

if err := d.Set("notification", flattenAlertConfigurationNotifications(alert.Notifications)); err != nil {
return fmt.Errorf(errorAlertConfSetting, "notification", projectID, err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (
)

func TestAccDataSourceMongoDBAtlaAlertConfiguration_basic(t *testing.T) {
var alert = &matlas.AlertConfiguration{}

dataSourceName := "data.mongodbatlas_alert_configuration.test"
projectID := os.Getenv("MONGODB_ATLAS_PROJECT_ID")
var (
alert = &matlas.AlertConfiguration{}
dataSourceName = "data.mongodbatlas_alert_configuration.test"
projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID")
)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -29,7 +30,6 @@ func TestAccDataSourceMongoDBAtlaAlertConfiguration_basic(t *testing.T) {
},
},
})

}

func testAccDSMongoDBAtlasAlertConfiguration(projectID string) string {
Expand All @@ -38,21 +38,21 @@ func testAccDSMongoDBAtlasAlertConfiguration(projectID string) string {
project_id = "%s"
event_type = "OUTSIDE_METRIC_THRESHOLD"
enabled = true

notification {
type_name = "GROUP"
interval_min = 5
delay_min = 0
sms_enabled = false
email_enabled = true
}

matcher {
field_name = "HOSTNAME_AND_PORT"
operator = "EQUALS"
value = "SECONDARY"
}

metric_threshold = {
metric_name = "ASSERT_REGULAR"
operator = "LESS_THAN"
Expand All @@ -61,7 +61,7 @@ func testAccDSMongoDBAtlasAlertConfiguration(projectID string) string {
mode = "AVERAGE"
}
}

data "mongodbatlas_alert_configuration" "test" {
project_id = "${mongodbatlas_alert_configuration.test.project_id}"
alert_configuration_id = "${mongodbatlas_alert_configuration.test.alert_configuration_id}"
Expand Down
5 changes: 4 additions & 1 deletion mongodbatlas/data_source_mongodbatlas_auditing.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func dataSourceMongoDBAtlasAuditing() *schema.Resource {

func dataSourceMongoDBAtlasAuditingRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*matlas.Client)

projectID := d.Get("project_id").(string)

auditing, _, err := conn.Auditing.Get(context.Background(), projectID)
Expand All @@ -50,16 +49,20 @@ func dataSourceMongoDBAtlasAuditingRead(d *schema.ResourceData, meta interface{}
if err := d.Set("audit_authorization_success", auditing.AuditAuthorizationSuccess); err != nil {
return fmt.Errorf(errorAuditingRead, projectID, err)
}

if err := d.Set("audit_filter", auditing.AuditFilter); err != nil {
return fmt.Errorf(errorAuditingRead, projectID, err)
}

if err := d.Set("enabled", auditing.Enabled); err != nil {
return fmt.Errorf(errorAuditingRead, projectID, err)
}

if err := d.Set("configuration_type", auditing.ConfigurationType); err != nil {
return fmt.Errorf(errorAuditingRead, projectID, err)
}

d.SetId(projectID)

return nil
}
15 changes: 8 additions & 7 deletions mongodbatlas/data_source_mongodbatlas_auditing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import (
)

func TestAccDataSourceMongoDBAtlasAuditing_basic(t *testing.T) {
var auditing matlas.Auditing
dataSourceName := "data.mongodbatlas_auditing.test"

projectID := os.Getenv("MONGODB_ATLAS_PROJECT_ID")
auditAuth := true
auditFilter := "{ 'atype': 'authenticate', 'param': { 'user': 'auditAdmin', 'db': 'admin', 'mechanism': 'SCRAM-SHA-1' }}"
enabled := true
var (
auditing matlas.Auditing
dataSourceName = "data.mongodbatlas_auditing.test"
projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID")
auditAuth = true
auditFilter = "{ 'atype': 'authenticate', 'param': { 'user': 'auditAdmin', 'db': 'admin', 'mechanism': 'SCRAM-SHA-1' }}"
enabled = true
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,35 @@ func dataSourceMongoDBAtlasCloudProviderSnapshotRead(d *schema.ResourceData, met
if err = d.Set("created_at", snapshotRes.CreatedAt); err != nil {
return fmt.Errorf("error setting `created_at` for cloudProviderSnapshot (%s): %s", d.Id(), err)
}

if err = d.Set("description", snapshotRes.Description); err != nil {
return fmt.Errorf("error setting `description` for cloudProviderSnapshot (%s): %s", d.Id(), err)
}

if err = d.Set("expires_at", snapshotRes.ExpiresAt); err != nil {
return fmt.Errorf("error setting `expires_at` for cloudProviderSnapshot (%s): %s", d.Id(), err)
}

if err = d.Set("master_key_uuid", snapshotRes.MasterKeyUUID); err != nil {
return fmt.Errorf("error setting `master_key_uuid` for cloudProviderSnapshot (%s): %s", d.Id(), err)
}

if err = d.Set("mongod_version", snapshotRes.MongodVersion); err != nil {
return fmt.Errorf("error setting `mongod_version` for cloudProviderSnapshot (%s): %s", d.Id(), err)
}

if err = d.Set("snapshot_type", snapshotRes.SnapshotType); err != nil {
return fmt.Errorf("error setting `snapshot_type` for cloudProviderSnapshot (%s): %s", d.Id(), err)
}

if err = d.Set("status", snapshotRes.Status); err != nil {
return fmt.Errorf("error setting `status` for cloudProviderSnapshot (%s): %s", d.Id(), err)
}

if err = d.Set("storage_size_bytes", snapshotRes.StorageSizeBytes); err != nil {
return fmt.Errorf("error setting `storage_size_bytes` for cloudProviderSnapshot (%s): %s", d.Id(), err)
}

if err = d.Set("type", snapshotRes.Type); err != nil {
return fmt.Errorf("error setting `type` for cloudProviderSnapshot (%s): %s", d.Id(), err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,27 @@ func dataSourceMongoDBAtlasCloudProviderSnapshotBackupPolicyRead(d *schema.Resou
if err := d.Set("cluster_id", backupPolicy.ClusterID); err != nil {
return fmt.Errorf(errorSnapshotBackupPolicySetting, "cluster_id", clusterName, err)
}

if err := d.Set("reference_hour_of_day", backupPolicy.ReferenceHourOfDay); err != nil {
return fmt.Errorf(errorSnapshotBackupPolicySetting, "reference_hour_of_day", clusterName, err)
}

if err := d.Set("reference_minute_of_hour", backupPolicy.ReferenceMinuteOfHour); err != nil {
return fmt.Errorf(errorSnapshotBackupPolicySetting, "reference_minute_of_hour", clusterName, err)
}

if err := d.Set("restore_window_days", backupPolicy.RestoreWindowDays); err != nil {
return fmt.Errorf(errorSnapshotBackupPolicySetting, "restore_window_days", clusterName, err)
}

if err := d.Set("update_snapshots", backupPolicy.UpdateSnapshots); err != nil {
return fmt.Errorf(errorSnapshotBackupPolicySetting, "update_snapshots", clusterName, err)
}

if err := d.Set("next_snapshot", backupPolicy.NextSnapshot); err != nil {
return fmt.Errorf(errorSnapshotBackupPolicySetting, "next_snapshot", clusterName, err)
}

if err := d.Set("policies", flattenPolicies(backupPolicy.Policies)); err != nil {
return fmt.Errorf(errorSnapshotBackupPolicySetting, "policies", clusterName, err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func testAccMongoDBAtlasDataSourceCloudProviderSnapshotBackupPolicyConfig(projec
name = "%s"
disk_size_gb = 5

//Provider Settings "block"
// Provider Settings "block"
provider_name = "AWS"
provider_region_name = "EU_CENTRAL_1"
provider_instance_size_name = "M10"
Expand Down
Loading