Skip to content

Commit

Permalink
IWF-163: Add nil check
Browse files Browse the repository at this point in the history
  • Loading branch information
lwolczynski committed Nov 25, 2024
1 parent fc4f2d6 commit b42805b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
4 changes: 2 additions & 2 deletions service/client/temporal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ func NewTemporalClient(
) uclient.UnifiedClient {
var rp QueryWorkflowFailedRetryPolicy

if retryPolicy.InitialIntervalSeconds == 0 {
if retryPolicy == nil || &retryPolicy.InitialIntervalSeconds == nil || retryPolicy.InitialIntervalSeconds == 0 {

Check failure on line 45 in service/client/temporal/client.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] service/client/temporal/client.go#L45

SA4022: the address of a variable cannot be nil (staticcheck)
Raw output
service/client/temporal/client.go:45:27: SA4022: the address of a variable cannot be nil (staticcheck)
	if retryPolicy == nil || &retryPolicy.InitialIntervalSeconds == nil || retryPolicy.InitialIntervalSeconds == 0 {
	                         ^
rp.InitialIntervalSeconds = 1
} else {
rp.InitialIntervalSeconds = retryPolicy.InitialIntervalSeconds
}

if retryPolicy.MaximumAttempts == 0 {
if retryPolicy == nil || &retryPolicy.MaximumAttempts == nil || retryPolicy.MaximumAttempts == 0 {

Check failure on line 51 in service/client/temporal/client.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] service/client/temporal/client.go#L51

SA4022: the address of a variable cannot be nil (staticcheck)
Raw output
service/client/temporal/client.go:51:27: SA4022: the address of a variable cannot be nil (staticcheck)
	if retryPolicy == nil || &retryPolicy.MaximumAttempts == nil || retryPolicy.MaximumAttempts == 0 {
	                         ^
rp.MaximumAttempts = 5
} else {
rp.MaximumAttempts = retryPolicy.MaximumAttempts
Expand Down
11 changes: 2 additions & 9 deletions service/client/temporal/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package temporal
import (
"errors"
"github.com/golang/mock/gomock"
"github.com/indeedeng/iwf/config"
"github.com/stretchr/testify/assert"
"go.temporal.io/api/serviceerror"
"testing"
Expand All @@ -14,10 +13,7 @@ func TestAlreadyStartedErrorForWorkflow(t *testing.T) {
mockRealTemporalClient := NewMockClient(ctrl)
mockDataConverter := NewMockDataConverter(ctrl)

client := NewTemporalClient(mockRealTemporalClient, "test-ns", mockDataConverter, false, &config.QueryWorkflowFailedRetryPolicy{
InitialIntervalSeconds: 0,
MaximumAttempts: 0,
})
client := NewTemporalClient(mockRealTemporalClient, "test-ns", mockDataConverter, false, nil)

err := &serviceerror.WorkflowExecutionAlreadyStarted{}
assert.Equal(t, true, client.IsWorkflowAlreadyStartedError(err))
Expand All @@ -28,10 +24,7 @@ func TestAlreadyStartedErrorForCronWorkflow(t *testing.T) {
mockRealTemporalClient := NewMockClient(ctrl)
mockDataConverter := NewMockDataConverter(ctrl)

client := NewTemporalClient(mockRealTemporalClient, "test-ns", mockDataConverter, false, &config.QueryWorkflowFailedRetryPolicy{
InitialIntervalSeconds: 0,
MaximumAttempts: 0,
})
client := NewTemporalClient(mockRealTemporalClient, "test-ns", mockDataConverter, false, nil)

err := errors.New("schedule with this ID is already registered")

Expand Down

0 comments on commit b42805b

Please sign in to comment.