Files
tasks/common/testing/testhooks/test_impl_test.go
zeekay 5a601d081b rebrand: go.temporal.io/server -> github.com/hanzoai/tasks
Full module path rebrand from Temporal to Hanzo Tasks:
- go.mod module: github.com/hanzoai/tasks
- All internal Go imports updated (1906 files)
- cmd/server renamed to cmd/tasksd
- Binary name: tasksd (was temporal-server)
- Docker images: hanzoai/tasks (was temporalio/server)
- README rewritten with Hanzo Tasks branding
- LLM.md created with integration notes
- Makefile, goreleaser, CI workflows updated
- go.temporal.io/sdk and go.temporal.io/api imports preserved (separate repos)

Fork of Temporal.io (MIT license).
2026-03-19 10:36:40 -07:00

109 lines
2.9 KiB
Go

//go:build test_dep
package testhooks
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/hanzoai/tasks/common/namespace"
)
func TestGet(t *testing.T) {
th := NewTestHooks()
t.Run("returns false for unset key", func(t *testing.T) {
_, ok := Get(th, MatchingDisableSyncMatch, namespace.ID("ns1"))
require.False(t, ok)
})
t.Run("returns set value", func(t *testing.T) {
cleanup := Set(th, MatchingLBForceReadPartition, 42, namespace.ID("ns1"))
defer cleanup()
v, ok := Get(th, MatchingLBForceReadPartition, namespace.ID("ns1"))
require.True(t, ok)
require.Equal(t, 42, v)
})
t.Run("cleanup removes value", func(t *testing.T) {
cleanup := Set(th, MatchingLBForceReadPartition, 42, namespace.ID("ns1"))
cleanup()
_, ok := Get(th, MatchingLBForceReadPartition, namespace.ID("ns1"))
require.False(t, ok)
})
}
func TestCall(t *testing.T) {
th := NewTestHooks()
t.Run("does nothing for unset key", func(t *testing.T) {
Call(th, UpdateWithStartInBetweenLockAndStart, namespace.ID("ns1")) // should not panic
})
t.Run("calls set function", func(t *testing.T) {
called := false
cleanup := Set(th, UpdateWithStartInBetweenLockAndStart, func() { called = true }, namespace.ID("ns1"))
defer cleanup()
Call(th, UpdateWithStartInBetweenLockAndStart, namespace.ID("ns1"))
require.True(t, called)
})
}
func TestSet(t *testing.T) {
th := NewTestHooks()
t.Run("namespace-scoped keys are isolated", func(t *testing.T) {
cleanup1 := Set(th, MatchingDisableSyncMatch, true, namespace.ID("ns1"))
defer cleanup1()
cleanup2 := Set(th, MatchingDisableSyncMatch, false, namespace.ID("ns2"))
v, ok := Get(th, MatchingDisableSyncMatch, namespace.ID("ns1"))
require.True(t, ok)
require.True(t, v)
v, ok = Get(th, MatchingDisableSyncMatch, namespace.ID("ns2"))
require.True(t, ok)
require.False(t, v)
_, ok = Get(th, MatchingDisableSyncMatch, namespace.ID("other"))
require.False(t, ok)
// Cleanup only affects specific namespace
cleanup2()
_, ok = Get(th, MatchingDisableSyncMatch, namespace.ID("ns2"))
require.False(t, ok)
v, ok = Get(th, MatchingDisableSyncMatch, namespace.ID("ns1"))
require.True(t, ok)
require.True(t, v)
})
t.Run("global-scoped keys", func(t *testing.T) {
cleanup := Set(th, TaskQueuesInDeploymentSyncBatchSize, 42, GlobalScope)
defer cleanup()
v, ok := Get(th, TaskQueuesInDeploymentSyncBatchSize, GlobalScope)
require.True(t, ok)
require.Equal(t, 42, v)
})
t.Run("overwrites previous value for same scope", func(t *testing.T) {
cleanup1 := Set(th, MatchingLBForceReadPartition, 1, namespace.ID("ns1"))
cleanup2 := Set(th, MatchingLBForceReadPartition, 2, namespace.ID("ns1"))
v, ok := Get(th, MatchingLBForceReadPartition, namespace.ID("ns1"))
require.True(t, ok)
require.Equal(t, 2, v)
cleanup2()
_, ok = Get(th, MatchingLBForceReadPartition, namespace.ID("ns1"))
require.False(t, ok)
cleanup1() // should not panic
})
}