diff --git a/client/client.go b/client/client.go index 52fd1cd88..8d02607ef 100644 --- a/client/client.go +++ b/client/client.go @@ -1261,6 +1261,9 @@ type ( // underlying connection. Only the final close of all existing clients will // close the underlying connection. Close() + + // Namespace returns the configured namespace of the Temporal client + Namespace() string } // NamespaceClient is the client for managing operations on the namespace. diff --git a/internal/client.go b/internal/client.go index 405de582a..c89048876 100644 --- a/internal/client.go +++ b/internal/client.go @@ -452,6 +452,9 @@ type ( // Close client and clean up underlying resources. Close() + + // Namespace returns the configured namespace of the Temporal client + Namespace() string } // ClientOptions are optional parameters for Client creation. diff --git a/internal/internal_workflow_client.go b/internal/internal_workflow_client.go index 8d0a7bf81..3fce10fae 100644 --- a/internal/internal_workflow_client.go +++ b/internal/internal_workflow_client.go @@ -1365,6 +1365,11 @@ func (wc *WorkflowClient) Close() { } } +// Namespace returns the configured namespace of the Temporal client +func (wc *WorkflowClient) Namespace() string { + return wc.namespace +} + // Register a namespace with temporal server // The errors it can throw: // - NamespaceAlreadyExistsError diff --git a/internal/internal_workflow_client_test.go b/internal/internal_workflow_client_test.go index 8accdd298..ce8b0d71e 100644 --- a/internal/internal_workflow_client_test.go +++ b/internal/internal_workflow_client_test.go @@ -2478,3 +2478,11 @@ func TestUpdate(t *testing.T) { require.NoError(t, err) }) } + +func (s *workflowClientTestSuite) TestNamespace() { + dc := NewContextAwareDataConverter(converter.GetDefaultDataConverter()) + s.client = NewServiceClient(s.service, nil, ClientOptions{DataConverter: dc}) + client, ok := s.client.(*WorkflowClient) + s.Require().True(ok) + s.Equal(DefaultNamespace, client.Namespace()) +} diff --git a/internal/nexus_operations.go b/internal/nexus_operations.go index 8a3a38639..af35ade10 100644 --- a/internal/nexus_operations.go +++ b/internal/nexus_operations.go @@ -698,6 +698,11 @@ func (t *testSuiteClientForNexusOperations) UpdateWorkflowExecutionOptions(ctx c panic("not implemented in the test environment") } +// Namespace returns the default testing namespace, ie. "default-test-namespace" +func (t *testSuiteClientForNexusOperations) Namespace() string { + return t.env.workflowInfo.Namespace +} + var _ Client = &testSuiteClientForNexusOperations{} // testEnvWorkflowRunForNexusOperations is a partial [WorkflowRun] implementation for the test workflow environment used diff --git a/mocks/Client.go b/mocks/Client.go index f7830bc9a..7d5e56e82 100644 --- a/mocks/Client.go +++ b/mocks/Client.go @@ -1112,6 +1112,26 @@ func (_m *Client) WorkflowService() workflowservice.WorkflowServiceClient { return r0 } +// Namespace provides a mock function with given fields: +func (_m *Client) Namespace() string { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Namespace") + } + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(string) + } + } + + return r0 +} + // NewClient creates a new instance of Client. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. // The first argument is typically a *testing.T value. func NewClient(t interface {