diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/lint.yml similarity index 89% rename from .github/workflows/golangci-lint.yml rename to .github/workflows/lint.yml index 4e6b215..ae6798a 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/lint.yml @@ -1,9 +1,8 @@ -name: golangci-lint +name: lint on: - push: - branches: - - main pull_request: + branches: [main] + permissions: contents: read diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..958e6aa --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,18 @@ +name: test + +on: + pull_request: + branches: + - main + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.21' + - name: Test + run: go test -v ./... diff --git a/.gitignore b/.gitignore index 619f315..c2ec9d0 100644 --- a/.gitignore +++ b/.gitignore @@ -226,4 +226,6 @@ $RECYCLE.BIN/ # Windows shortcuts *.lnk -# End of https://www.toptal.com/developers/gitignore/api/go,osx,linux,visualstudiocode,goland,windows \ No newline at end of file +# End of https://www.toptal.com/developers/gitignore/api/go,osx,linux,visualstudiocode,goland,windows +dist/ +ctrf-report.json diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..f5ced3e --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,41 @@ +# This is an example .goreleaser.yml file with some sensible defaults. +# Make sure to check the documentation at https://goreleaser.com + +# The lines below are called `modelines`. See `:help modeline` +# Feel free to remove those if you don't want/need to use them. +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj + +version: 2 + +before: + hooks: + # You may remove this if you don't use go modules. + - go mod tidy + # you may remove this if you don't need go generate + - go generate ./... + +builds: + - skip: true + +archives: + - format: tar.gz + # this name template makes the OS and Arch compatible with the results of `uname`. + name_template: >- + {{ .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + # use zip for windows archives + format_overrides: + - goos: windows + format: zip + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" diff --git a/README.md b/README.md index 937436f..f6444b5 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ ![GitHub release (with filter)](https://img.shields.io/github/v/release/breuHQ/go-temporal-tools) ![GitHub go.mod Go version (subdirectory of monorepo)](https://img.shields.io/github/go-mod/go-version/breuHQ/go-temporal-tools) +![Tests](https://img.shields.io/github/actions/workflow/status/breuHQ/go-temporal-tools/test.yml?label=test) [![License](https://img.shields.io/github/license/breuHQ/go-temporal-tools)](./LICENSE) ![GitHub contributors](https://img.shields.io/github/contributors/breuHQ/go-temporal-tools) diff --git a/go.mod b/go.mod index 0ea3e40..6f16ad8 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.21.0 require ( github.com/gobeam/stringy v0.0.7 + github.com/google/uuid v1.6.0 github.com/stretchr/testify v1.9.0 go.temporal.io/api v1.32.0 go.temporal.io/sdk v1.26.1 @@ -14,7 +15,6 @@ require ( github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/mock v1.6.0 // indirect - github.com/google/uuid v1.6.0 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 // indirect github.com/pborman/uuid v1.2.1 // indirect diff --git a/queues/queues_test.go b/queues/queues_test.go new file mode 100644 index 0000000..f5d7dd5 --- /dev/null +++ b/queues/queues_test.go @@ -0,0 +1,89 @@ +package queues_test + +import ( + "context" + "testing" + + "github.com/google/uuid" + "github.com/stretchr/testify/suite" + "go.temporal.io/sdk/testsuite" + "go.temporal.io/sdk/workflow" + + "go.breu.io/temporal-tools/queues" + "go.breu.io/temporal-tools/workflows" +) + +type ( + QueueTestSuite struct { + suite.Suite + testsuite.WorkflowTestSuite + + env *testsuite.TestWorkflowEnvironment + queue queues.Queue + } +) + +func (s *QueueTestSuite) SetupTest() { + s.env = s.NewTestWorkflowEnvironment() + c := &MockClient{env: s.env} + + s.queue = queues.New( + queues.WithName("test"), + queues.WithClient(c), + ) +} + +func (s *QueueTestSuite) AfterTest(suiteName, testName string) { + s.env.AssertExpectations(s.T()) +} + +func (s *QueueTestSuite) TestName() { + expected := "test" + + s.Equal(expected, s.queue.Name().String()) +} + +func (s *QueueTestSuite) TestPrefix() { + expected := "io.breu.test" + + s.Equal(expected, s.queue.Prefix()) +} + +func (s *QueueTestSuite) TestWorkflowID() { + id := uuid.New() + opts, _ := workflows.NewOptions( + workflows.WithBlock("suite"), + workflows.WithBlockID(id.String()), + ) + expected := "io.breu.test.suite." + id.String() + actual := s.queue.WorkflowID(opts) + + s.Equal(expected, actual) +} + +func (s *QueueTestSuite) TestExecuteWorkflow() { + ctx := context.Background() + id := uuid.New() + opts, _ := workflows.NewOptions( + workflows.WithBlock("test"), + workflows.WithBlockID(id.String()), + ) + + fn := func(ctx workflow.Context, in string) (string, error) { + return in + " world", nil + } + + // Execute the workflow + _, _ = s.queue.ExecuteWorkflow(ctx, opts, fn, "hello") + + expected := "hello world" + result := "" + + _ = s.env.GetWorkflowResult(&result) + + s.Equal(expected, result) +} + +func TestQueueTestSuite(t *testing.T) { + suite.Run(t, new(QueueTestSuite)) +}