From 98e0be0582353fdf194b9460c2b298da28928053 Mon Sep 17 00:00:00 2001 From: Conor Mongey Date: Thu, 17 Dec 2020 23:38:12 +0000 Subject: [PATCH] Add golangci-lint to CI (#160) --- .github/workflows/release.yml | 2 +- .github/workflows/snapshot.yml | 2 +- .github/workflows/test.yml | 17 ++++++++++++++--- kafka/config.go | 1 - kafka/kafka_acls.go | 13 +++---------- kafka/provider_test.go | 1 - kafka/resource_kafka_acl.go | 31 +++++++++++++++++++++++++------ kafka/resource_kafka_topic.go | 17 +++++++++-------- tls-debug/main.go | 3 ++- 9 files changed, 55 insertions(+), 32 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1b990148..f4b5f1dd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v2 - name: Set up Go uses: actions/setup-go@v1 with: diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml index f93ac053..b198cab1 100644 --- a/.github/workflows/snapshot.yml +++ b/.github/workflows/snapshot.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v2 - name: Set up Go uses: actions/setup-go@v1 with: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5b70d241..b2f837f2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v2 - name: Set up Go uses: actions/setup-go@v1 with: @@ -23,17 +23,28 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2.0.0 + - uses: actions/checkout@v2 - uses: bflad/tfproviderlint-github-action@master with: args: ./... + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. + version: v1.29 + acctest: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v2 - name: Set up Go uses: actions/setup-go@v1 with: diff --git a/kafka/config.go b/kafka/config.go index 1df13ed5..0876f8b9 100644 --- a/kafka/config.go +++ b/kafka/config.go @@ -161,7 +161,6 @@ func newTLSConfig(clientCert, clientKey, caCert, clientKeyPassphrase string) (*t } tlsConfig.RootCAs = caCertPool - tlsConfig.BuildNameToCertificate() return &tlsConfig, nil } diff --git a/kafka/kafka_acls.go b/kafka/kafka_acls.go index 612ff88e..bdc59cc9 100644 --- a/kafka/kafka_acls.go +++ b/kafka/kafka_acls.go @@ -352,14 +352,8 @@ func (c *Client) DescribeACLs(s StringlyTypedACL) ([]*sarama.ResourceAcls, error return nil, fmt.Errorf("%s", aclsR.Err) } } - res := []*sarama.ResourceAcls{} - - for _, a := range aclsR.ResourceAcls { - res = append(res, a) - } - - return res, err + return aclsR.ResourceAcls, err } func (c *Client) ListACLs() ([]*sarama.ResourceAcls, error) { @@ -424,9 +418,8 @@ func (c *Client) ListACLs() ([]*sarama.ResourceAcls, error) { } } - for _, a := range aclsR.ResourceAcls { - res = append(res, a) - } + res = append(res, aclsR.ResourceAcls...) } + return res, err } diff --git a/kafka/provider_test.go b/kafka/provider_test.go index 59e52510..f15eec6a 100644 --- a/kafka/provider_test.go +++ b/kafka/provider_test.go @@ -11,7 +11,6 @@ import ( ) var testProvider *schema.Provider -var testProviders map[string]terraform.ResourceProvider func TestProvider(t *testing.T) { if err := Provider().(*schema.Provider).InternalValidate(); err != nil { diff --git a/kafka/resource_kafka_acl.go b/kafka/resource_kafka_acl.go index ed61720a..953f2aad 100644 --- a/kafka/resource_kafka_acl.go +++ b/kafka/resource_kafka_acl.go @@ -119,9 +119,9 @@ func aclRead(d *schema.ResourceData, meta interface{}) error { Name: foundACLs.ResourceName, }, } + // exact match if a.String() == aclID.String() { - aclNotFound = false return nil } @@ -129,21 +129,40 @@ func aclRead(d *schema.ResourceData, meta interface{}) error { if a.ACL.Principal == aclID.ACL.Principal && a.ACL.Operation == aclID.ACL.Operation { aclNotFound = false - d.Set("acl_principal", acl.Principal) - d.Set("acl_host", acl.Host) - d.Set("acl_operation", acl.Operation) - d.Set("acl_permission_type", acl.PermissionType) - d.Set("resource_pattern_type_filter", foundACLs.ResourcePatternType) + errSet := errSetter{d: d} + errSet.Set("acl_principal", acl.Principal) + errSet.Set("acl_host", acl.Host) + errSet.Set("acl_operation", acl.Operation) + errSet.Set("acl_permission_type", acl.PermissionType) + errSet.Set("resource_pattern_type_filter", foundACLs.ResourcePatternType) + if errSet.err != nil { + return err + } } } } + if aclNotFound { log.Printf("[INFO] Did not find ACL %s", a.String()) d.SetId("") } + return nil } +type errSetter struct { + err error + d *schema.ResourceData +} + +func (es *errSetter) Set(key string, value interface{}) { + if es.err != nil { + return + } + //lintignore:R001 + es.err = es.d.Set(key, value) +} + func aclInfo(d *schema.ResourceData) StringlyTypedACL { s := StringlyTypedACL{ ACL: ACL{ diff --git a/kafka/resource_kafka_topic.go b/kafka/resource_kafka_topic.go index 6e01b3f8..46b9835b 100644 --- a/kafka/resource_kafka_topic.go +++ b/kafka/resource_kafka_topic.go @@ -192,15 +192,16 @@ func topicRead(d *schema.ResourceData, meta interface{}) error { } log.Printf("[DEBUG] Setting the state from Kafka %v", topic) - d.Set("name", topic.Name) - d.Set("partitions", topic.Partitions) - d.Set("replication_factor", topic.ReplicationFactor) - d.Set("config", topic.Config) + errSet := errSetter{d: d} + errSet.Set("name", topic.Name) + errSet.Set("partitions", topic.Partitions) + errSet.Set("replication_factor", topic.ReplicationFactor) + errSet.Set("config", topic.Config) - return nil + return errSet.err } -func customPartitionDiff(diff *schema.ResourceDiff, v interface{}) error { +func customPartitionDiff(diff *schema.ResourceDiff, v interface{}) (err error) { log.Printf("[INFO] Checking the diff!") if diff.HasChange("partitions") { log.Printf("[INFO] Partitions have changed!") @@ -210,9 +211,9 @@ func customPartitionDiff(diff *schema.ResourceDiff, v interface{}) error { log.Printf("Partitions is changing from %d to %d", oi, ni) if ni < oi { log.Printf("Partitions decreased from %d to %d. Forcing new resource", oi, ni) - diff.ForceNew("partitions") + err = diff.ForceNew("partitions") } } - return nil + return err } diff --git a/tls-debug/main.go b/tls-debug/main.go index b6e39f69..104da817 100644 --- a/tls-debug/main.go +++ b/tls-debug/main.go @@ -108,7 +108,8 @@ func fauxMain() error { if err != nil { return err } - err = c.Handshake() + + return c.Handshake() } return nil