diff --git a/internal/workflow.go b/internal/workflow.go index 8cae1b815..12a08b622 100644 --- a/internal/workflow.go +++ b/internal/workflow.go @@ -2408,6 +2408,12 @@ type nexusClient struct { // // NOTE: Experimental func NewNexusClient(endpoint, service string) NexusClient { + if endpoint == "" { + panic("endpoint must not be empty") + } + if service == "" { + panic("service must not be empty") + } return nexusClient{endpoint, service} } diff --git a/test/nexus_test.go b/test/nexus_test.go index b5fbadd36..5f3126fd6 100644 --- a/test/nexus_test.go +++ b/test/nexus_test.go @@ -648,6 +648,38 @@ func TestAsyncOperationFromWorkflow(t *testing.T) { }) } +func TestNewNexusClientValidation(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) + defer cancel() + tc := newTestContext(t, ctx) + + callerWorkflow := func(ctx workflow.Context, endpoint, service string) (err error) { + defer func() { + panicMessage := recover() + err = fmt.Errorf("recovered: %s", panicMessage) + }() + _ = workflow.NewNexusClient(endpoint, service) + return + } + + w := worker.New(tc.client, tc.taskQueue, worker.Options{}) + w.RegisterWorkflow(callerWorkflow) + require.NoError(t, w.Start()) + t.Cleanup(w.Stop) + + opts := client.StartWorkflowOptions{ + TaskQueue: tc.taskQueue, + } + + run, err := tc.client.ExecuteWorkflow(ctx, opts, callerWorkflow, "", "service") + require.NoError(t, err) + require.ErrorContains(t, run.Get(ctx, nil), "recovered: endpoint must not be empty") + + run, err = tc.client.ExecuteWorkflow(ctx, opts, callerWorkflow, "endpoint", "") + require.NoError(t, err) + require.ErrorContains(t, run.Get(ctx, nil), "recovered: service must not be empty") +} + func TestReplay(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) defer cancel()