Skip to content

Commit

Permalink
Support space characters (" ") in Job names (diagridio#49)
Browse files Browse the repository at this point in the history
Now that keys correctly use `path.Join` concatenation to the Job name,
we can safely add support for space characters.

Closes diagridio#46

Signed-off-by: joshvanl <[email protected]>
  • Loading branch information
JoshVanL authored Oct 14, 2024
1 parent b36ada3 commit 4508902
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
40 changes: 40 additions & 0 deletions cron/cron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,46 @@ func Test_schedule(t *testing.T) {
})
}

func Test_jobWithSpace(t *testing.T) {
t.Parallel()

cron := testCronWithOptions(t, testCronOptions{
total: 1,
client: tests.EmbeddedETCDBareClient(t),
})

require.NoError(t, cron.api.Add(context.Background(), "hello world", &api.Job{
DueTime: ptr.Of(time.Now().Add(2).Format(time.RFC3339)),
}))
resp, err := cron.api.Get(context.Background(), "hello world")
assert.NoError(t, err)
assert.NotNil(t, resp)

assert.EventuallyWithT(t, func(c *assert.CollectT) {
assert.Equal(c, int64(1), cron.triggered.Load())
resp, err = cron.api.Get(context.Background(), "hello world")
assert.NoError(c, err)
assert.Nil(c, resp)
}, time.Second*10, time.Millisecond*10)

require.NoError(t, cron.api.Add(context.Background(), "another hello world", &api.Job{
Schedule: ptr.Of("@every 1s"),
}))
resp, err = cron.api.Get(context.Background(), "another hello world")
assert.NoError(t, err)
assert.NotNil(t, resp)
listresp, err := cron.api.List(context.Background(), "")
assert.NoError(t, err)
assert.Len(t, listresp.Jobs, 1)
require.NoError(t, cron.api.Delete(context.Background(), "another hello world"))
resp, err = cron.api.Get(context.Background(), "another hello world")
assert.NoError(t, err)
assert.Nil(t, resp)
listresp, err = cron.api.List(context.Background(), "")
assert.NoError(t, err)
assert.Empty(t, listresp.Jobs)
}

type testCronOptions struct {
total uint32
gotCh chan *api.TriggerRequest
Expand Down
2 changes: 1 addition & 1 deletion internal/api/validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Validator struct {
func New(opts Options) *Validator {
jobNameSanitizer := opts.JobNameSanitizer
if jobNameSanitizer == nil {
jobNameSanitizer = strings.NewReplacer("_", "", ":", "", "-", "")
jobNameSanitizer = strings.NewReplacer("_", "", ":", "", "-", "", " ", "")
}
return &Validator{
jobNameSanitizer: jobNameSanitizer,
Expand Down
4 changes: 4 additions & 0 deletions internal/api/validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ func Test_JobName(t *testing.T) {
name: "aABVCD||dapr-::123:123||dapr.internal.dapr-tests.perf-workflowsapp.workflow||24b3fbad-0db5-4e81-a272-71f6018a66a6||start-4NYDFil-",
expErr: false,
},
{
name: "aABVCD||dapr-::123:123||dapr.internal.dapr-tests.perf- workflowsapp.workflow||24b3fbad-0db5-4e81 -a272-71f6018a66a6||start-4NYDFil-",
expErr: false,
},
}

for _, test := range tests {
Expand Down

0 comments on commit 4508902

Please sign in to comment.