Skip to content

Commit 75bd94b

Browse files
authoredOct 8, 2024··
Panic if endpoint or service is empty in NewNexusClient (#1661)
1 parent b4e934e commit 75bd94b

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
 

‎internal/workflow.go

+6
Original file line numberDiff line numberDiff line change
@@ -2408,6 +2408,12 @@ type nexusClient struct {
24082408
//
24092409
// NOTE: Experimental
24102410
func NewNexusClient(endpoint, service string) NexusClient {
2411+
if endpoint == "" {
2412+
panic("endpoint must not be empty")
2413+
}
2414+
if service == "" {
2415+
panic("service must not be empty")
2416+
}
24112417
return nexusClient{endpoint, service}
24122418
}
24132419

‎test/nexus_test.go

+32
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,38 @@ func TestAsyncOperationFromWorkflow(t *testing.T) {
648648
})
649649
}
650650

651+
func TestNewNexusClientValidation(t *testing.T) {
652+
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
653+
defer cancel()
654+
tc := newTestContext(t, ctx)
655+
656+
callerWorkflow := func(ctx workflow.Context, endpoint, service string) (err error) {
657+
defer func() {
658+
panicMessage := recover()
659+
err = fmt.Errorf("recovered: %s", panicMessage)
660+
}()
661+
_ = workflow.NewNexusClient(endpoint, service)
662+
return
663+
}
664+
665+
w := worker.New(tc.client, tc.taskQueue, worker.Options{})
666+
w.RegisterWorkflow(callerWorkflow)
667+
require.NoError(t, w.Start())
668+
t.Cleanup(w.Stop)
669+
670+
opts := client.StartWorkflowOptions{
671+
TaskQueue: tc.taskQueue,
672+
}
673+
674+
run, err := tc.client.ExecuteWorkflow(ctx, opts, callerWorkflow, "", "service")
675+
require.NoError(t, err)
676+
require.ErrorContains(t, run.Get(ctx, nil), "recovered: endpoint must not be empty")
677+
678+
run, err = tc.client.ExecuteWorkflow(ctx, opts, callerWorkflow, "endpoint", "")
679+
require.NoError(t, err)
680+
require.ErrorContains(t, run.Get(ctx, nil), "recovered: service must not be empty")
681+
}
682+
651683
func TestReplay(t *testing.T) {
652684
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
653685
defer cancel()

0 commit comments

Comments
 (0)