Skip to content

Commit

Permalink
Panic if endpoint or service is empty in NewNexusClient (#1661)
Browse files Browse the repository at this point in the history
  • Loading branch information
bergundy authored Oct 8, 2024
1 parent b4e934e commit 75bd94b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}

Expand Down
32 changes: 32 additions & 0 deletions test/nexus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 75bd94b

Please sign in to comment.