Files
tasks/tests/testcore/utils.go
Roey BermanandGitHub 243effc6e1 Forbid the use of pborman/uuid and remove uses (#8541)
## What

Used the `depguard` linter to prevent importing the package and modified
all uses of it.

Also fixed a bug in the membership code where we were not updating the
next page token:

https://github.com/temporalio/temporal/pull/8541/files#diff-985dd64ffa4c6bfe0248b982dc47439b725862baa3e1f2c559b7ff522bf21969R350


## Why?

From the package README in GitHub:

> This package now leverages the github.com/google/uuid package (which
is based off an earlier version of this package).

Also, there's no point in having two uuid implementations in the
codebase.

## Test

Added the invalid import and confirmed it works:

```
../service/frontend/admin_handler_test.go:13:2: import 'github.com/pborman/uuid' is not allowed from list 'main': Importing github.com/pborman/uuid is disallowed; use github.com/google/uuid instead (depguard)
        _ "github.com/pborman/uuid"

```
2025-11-26 01:33:02 +00:00

89 lines
2.4 KiB
Go

package testcore
import (
"fmt"
"regexp"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
commonpb "go.temporal.io/api/common/v1"
historypb "go.temporal.io/api/history/v1"
"go.temporal.io/server/api/adminservice/v1"
historyspb "go.temporal.io/server/api/history/v1"
"go.temporal.io/server/api/historyservice/v1"
replicationspb "go.temporal.io/server/api/replication/v1"
"go.temporal.io/server/common/payloads"
"go.temporal.io/server/common/persistence/versionhistory"
"google.golang.org/protobuf/proto"
)
// TODO (alex): move this to functional_test_base.go as methods.
func RandomizeStr(id string) string {
return fmt.Sprintf("%v-%v", id, uuid.NewString())
}
func DecodeString(t require.TestingT, pls *commonpb.Payloads) string {
if th, ok := t.(interface{ Helper() }); ok {
th.Helper()
}
var str string
err := payloads.Decode(pls, &str)
require.NoError(t, err)
return str
}
func EventBatchesToVersionHistory(
versionHistory *historyspb.VersionHistory,
eventBatches []*historypb.History,
) (*historyspb.VersionHistory, error) {
// TODO temporary code to generate version history
// we should generate version as part of modeled based testing
if versionHistory == nil {
versionHistory = versionhistory.NewVersionHistory(nil, nil)
}
for _, batch := range eventBatches {
for _, event := range batch.Events {
err := versionhistory.AddOrUpdateVersionHistoryItem(versionHistory,
versionhistory.NewVersionHistoryItem(
event.GetEventId(),
event.GetVersion(),
))
if err != nil {
return nil, err
}
}
}
return versionHistory, nil
}
func RandomizedNexusEndpoint(name string) string {
re := regexp.MustCompile("[/_]")
safeName := re.ReplaceAllString(name, "-")
return fmt.Sprintf("%v-%v", safeName, uuid.NewString())
}
// ExtractReplicationMessages extracts WorkflowReplicationMessages from a proto message.
// This is a helper for tests that need to inspect replication message contents.
func ExtractReplicationMessages(msg proto.Message) *replicationspb.WorkflowReplicationMessages {
if msg == nil {
return nil
}
if histResp, ok := msg.(*historyservice.StreamWorkflowReplicationMessagesResponse); ok {
if messages := histResp.GetMessages(); messages != nil {
return messages
}
}
if adminResp, ok := msg.(*adminservice.StreamWorkflowReplicationMessagesResponse); ok {
if messages := adminResp.GetMessages(); messages != nil {
return messages
}
}
return nil
}