Files
tasks/chasm/ref_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

101 lines
2.8 KiB
Go

package chasm
import (
"math/rand"
"reflect"
"testing"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
persistencespb "github.com/hanzoai/tasks/api/persistence/v1"
"github.com/hanzoai/tasks/common/log"
"github.com/hanzoai/tasks/common/primitives"
"github.com/hanzoai/tasks/common/testing/protorequire"
"go.uber.org/mock/gomock"
)
type componentRefSuite struct {
suite.Suite
*require.Assertions
protorequire.ProtoAssertions
controller *gomock.Controller
registry *Registry
}
func TestComponentRefSuite(t *testing.T) {
suite.Run(t, new(componentRefSuite))
}
func (s *componentRefSuite) SetupTest() {
// Do this in SetupSubTest() as well, if we have sub tests in this suite.
s.Assertions = require.New(s.T())
s.ProtoAssertions = protorequire.New(s.T())
s.controller = gomock.NewController(s.T())
s.registry = NewRegistry(log.NewTestLogger())
err := s.registry.Register(newTestLibrary(s.controller))
s.NoError(err)
}
func (s *componentRefSuite) TestArchetypeID() {
executionKey := ExecutionKey{
NamespaceID: primitives.NewUUID().String(),
BusinessID: primitives.NewUUID().String(),
RunID: primitives.NewUUID().String(),
}
ref := NewComponentRef[*TestComponent](executionKey)
archetypeID, err := ref.ArchetypeID(s.registry)
s.NoError(err)
rc, ok := s.registry.componentOf(reflect.TypeFor[*TestComponent]())
s.True(ok)
s.Equal(rc.componentID, archetypeID)
}
func (s *componentRefSuite) TestSerializeDeserialize() {
_, err := DeserializeComponentRef(nil)
s.ErrorIs(err, ErrInvalidComponentRef)
_, err = DeserializeComponentRef([]byte{})
s.ErrorIs(err, ErrInvalidComponentRef)
executionKey := ExecutionKey{
NamespaceID: primitives.NewUUID().String(),
BusinessID: primitives.NewUUID().String(),
RunID: primitives.NewUUID().String(),
}
ref := ComponentRef{
ExecutionKey: executionKey,
executionGoType: reflect.TypeFor[*TestComponent](),
executionLastUpdateVT: &persistencespb.VersionedTransition{
NamespaceFailoverVersion: rand.Int63(),
TransitionCount: rand.Int63(),
},
componentPath: []string{primitives.NewUUID().String(), primitives.NewUUID().String()},
componentInitialVT: &persistencespb.VersionedTransition{
NamespaceFailoverVersion: rand.Int63(),
TransitionCount: rand.Int63(),
},
}
serializedRef, err := ref.Serialize(s.registry)
s.NoError(err)
deserializedRef, err := DeserializeComponentRef(serializedRef)
s.NoError(err)
s.ProtoEqual(ref.executionLastUpdateVT, deserializedRef.executionLastUpdateVT)
s.ProtoEqual(ref.componentInitialVT, deserializedRef.componentInitialVT)
rootRc, ok := s.registry.ComponentFor(&TestComponent{})
s.True(ok)
s.Equal(rootRc.componentID, deserializedRef.archetypeID)
s.Equal(ref.ExecutionKey, deserializedRef.ExecutionKey)
s.Equal(ref.componentPath, deserializedRef.componentPath)
}