Skip to content

Commit

Permalink
chore(queue): some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Yousuf Jawwad committed Aug 14, 2024
1 parent 85f08aa commit 2e5140b
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 5 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
name: Test
name: test

on:
push:
branches:
- main
pull_request:
branches:
- main
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,4 @@ $RECYCLE.BIN/

# End of https://www.toptal.com/developers/gitignore/api/go,osx,linux,visualstudiocode,goland,windows
dist/
ctrf-report.json
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
89 changes: 89 additions & 0 deletions queues/queues_test.go
Original file line number Diff line number Diff line change
@@ -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))
}

0 comments on commit 2e5140b

Please sign in to comment.