Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(tests): create tests on queue #9

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: golangci-lint
name: lint
on:
push:
branches:
- main
pull_request:
branches: [main]


permissions:
contents: read
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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 ./...
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,6 @@ $RECYCLE.BIN/
# Windows shortcuts
*.lnk

# End of https://www.toptal.com/developers/gitignore/api/go,osx,linux,visualstudiocode,goland,windows
# End of https://www.toptal.com/developers/gitignore/api/go,osx,linux,visualstudiocode,goland,windows
dist/
ctrf-report.json
41 changes: 41 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -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:"
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))
}
Loading