Repository: beatlabs/patron
Pull request #633 (2023-06-16 06:50:50)

Upgrade Linter and refactor
<!--
Thanks for taking precious time for making a PR.

Before creating a pull request, please make sure:
- Your PR solves one problem for which an issue exist and a solution has been discussed
- You have read the guide for contributing
  - See https://github.com/beatlabs/patron/blob/master/README.md#how-to-contribute
- You signed all your commits (otherwise we won't be able to merge the PR)
  - See https://github.com/beatlabs/patron/blob/master/SIGNYOURWORK.md
- You added unit tests for the new functionality
- You mention in the PR description which issue it is addressing, e.g. "Resolves #123"
-->

## Which problem is this PR solving?

Linter is outdated

## Short description of the changes

- Upgrade linter
- Refactor cb state



Patch:
diff --git a/Makefile b/Makefile
index 234bd31cc..06de0d4b8 100644
--- a/Makefile
+++ b/Makefile
@@ -25,10 +25,10 @@ fmtcheck:
 	@sh -c "'$(CURDIR)/script/gofmtcheck.sh'"
 
 lint: fmtcheck
-	$(DOCKER) run --env=GOFLAGS=-mod=vendor --rm -v $(CURDIR):/app -w /app golangci/golangci-lint:v1.50.1 golangci-lint -v run
+	$(DOCKER) run --env=GOFLAGS=-mod=vendor --rm -v $(CURDIR):/app -w /app golangci/golangci-lint:v1.53.3 golangci-lint -v run
 
 deeplint: fmtcheck
-	$(DOCKER) run --env=GOFLAGS=-mod=vendor --rm -v $(CURDIR):/app -w /app golangci/golangci-lint:v1.50.1 golangci-lint run --exclude-use-default=false --enable-all -D dupl --build-tags integration
+	$(DOCKER) run --env=GOFLAGS=-mod=vendor --rm -v $(CURDIR):/app -w /app golangci/golangci-lint:v1.53.3 golangci-lint run --exclude-use-default=false --enable-all -D dupl --build-tags integration
 
 modsync: fmtcheck
 	go mod tidy && 	go mod vendor
diff --git a/reliability/circuitbreaker/breaker.go b/reliability/circuitbreaker/breaker.go
index 3a70f733e..a5029be47 100644
--- a/reliability/circuitbreaker/breaker.go
+++ b/reliability/circuitbreaker/breaker.go
@@ -20,15 +20,15 @@ func (oe OpenError) Error() string {
 type status int
 
 const (
-	close status = iota // nolint:predeclared
-	open
+	closed status = iota
+	opened
 )
 
 var (
 	tsFuture       = int64(math.MaxInt64)
 	errOpen        = new(OpenError)
 	breakerCounter *prometheus.CounterVec
-	statusMap      = map[status]string{close: "close", open: "open"}
+	statusMap      = map[status]string{closed: "closed", opened: "opened"}
 )
 
 func init() {
@@ -89,7 +89,7 @@ func New(name string, s Setting) (*CircuitBreaker, error) {
 	return &CircuitBreaker{
 		name:       name,
 		set:        s,
-		status:     close,
+		status:     closed,
 		executions: 0,
 		failures:   0,
 		retries:    0,
@@ -100,7 +100,7 @@ func New(name string, s Setting) (*CircuitBreaker, error) {
 func (cb *CircuitBreaker) isHalfOpen() bool {
 	cb.RLock()
 	defer cb.RUnlock()
-	if cb.status == open && cb.nextRetry <= time.Now().UnixNano() {
+	if cb.status == opened && cb.nextRetry <= time.Now().UnixNano() {
 		return true
 	}
 	return false
@@ -109,7 +109,7 @@ func (cb *CircuitBreaker) isHalfOpen() bool {
 func (cb *CircuitBreaker) isOpen() bool {
 	cb.RLock()
 	defer cb.RUnlock()
-	if cb.status == open && cb.nextRetry > time.Now().UnixNano() {
+	if cb.status == opened && cb.nextRetry > time.Now().UnixNano() {
 		return true
 	}
 	return false
@@ -118,7 +118,7 @@ func (cb *CircuitBreaker) isOpen() bool {
 func (cb *CircuitBreaker) isClose() bool {
 	cb.RLock()
 	defer cb.RUnlock()
-	return cb.status == close
+	return cb.status == closed
 }
 
 // Execute the provided action.
@@ -147,7 +147,7 @@ func (cb *CircuitBreaker) incFailure() {
 
 	cb.failures++
 
-	if cb.status == close && cb.failures >= cb.set.FailureThreshold {
+	if cb.status == closed && cb.failures >= cb.set.FailureThreshold {
 		cb.transitionToOpen()
 		return
 	}
@@ -179,7 +179,7 @@ func (cb *CircuitBreaker) incSuccess() {
 }
 
 func (cb *CircuitBreaker) transitionToOpen() {
-	cb.status = open
+	cb.status = opened
 	cb.failures = 0
 	cb.executions = 0
 	cb.retries = 0
@@ -188,7 +188,7 @@ func (cb *CircuitBreaker) transitionToOpen() {
 }
 
 func (cb *CircuitBreaker) transitionToClose() {
-	cb.status = close
+	cb.status = closed
 	cb.failures = 0
 	cb.executions = 0
 	cb.retries = 0


Test patch:
diff --git a/client/sns/publisher_test.go b/client/sns/publisher_test.go
index 8b7454daa..b96c52a7a 100644
--- a/client/sns/publisher_test.go
+++ b/client/sns/publisher_test.go
@@ -98,7 +98,7 @@ func newStubSNSAPI(expectedOutput *sns.PublishOutput, expectedErr error) *stubSN
 	return &stubSNSAPI{output: expectedOutput, err: expectedErr}
 }
 
-func (s *stubSNSAPI) Publish(ctx context.Context, params *sns.PublishInput, optFns ...func(*sns.Options)) (*sns.PublishOutput, error) {
+func (s *stubSNSAPI) Publish(_ context.Context, _ *sns.PublishInput, _ ...func(*sns.Options)) (*sns.PublishOutput, error) {
 	return s.output, s.err
 }
 
diff --git a/component/async/kafka/simple/simple_test.go b/component/async/kafka/simple/simple_test.go
index 9ee77d727..d2f4d8819 100644
--- a/component/async/kafka/simple/simple_test.go
+++ b/component/async/kafka/simple/simple_test.go
@@ -70,6 +70,7 @@ func TestNew(t *testing.T) {
 		},
 	}
 	for _, tt := range tests {
+		tt := tt
 		t.Run(tt.name, func(t *testing.T) {
 			t.Parallel()
 
diff --git a/component/sqs/message_test.go b/component/sqs/message_test.go
index 8eb69fac3..a659c1f4f 100644
--- a/component/sqs/message_test.go
+++ b/component/sqs/message_test.go
@@ -296,14 +296,14 @@ type stubSQSAPI struct {
 	queueURL                  string
 }
 
-func (s stubSQSAPI) DeleteMessage(ctx context.Context, params *sqs.DeleteMessageInput, optFns ...func(*sqs.Options)) (*sqs.DeleteMessageOutput, error) {
+func (s stubSQSAPI) DeleteMessage(_ context.Context, _ *sqs.DeleteMessageInput, _ ...func(*sqs.Options)) (*sqs.DeleteMessageOutput, error) {
 	if s.deleteMessageWithContextErr != nil {
 		return nil, s.deleteMessageWithContextErr
 	}
 	return &sqs.DeleteMessageOutput{}, nil
 }
 
-func (s stubSQSAPI) DeleteMessageBatch(ctx context.Context, params *sqs.DeleteMessageBatchInput, optFns ...func(*sqs.Options)) (*sqs.DeleteMessageBatchOutput, error) {
+func (s stubSQSAPI) DeleteMessageBatch(_ context.Context, _ *sqs.DeleteMessageBatchInput, _ ...func(*sqs.Options)) (*sqs.DeleteMessageBatchOutput, error) {
 	if s.deleteMessageBatchWithContextErr != nil {
 		return nil, s.deleteMessageBatchWithContextErr
 	}
@@ -322,7 +322,7 @@ func (s stubSQSAPI) DeleteMessageBatch(ctx context.Context, params *sqs.DeleteMe
 	}, nil
 }
 
-func (s stubSQSAPI) GetQueueAttributes(ctx context.Context, params *sqs.GetQueueAttributesInput, optFns ...func(*sqs.Options)) (*sqs.GetQueueAttributesOutput, error) {
+func (s stubSQSAPI) GetQueueAttributes(_ context.Context, _ *sqs.GetQueueAttributesInput, _ ...func(*sqs.Options)) (*sqs.GetQueueAttributesOutput, error) {
 	if s.getQueueAttributesWithContextErr != nil {
 		return nil, s.getQueueAttributesWithContextErr
 	}
@@ -336,14 +336,14 @@ func (s stubSQSAPI) GetQueueAttributes(ctx context.Context, params *sqs.GetQueue
 }
 
 // nolint
-func (s stubSQSAPI) GetQueueUrl(ctx context.Context, params *sqs.GetQueueUrlInput, optFns ...func(*sqs.Options)) (*sqs.GetQueueUrlOutput, error) {
+func (s stubSQSAPI) GetQueueUrl(_ context.Context, _ *sqs.GetQueueUrlInput, _ ...func(*sqs.Options)) (*sqs.GetQueueUrlOutput, error) {
 	if s.getQueueUrlWithContextErr != nil {
 		return nil, s.getQueueUrlWithContextErr
 	}
 	return &sqs.GetQueueUrlOutput{QueueUrl: aws.String(s.queueURL)}, nil
 }
 
-func (s stubSQSAPI) ReceiveMessage(ctx context.Context, params *sqs.ReceiveMessageInput, optFns ...func(*sqs.Options)) (*sqs.ReceiveMessageOutput, error) {
+func (s stubSQSAPI) ReceiveMessage(_ context.Context, _ *sqs.ReceiveMessageInput, _ ...func(*sqs.Options)) (*sqs.ReceiveMessageOutput, error) {
 	if s.receiveMessageWithContextErr != nil {
 		return nil, s.receiveMessageWithContextErr
 	}
diff --git a/reliability/circuitbreaker/breaker_test.go b/reliability/circuitbreaker/breaker_test.go
index c4cc48b14..47319c71f 100644
--- a/reliability/circuitbreaker/breaker_test.go
+++ b/reliability/circuitbreaker/breaker_test.go
@@ -53,9 +53,9 @@ func TestCircuitBreaker_isHalfOpen(t *testing.T) {
 		fields fields
 		want   bool
 	}{
-		"closed":    {fields: fields{status: close, nextRetry: tsFuture}, want: false},
-		"open":      {fields: fields{status: open, nextRetry: time.Now().Add(1 * time.Hour).UnixNano()}, want: false},
-		"half open": {fields: fields{status: open, nextRetry: time.Now().Add(-1 * time.Minute).UnixNano()}, want: true},
+		"closed":    {fields: fields{status: closed, nextRetry: tsFuture}, want: false},
+		"open":      {fields: fields{status: opened, nextRetry: time.Now().Add(1 * time.Hour).UnixNano()}, want: false},
+		"half open": {fields: fields{status: opened, nextRetry: time.Now().Add(-1 * time.Minute).UnixNano()}, want: true},
 	}
 	for name, tt := range tests {
 		tt := tt
@@ -82,9 +82,9 @@ func TestCircuitBreaker_isOpen(t *testing.T) {
 		fields fields
 		want   bool
 	}{
-		"closed":    {fields: fields{status: close, nextRetry: tsFuture}, want: false},
-		"half open": {fields: fields{status: open, nextRetry: time.Now().Add(-1 * time.Minute).UnixNano()}, want: false},
-		"open":      {fields: fields{status: open, nextRetry: time.Now().Add(1 * time.Hour).UnixNano()}, want: true},
+		"closed":    {fields: fields{status: closed, nextRetry: tsFuture}, want: false},
+		"half open": {fields: fields{status: opened, nextRetry: time.Now().Add(-1 * time.Minute).UnixNano()}, want: false},
+		"open":      {fields: fields{status: opened, nextRetry: time.Now().Add(1 * time.Hour).UnixNano()}, want: true},
 	}
 	for name, tt := range tests {
 		tt := tt
@@ -111,9 +111,9 @@ func TestCircuitBreaker_isClose(t *testing.T) {
 		fields fields
 		want   bool
 	}{
-		"closed":    {fields: fields{status: close, nextRetry: tsFuture}, want: true},
-		"half open": {fields: fields{status: open, nextRetry: time.Now().Add(-1 * time.Minute).UnixNano()}, want: false},
-		"open":      {fields: fields{status: open, nextRetry: time.Now().Add(1 * time.Hour).UnixNano()}, want: false},
+		"closed":    {fields: fields{status: closed, nextRetry: tsFuture}, want: true},
+		"half open": {fields: fields{status: opened, nextRetry: time.Now().Add(-1 * time.Minute).UnixNano()}, want: false},
+		"open":      {fields: fields{status: opened, nextRetry: time.Now().Add(1 * time.Hour).UnixNano()}, want: false},
 	}
 	for name, tt := range tests {
 		tt := tt