Skip to content

Commit

Permalink
Add golangci-lint to CI (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mongey authored Dec 17, 2020
1 parent 3162581 commit 98e0be0
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 14 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
1 change: 0 additions & 1 deletion kafka/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ func newTLSConfig(clientCert, clientKey, caCert, clientKeyPassphrase string) (*t
}

tlsConfig.RootCAs = caCertPool
tlsConfig.BuildNameToCertificate()
return &tlsConfig, nil
}

Expand Down
13 changes: 3 additions & 10 deletions kafka/kafka_acls.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
1 change: 0 additions & 1 deletion kafka/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
31 changes: 25 additions & 6 deletions kafka/resource_kafka_acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,31 +119,50 @@ func aclRead(d *schema.ResourceData, meta interface{}) error {
Name: foundACLs.ResourceName,
},
}

// exact match
if a.String() == aclID.String() {
aclNotFound = false
return nil
}

// partial match -> update state
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{
Expand Down
17 changes: 9 additions & 8 deletions kafka/resource_kafka_topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
Expand All @@ -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
}
3 changes: 2 additions & 1 deletion tls-debug/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ func fauxMain() error {
if err != nil {
return err
}
err = c.Handshake()

return c.Handshake()
}

return nil
Expand Down

0 comments on commit 98e0be0

Please sign in to comment.