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

workflow: Use int value for status filter to avoid generic assertion #11

Merged
merged 2 commits into from
Aug 9, 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
2 changes: 1 addition & 1 deletion adapters/adaptertest/recordstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func testList(t *testing.T, factory func() workflow.RecordStore) {
}

for status, count := range config {
ls, err := store.List(ctx, workflowName, 0, 100, workflow.OrderTypeAscending, workflow.FilterByStatus(status))
ls, err := store.List(ctx, workflowName, 0, 100, workflow.OrderTypeAscending, workflow.FilterByStatus(int64(status)))
jtest.RequireNil(t, err)
require.Equal(t, count, len(ls))

Expand Down
4 changes: 2 additions & 2 deletions filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ func FilterByForeignID(val string) RecordFilter {
}
}

func FilterByStatus[status StatusType](s status) RecordFilter {
func FilterByStatus(status int64) RecordFilter {
return func(filters *recordFilters) {
i := strconv.FormatInt(int64(s), 10)
i := strconv.FormatInt(status, 10)
filters.byStatus = makeFilterValue(i)
}
}
Expand Down
29 changes: 29 additions & 0 deletions filter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package workflow_test

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/luno/workflow"
)

func TestMakeFilter(t *testing.T) {
t.Run("Filter by RunState", func(t *testing.T) {
filter := workflow.MakeFilter(workflow.FilterByRunState(workflow.RunStateInitiated))
require.True(t, filter.ByRunState().Enabled, "Expected RunState filter to be enabled")
require.Equal(t, "1", filter.ByRunState().Value, "Expected RunState filter value to be 5")
})

t.Run("Filter by ForeignID", func(t *testing.T) {
filter := workflow.MakeFilter(workflow.FilterByForeignID("test value"))
require.True(t, filter.ByForeignID().Enabled, "Expected foreign ID filter to be enabled")
require.Equal(t, "test value", filter.ByForeignID().Value, "Expected foreign ID filter value to be 5")
})

t.Run("Filter by Status", func(t *testing.T) {
filter := workflow.MakeFilter(workflow.FilterByStatus(9))
require.True(t, filter.ByStatus().Enabled, "Expected status filter to be enabled")
require.Equal(t, "9", filter.ByStatus().Value, "Expected status filter value to be 5")
})
}
Loading