Skip to content

Commit

Permalink
switch s.True(strings.Contains to s.ErrorContains
Browse files Browse the repository at this point in the history
  • Loading branch information
3vilhamster committed May 24, 2024
1 parent 528e29c commit 35a729e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
28 changes: 14 additions & 14 deletions common/persistence/elasticsearch/es_visibility_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func (s *ESVisibilitySuite) TestListOpenWorkflowExecutions() {
_, err = s.visibilityStore.ListOpenWorkflowExecutions(ctx, testRequest)
s.Error(err)
s.ErrorAs(err, new(*types.InternalServiceError))
s.True(strings.Contains(err.Error(), "ListOpenWorkflowExecutions failed"))
s.ErrorContains(err, "ListOpenWorkflowExecutions failed")
}

func (s *ESVisibilitySuite) TestListClosedWorkflowExecutions() {
Expand All @@ -325,7 +325,7 @@ func (s *ESVisibilitySuite) TestListClosedWorkflowExecutions() {
_, err = s.visibilityStore.ListClosedWorkflowExecutions(ctx, testRequest)
s.Error(err)
s.ErrorAs(err, new(*types.InternalServiceError))
s.True(strings.Contains(err.Error(), "ListClosedWorkflowExecutions failed"))
s.ErrorContains(err, "ListClosedWorkflowExecutions failed")
}

func (s *ESVisibilitySuite) TestListOpenWorkflowExecutionsByType() {
Expand Down Expand Up @@ -353,7 +353,7 @@ func (s *ESVisibilitySuite) TestListOpenWorkflowExecutionsByType() {
_, err = s.visibilityStore.ListOpenWorkflowExecutionsByType(ctx, request)
s.Error(err)
s.ErrorAs(err, new(*types.InternalServiceError))
s.True(strings.Contains(err.Error(), "ListOpenWorkflowExecutionsByType failed"))
s.ErrorContains(err, "ListOpenWorkflowExecutionsByType failed")
}

func (s *ESVisibilitySuite) TestListAllWorkflowExecutions() {
Expand Down Expand Up @@ -389,7 +389,7 @@ func (s *ESVisibilitySuite) TestListClosedWorkflowExecutionsByType() {
_, err = s.visibilityStore.ListClosedWorkflowExecutionsByType(ctx, request)
s.Error(err)
s.ErrorAs(err, new(*types.InternalServiceError))
s.True(strings.Contains(err.Error(), "ListClosedWorkflowExecutionsByType failed"))
s.ErrorContains(err, "ListClosedWorkflowExecutionsByType failed")
}

func (s *ESVisibilitySuite) TestListOpenWorkflowExecutionsByWorkflowID() {
Expand Down Expand Up @@ -418,7 +418,7 @@ func (s *ESVisibilitySuite) TestListOpenWorkflowExecutionsByWorkflowID() {
_, err = s.visibilityStore.ListOpenWorkflowExecutionsByWorkflowID(ctx, request)
s.Error(err)
s.ErrorAs(err, new(*types.InternalServiceError))
s.True(strings.Contains(err.Error(), "ListOpenWorkflowExecutionsByWorkflowID failed"))
s.ErrorContains(err, "ListOpenWorkflowExecutionsByWorkflowID failed")
}

func (s *ESVisibilitySuite) TestListClosedWorkflowExecutionsByWorkflowID() {
Expand Down Expand Up @@ -447,7 +447,7 @@ func (s *ESVisibilitySuite) TestListClosedWorkflowExecutionsByWorkflowID() {
_, err = s.visibilityStore.ListClosedWorkflowExecutionsByWorkflowID(ctx, request)
s.Error(err)
s.ErrorAs(err, new(*types.InternalServiceError))
s.True(strings.Contains(err.Error(), "ListClosedWorkflowExecutionsByWorkflowID failed"))
s.ErrorContains(err, "ListClosedWorkflowExecutionsByWorkflowID failed")
}

func (s *ESVisibilitySuite) TestListClosedWorkflowExecutionsByStatus() {
Expand Down Expand Up @@ -477,7 +477,7 @@ func (s *ESVisibilitySuite) TestListClosedWorkflowExecutionsByStatus() {
_, err = s.visibilityStore.ListClosedWorkflowExecutionsByStatus(ctx, request)
s.Error(err)
s.ErrorAs(err, new(*types.InternalServiceError))
s.True(strings.Contains(err.Error(), "ListClosedWorkflowExecutionsByStatus failed"))
s.ErrorContains(err, "ListClosedWorkflowExecutionsByStatus failed")
}

func (s *ESVisibilitySuite) TestGetNextPageToken() {
Expand Down Expand Up @@ -511,7 +511,7 @@ func (s *ESVisibilitySuite) TestDeserializePageToken() {
s.Nil(result)
var typedError *types.BadRequestError
s.ErrorAs(err, &typedError)
s.True(strings.Contains(typedError.Error(), "unable to deserialize page token"))
s.ErrorContains(typedError, "unable to deserialize page token")

token = &es.ElasticVisibilityPageToken{SortValue: int64(64), TieBreaker: "unique"}
data, _ = es.SerializePageToken(token)
Expand Down Expand Up @@ -810,13 +810,13 @@ func (s *ESVisibilitySuite) TestListWorkflowExecutions() {
_, err = s.visibilityStore.ListWorkflowExecutions(ctx, request)
s.Error(err)
s.ErrorAs(err, new(*types.InternalServiceError))
s.True(strings.Contains(err.Error(), "ListWorkflowExecutions failed"))
s.ErrorContains(err, "ListWorkflowExecutions failed")

request.Query = `invalid query`
_, err = s.visibilityStore.ListWorkflowExecutions(context.Background(), request)
s.Error(err)
s.ErrorAs(err, new(*types.BadRequestError))
s.True(strings.Contains(err.Error(), "Error when parse query"))
s.ErrorContains(err, "Error when parse query")
}

func (s *ESVisibilitySuite) TestScanWorkflowExecutions() {
Expand Down Expand Up @@ -844,15 +844,15 @@ func (s *ESVisibilitySuite) TestScanWorkflowExecutions() {
_, err = s.visibilityStore.ScanWorkflowExecutions(ctx, request)
s.Error(err)
s.ErrorAs(err, new(*types.BadRequestError))
s.True(strings.Contains(err.Error(), "Error when parse query"))
s.ErrorContains(err, "Error when parse query")

// test internal error
request.Query = `CloseStatus = 5`
s.mockESClient.On("ScanByQuery", mock.Anything, mock.Anything).Return(nil, errTestESSearch).Once()
_, err = s.visibilityStore.ScanWorkflowExecutions(ctx, request)
s.Error(err)
s.ErrorAs(err, new(*types.InternalServiceError))
s.True(strings.Contains(err.Error(), "ScanWorkflowExecutions failed"))
s.ErrorContains(err, "ScanWorkflowExecutions failed")
}

func (s *ESVisibilitySuite) TestCountWorkflowExecutions() {
Expand Down Expand Up @@ -880,14 +880,14 @@ func (s *ESVisibilitySuite) TestCountWorkflowExecutions() {
_, err = s.visibilityStore.CountWorkflowExecutions(ctx, request)
s.Error(err)
s.ErrorAs(err, new(*types.InternalServiceError))
s.True(strings.Contains(err.Error(), "CountWorkflowExecutions failed"))
s.ErrorContains(err, "CountWorkflowExecutions failed")

// test bad request
request.Query = `invalid query`
_, err = s.visibilityStore.CountWorkflowExecutions(ctx, request)
s.Error(err)
s.ErrorAs(err, new(*types.BadRequestError))
s.True(strings.Contains(err.Error(), "Error when parse query"))
s.ErrorContains(err, "Error when parse query")
}

func (s *ESVisibilitySuite) TestTimeProcessFunc() {
Expand Down
7 changes: 2 additions & 5 deletions host/signal_workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"encoding/binary"
"fmt"
"strconv"
"strings"
"time"

"github.com/pborman/uuid"
Expand Down Expand Up @@ -1576,8 +1575,7 @@ func (s *IntegrationSuite) TestSignalWithStartWorkflow_IDReusePolicy() {
s.Error(err)
var alreadyStartedErr *types.WorkflowExecutionAlreadyStartedError
s.ErrorAs(err, &alreadyStartedErr)
errMsg := alreadyStartedErr.GetMessage()
s.True(strings.Contains(errMsg, "reject duplicate workflow ID"))
s.ErrorContains(alreadyStartedErr, "reject duplicate workflow ID")

// test policy WorkflowIDReusePolicyAllowDuplicateFailedOnly
wfIDReusePolicy = types.WorkflowIDReusePolicyAllowDuplicateFailedOnly
Expand All @@ -1588,8 +1586,7 @@ func (s *IntegrationSuite) TestSignalWithStartWorkflow_IDReusePolicy() {
s.Nil(resp)
s.Error(err)
s.ErrorAs(err, &alreadyStartedErr)
errMsg = alreadyStartedErr.GetMessage()
s.True(strings.Contains(errMsg, "allow duplicate workflow ID if last run failed"))
s.ErrorContains(alreadyStartedErr, "allow duplicate workflow ID if last run failed")

// test policy WorkflowIDReusePolicyAllowDuplicate
wfIDReusePolicy = types.WorkflowIDReusePolicyAllowDuplicate
Expand Down

0 comments on commit 35a729e

Please sign in to comment.