Skip to content

Instantly share code, notes, and snippets.

@Semior001
Last active January 6, 2024 22:09
Show Gist options
  • Save Semior001/ec43888490fda9741e6d77cf71415fa5 to your computer and use it in GitHub Desktop.
Save Semior001/ec43888490fda9741e6d77cf71415fa5 to your computer and use it in GitHub Desktop.
package exampleservice
import (
"context"
api "prototemporal/_example/simple/api"
"go.temporal.io/sdk/temporal"
"go.temporal.io/sdk/workflow"
)
type ExampleService struct {
api.ExampleServiceWfClient
}
func (e *ExampleService) ComplexAction(
wctx workflow.Context,
req *api.ComplexActionRequest,
) (*api.ComplexActionResponse, error) {
resp, err := e.ExampleServiceWfClient.SimpleActivity(wctx, &api.SimpleActivityRequest{
AgreementId: req.GetAgreementId() + "_workflow",
ProductId: req.GetProductId() + "_workflow",
})
if err != nil {
return nil, temporal.NewNonRetryableApplicationError(
"failed to call SimpleActivity",
"some-non-retryable-error-type",
err,
// here might be some details about the error
)
}
return &api.ComplexActionResponse{
AgreementId: resp.GetAgreementId() + "_processed",
ProductId: resp.GetProductId() + "_processed",
}, nil
}
func (e *ExampleService) SimpleActivity(
ctx context.Context,
req *api.SimpleActivityRequest,
) (*api.SimpleActivityResponse, error) {
return &api.SimpleActivityResponse{
AgreementId: req.GetAgreementId() + "_activity",
ProductId: req.GetProductId() + "_activity",
}, nil
}
package exampleservice
import (
api "git.sbercloud.tech/cp/go/lib/prototemporal/_example/simple/api"
"git.sbercloud.tech/cp/go/lib/prototemporal/lib/temporaltest/twfctx"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
"testing"
)
func TestExampleService_ComplexAction(t *testing.T) {
ctrl := gomock.NewController(t)
wfClientMock := api.NewMockExampleServiceWfClient(ctrl)
wfClientMock.EXPECT().
SimpleActivity(gomock.Any(), &api.SimpleActivityRequest{
AgreementId: "agreement_workflow",
ProductId: "product_workflow",
}).
Return(&api.SimpleActivityResponse{
AgreementId: "agreement_workflow_activity",
ProductId: "product_workflow_activity",
}, nil)
srv := &ExampleService{
ExampleServiceWfClient: wfClientMock,
}
resp, err := srv.ComplexAction(twfctx.Background(t), &api.ComplexActionRequest{
AgreementId: "agreement",
ProductId: "product",
})
require.NoError(t, err)
require.Equal(t, "agreement_workflow_activity_processed", resp.GetAgreementId())
require.Equal(t, "product_workflow_activity_processed", resp.GetProductId())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment