Skip to content

Commit

Permalink
Merge #5904
Browse files Browse the repository at this point in the history
5904: [Backport stable/0.25] use golangci action r=MiguelPires a=MiguelPires

## Description

Backport of #5826 to stable/0.25.

Co-authored-by: Miguel Pires <miguel.pires@camunda.com>
  • Loading branch information
zeebe-bors[bot] and Miguel Pires authored Nov 23, 2020
2 parents e5310ec + e6d181c commit a45915c
Show file tree
Hide file tree
Showing 26 changed files with 86 additions and 43 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: golangci-lint
on:
push:
tags:
- v*
branches:
- master
- develop
pull_request:
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2.3.0
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.32

# Optional: working directory, useful for monorepos
working-directory: clients/go

# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: false
2 changes: 1 addition & 1 deletion clients/go/.gocompat.json

Large diffs are not rendered by default.

File renamed without changes.
6 changes: 5 additions & 1 deletion clients/go/cmd/zbctl/internal/commands/publishMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ var publishMessageCmd = &cobra.Command{
ctx, cancel := context.WithTimeout(context.Background(), defaultTimeout)
defer cancel()

response, err := request.Send(ctx)
response, err := request.Send(ctx)
if err != nil {
return err
}

return printJSON(response)
},
}
Expand Down
7 changes: 5 additions & 2 deletions clients/go/cmd/zbctl/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,12 @@ func (s *integrationTestSuite) runCommand(command string, envVars ...string) ([]
}

func buildZbctl() ([]byte, error) {
if runtime.GOOS == "linux" {
switch runtime.GOOS {
case "linux":
zbctl = "zbctl"
} else {
case "darwin":
zbctl = "zbctl.darwin"
default:
return nil, fmt.Errorf("can't run zbctl tests on unsupported OS '%s'", runtime.GOOS)
}

Expand Down
2 changes: 2 additions & 0 deletions clients/go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,8 @@ google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM
google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
google.golang.org/grpc v1.33.1 h1:DGeFlSan2f+WEtCERJ4J9GJWk15TxUi8QGagfI87Xyc=
google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0=
google.golang.org/grpc v1.33.2 h1:EQyQC3sa8M+p6Ulc8yy9SWSS2GVwyRc83gAbG8lrl4o=
google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
Expand Down
13 changes: 6 additions & 7 deletions clients/go/internal/embedded/embedded.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion clients/go/pkg/commands/activate_jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (cmd *ActivateJobsCommand) Send(ctx context.Context) ([]entities.Job, error
return activatedJobs, err
}
for _, activatedJob := range response.Jobs {
activatedJobs = append(activatedJobs, entities.Job{ActivatedJob: *activatedJob})
activatedJobs = append(activatedJobs, entities.Job{ActivatedJob: activatedJob})
}
}

Expand Down
6 changes: 3 additions & 3 deletions clients/go/pkg/commands/activate_jobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ func TestActivateJobsCommand(t *testing.T) {

var expectedJobs []entities.Job
for _, job := range response1.Jobs {
expectedJobs = append(expectedJobs, entities.Job{ActivatedJob: *job})
expectedJobs = append(expectedJobs, entities.Job{ActivatedJob: job})
}
for _, job := range response2.Jobs {
expectedJobs = append(expectedJobs, entities.Job{ActivatedJob: *job})
expectedJobs = append(expectedJobs, entities.Job{ActivatedJob: job})
}
for _, job := range response3.Jobs {
expectedJobs = append(expectedJobs, entities.Job{ActivatedJob: *job})
expectedJobs = append(expectedJobs, entities.Job{ActivatedJob: job})
}

gomock.InOrder(
Expand Down
4 changes: 2 additions & 2 deletions clients/go/pkg/commands/cancel_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type CancelWorkflowInstanceCommand struct {
request pb.CancelWorkflowInstanceRequest
}

func (cmd CancelWorkflowInstanceCommand) Send(ctx context.Context) (*pb.CancelWorkflowInstanceResponse, error) {
func (cmd *CancelWorkflowInstanceCommand) Send(ctx context.Context) (*pb.CancelWorkflowInstanceResponse, error) {
response, err := cmd.gateway.CancelWorkflowInstance(ctx, &cmd.request)
if cmd.shouldRetry(ctx, err) {
return cmd.Send(ctx)
Expand All @@ -41,7 +41,7 @@ func (cmd CancelWorkflowInstanceCommand) Send(ctx context.Context) (*pb.CancelWo
return response, err
}

func (cmd CancelWorkflowInstanceCommand) WorkflowInstanceKey(key int64) DispatchCancelWorkflowInstanceCommand {
func (cmd *CancelWorkflowInstanceCommand) WorkflowInstanceKey(key int64) DispatchCancelWorkflowInstanceCommand {
cmd.request = pb.CancelWorkflowInstanceRequest{WorkflowInstanceKey: key}
return cmd
}
Expand Down
1 change: 1 addition & 0 deletions clients/go/pkg/commands/create_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func (cmd *CreateInstanceCommand) WorkflowKey(key int64) CreateInstanceCommandSt
return cmd
}

//nolint:golint
func (cmd *CreateInstanceCommand) BPMNProcessId(id string) CreateInstanceCommandStep2 {
cmd.request.BpmnProcessId = id
return cmd
Expand Down
1 change: 1 addition & 0 deletions clients/go/pkg/commands/publish_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type PublishMessageCommand struct {
request pb.PublishMessageRequest
}

//nolint:golint
func (cmd *PublishMessageCommand) MessageId(messageId string) PublishMessageCommandStep3 {
cmd.request.MessageId = messageId
return cmd
Expand Down
4 changes: 2 additions & 2 deletions clients/go/pkg/commands/publish_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func TestPublishMessageCommand(t *testing.T) {
CorrelationKey: "bar",
}
stub := &pb.PublishMessageResponse{
Key: 1,
}
Key: 1,
}

client.EXPECT().PublishMessage(gomock.Any(), &utils.RPCTestMsg{Msg: request}).Return(stub, nil)

Expand Down
2 changes: 1 addition & 1 deletion clients/go/pkg/entities/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
// See https://docs.zeebe.io/basics/job-workers.html#what-is-a-job for details
// on jobs.
type Job struct {
pb.ActivatedJob
*pb.ActivatedJob
}

// GetVariablesAsMap returns a map of a workflow instance's variables.
Expand Down
2 changes: 1 addition & 1 deletion clients/go/pkg/entities/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type testType struct {
}

var (
job = Job{pb.ActivatedJob{
job = Job{&pb.ActivatedJob{
CustomHeaders: `{"foo": "bar", "hello": "world"}`,
Variables: `{"foo": "bar", "hello": "world"}`,
}}
Expand Down
2 changes: 1 addition & 1 deletion clients/go/pkg/worker/jobDispatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (suite *JobDispatcherSuite) TestShouldPassClientAndJobToHandler() {
go suite.dispatcher.run(&suite.client, handler, 1, &suite.waitGroup)

// when
suite.dispatcher.jobQueue <- entities.Job{ActivatedJob: pb.ActivatedJob{Key: jobKey}}
suite.dispatcher.jobQueue <- entities.Job{ActivatedJob: &pb.ActivatedJob{Key: jobKey}}

// then
select {
Expand Down
6 changes: 3 additions & 3 deletions clients/go/pkg/worker/jobPoller.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

type jobPoller struct {
client pb.GatewayClient
request pb.ActivateJobsRequest
request *pb.ActivateJobsRequest
requestTimeout time.Duration
maxJobsActive int
pollInterval time.Duration
Expand Down Expand Up @@ -77,7 +77,7 @@ func (poller *jobPoller) activateJobs() {
defer cancel()

poller.request.MaxJobsToActivate = int32(poller.maxJobsActive - poller.remaining)
stream, err := poller.client.ActivateJobs(ctx, &poller.request)
stream, err := poller.client.ActivateJobs(ctx, poller.request)
if err != nil {
log.Println("Failed to request jobs for worker", poller.request.Worker, err)
return
Expand All @@ -96,7 +96,7 @@ func (poller *jobPoller) activateJobs() {
poller.remaining += len(response.Jobs)
poller.setJobsRemainingCountMetric(poller.remaining)
for _, job := range response.Jobs {
poller.jobQueue <- entities.Job{ActivatedJob: *job}
poller.jobQueue <- entities.Job{ActivatedJob: job}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions clients/go/pkg/worker/jobPoller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ type JobPollerSuite struct {
waitGroup sync.WaitGroup
}

func (suite *JobPollerSuite) BeforeTest(suiteName, testName string) {
func (suite *JobPollerSuite) BeforeTest(_, _ string) {
suite.ctrl = gomock.NewController(suite.T())
suite.client = mock_pb.NewMockGatewayClient(suite.ctrl)
suite.poller = jobPoller{
client: suite.client,
request: pb.ActivateJobsRequest{},
request: &pb.ActivateJobsRequest{},
requestTimeout: utils.DefaultTestTimeout,
maxJobsActive: DefaultJobWorkerMaxJobActive,
pollInterval: DefaultJobWorkerPollInterval,
Expand All @@ -55,7 +55,7 @@ func (suite *JobPollerSuite) BeforeTest(suiteName, testName string) {
suite.waitGroup.Add(1)
}

func (suite *JobPollerSuite) AfterTest(suiteName, testName string) {
func (suite *JobPollerSuite) AfterTest(_, _ string) {
defer suite.ctrl.Finish()

close(suite.poller.closeSignal)
Expand Down
4 changes: 2 additions & 2 deletions clients/go/pkg/worker/jobWorker_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const (
type JobWorkerBuilder struct {
gatewayClient pb.GatewayClient
jobClient JobClient
request pb.ActivateJobsRequest
request *pb.ActivateJobsRequest
requestTimeout time.Duration

handler JobHandler
Expand Down Expand Up @@ -198,7 +198,7 @@ func NewJobWorkerBuilder(gatewayClient pb.GatewayClient, jobClient JobClient) Jo
concurrency: DefaultJobWorkerConcurrency,
pollInterval: DefaultJobWorkerPollInterval,
pollThreshold: DefaultJobWorkerPollThreshold,
request: pb.ActivateJobsRequest{
request: &pb.ActivateJobsRequest{
Timeout: commands.DefaultJobTimeoutInMs,
Worker: commands.DefaultJobWorkerName,
RequestTimeout: DefaultRequestTimeout.Milliseconds(),
Expand Down
9 changes: 5 additions & 4 deletions clients/go/pkg/worker/jobWorker_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/zeebe-io/zeebe/clients/go/internal/mock_pb"
"github.com/zeebe-io/zeebe/clients/go/pkg/entities"
"github.com/zeebe-io/zeebe/clients/go/pkg/pb"
"testing"
"time"
)
Expand All @@ -28,7 +29,7 @@ const testDuration = 12 * time.Minute
const testDurationMs = int64(testDuration / time.Millisecond)

func TestJobWorkerBuilder_JobType(t *testing.T) {
builder := JobWorkerBuilder{}
builder := JobWorkerBuilder{request: &pb.ActivateJobsRequest{}}
builder.JobType("foo")
assert.Equal(t, "foo", builder.request.Type)
}
Expand All @@ -40,13 +41,13 @@ func TestJobWorkerBuilder_Handler(t *testing.T) {
}

func TestJobWorkerBuilder_Name(t *testing.T) {
builder := JobWorkerBuilder{}
builder := JobWorkerBuilder{request: &pb.ActivateJobsRequest{}}
builder.Name("foo")
assert.Equal(t, "foo", builder.request.Worker)
}

func TestJobWorkerBuilder_Timeout(t *testing.T) {
builder := JobWorkerBuilder{}
builder := JobWorkerBuilder{request: &pb.ActivateJobsRequest{}}
builder.Timeout(testDuration)
assert.Equal(t, testDurationMs, builder.request.Timeout)
}
Expand Down Expand Up @@ -90,7 +91,7 @@ func TestJobWorkerBuilder_PollThreshold(t *testing.T) {
func TestJobWorkerBuilder_FetchVariables(t *testing.T) {
fetchVariables := []string{"foo", "bar", "baz"}

builder := JobWorkerBuilder{}
builder := JobWorkerBuilder{request: &pb.ActivateJobsRequest{}}
builder.FetchVariables(fetchVariables...)
assert.Equal(t, fetchVariables, builder.request.FetchVariable)
}
Expand Down
2 changes: 1 addition & 1 deletion clients/go/pkg/worker/jobWorker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ package worker
import (
"fmt"
"github.com/golang/mock/gomock"
"github.com/golang/protobuf/proto"
"github.com/zeebe-io/zeebe/clients/go/internal/mock_pb"
"github.com/zeebe-io/zeebe/clients/go/internal/utils"
"github.com/zeebe-io/zeebe/clients/go/pkg/commands"
"github.com/zeebe-io/zeebe/clients/go/pkg/entities"
"github.com/zeebe-io/zeebe/clients/go/pkg/pb"
"google.golang.org/protobuf/proto"
"testing"
"time"
)
Expand Down
2 changes: 1 addition & 1 deletion clients/go/pkg/zbc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func configureConnectionSecurity(config *ClientConfig) error {
var creds credentials.TransportCredentials

if config.CaCertificatePath == "" {
creds = credentials.NewTLS(&tls.Config{})
creds = credentials.NewTLS(&tls.Config{MinVersion: tls.VersionTLS13})
} else if _, err := os.Stat(config.CaCertificatePath); os.IsNotExist(err) {
return fmt.Errorf("expected to find CA certificate but no such file at '%s': %w", config.CaCertificatePath, ErrFileNotFound)
} else {
Expand Down
10 changes: 5 additions & 5 deletions clients/go/pkg/zbc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (s *clientTestSuite) TestClientWithPathToNonExistingFile() {
parts := strings.Split(lis.Addr().String(), ":")
wrongPath := "non.existing"

//when
// when
_, err := NewClient(&ClientConfig{
GatewayAddress: fmt.Sprintf("0.0.0.0:%s", parts[len(parts)-1]),
CaCertificatePath: wrongPath,
Expand Down Expand Up @@ -269,7 +269,7 @@ func (s *clientTestSuite) TestKeepAlive() {
// given
keepAlive := 2 * time.Minute
config := &ClientConfig{
GatewayAddress: fmt.Sprintf("0.0.0.0:0"),
GatewayAddress: "0.0.0.0:0",
UsePlaintextConnection: true,
KeepAlive: keepAlive,
}
Expand All @@ -289,7 +289,7 @@ func (s *clientTestSuite) TestOverrideKeepAliveWithEnvVar() {

env.set(KeepAliveEnvVar, strconv.Itoa(keepAlive))
config := &ClientConfig{
GatewayAddress: fmt.Sprintf("0.0.0.0:0"),
GatewayAddress: "0.0.0.0:0",
UsePlaintextConnection: true,
KeepAlive: 5 * time.Second,
}
Expand All @@ -305,7 +305,7 @@ func (s *clientTestSuite) TestOverrideKeepAliveWithEnvVar() {
func (s *clientTestSuite) TestRejectNegativeDuration() {
// given
config := &ClientConfig{
GatewayAddress: fmt.Sprintf("0.0.0.0:0"),
GatewayAddress: "0.0.0.0:0",
UsePlaintextConnection: true,
KeepAlive: -5 * time.Second,
}
Expand All @@ -321,7 +321,7 @@ func (s *clientTestSuite) TestRejectNegativeDurationAsEnvVar() {
// given
env.set(KeepAliveEnvVar, "-100")
config := &ClientConfig{
GatewayAddress: fmt.Sprintf("0.0.0.0:0"),
GatewayAddress: "0.0.0.0:0",
UsePlaintextConnection: true,
}

Expand Down
2 changes: 1 addition & 1 deletion clients/go/pkg/zbc/oauthCredentialsCache.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (cache *oauthYamlCredentialsCache) writeCache() error {
return err
}

return ioutil.WriteFile(cache.path, cacheContents, 0640)
return ioutil.WriteFile(cache.path, cacheContents, 0600)
}

func getDefaultOAuthYamlCredentialsCacheRelativePath() string {
Expand Down
Loading

0 comments on commit a45915c

Please sign in to comment.