Skip to content

Commit 4508902

Browse files
authored
Support space characters (" ") in Job names (#49)
Now that keys correctly use `path.Join` concatenation to the Job name, we can safely add support for space characters. Closes #46 Signed-off-by: joshvanl <[email protected]>
1 parent b36ada3 commit 4508902

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

cron/cron_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,46 @@ func Test_schedule(t *testing.T) {
493493
})
494494
}
495495

496+
func Test_jobWithSpace(t *testing.T) {
497+
t.Parallel()
498+
499+
cron := testCronWithOptions(t, testCronOptions{
500+
total: 1,
501+
client: tests.EmbeddedETCDBareClient(t),
502+
})
503+
504+
require.NoError(t, cron.api.Add(context.Background(), "hello world", &api.Job{
505+
DueTime: ptr.Of(time.Now().Add(2).Format(time.RFC3339)),
506+
}))
507+
resp, err := cron.api.Get(context.Background(), "hello world")
508+
assert.NoError(t, err)
509+
assert.NotNil(t, resp)
510+
511+
assert.EventuallyWithT(t, func(c *assert.CollectT) {
512+
assert.Equal(c, int64(1), cron.triggered.Load())
513+
resp, err = cron.api.Get(context.Background(), "hello world")
514+
assert.NoError(c, err)
515+
assert.Nil(c, resp)
516+
}, time.Second*10, time.Millisecond*10)
517+
518+
require.NoError(t, cron.api.Add(context.Background(), "another hello world", &api.Job{
519+
Schedule: ptr.Of("@every 1s"),
520+
}))
521+
resp, err = cron.api.Get(context.Background(), "another hello world")
522+
assert.NoError(t, err)
523+
assert.NotNil(t, resp)
524+
listresp, err := cron.api.List(context.Background(), "")
525+
assert.NoError(t, err)
526+
assert.Len(t, listresp.Jobs, 1)
527+
require.NoError(t, cron.api.Delete(context.Background(), "another hello world"))
528+
resp, err = cron.api.Get(context.Background(), "another hello world")
529+
assert.NoError(t, err)
530+
assert.Nil(t, resp)
531+
listresp, err = cron.api.List(context.Background(), "")
532+
assert.NoError(t, err)
533+
assert.Empty(t, listresp.Jobs)
534+
}
535+
496536
type testCronOptions struct {
497537
total uint32
498538
gotCh chan *api.TriggerRequest

internal/api/validator/validator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type Validator struct {
2828
func New(opts Options) *Validator {
2929
jobNameSanitizer := opts.JobNameSanitizer
3030
if jobNameSanitizer == nil {
31-
jobNameSanitizer = strings.NewReplacer("_", "", ":", "", "-", "")
31+
jobNameSanitizer = strings.NewReplacer("_", "", ":", "", "-", "", " ", "")
3232
}
3333
return &Validator{
3434
jobNameSanitizer: jobNameSanitizer,

internal/api/validator/validator_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ func Test_JobName(t *testing.T) {
9494
name: "aABVCD||dapr-::123:123||dapr.internal.dapr-tests.perf-workflowsapp.workflow||24b3fbad-0db5-4e81-a272-71f6018a66a6||start-4NYDFil-",
9595
expErr: false,
9696
},
97+
{
98+
name: "aABVCD||dapr-::123:123||dapr.internal.dapr-tests.perf- workflowsapp.workflow||24b3fbad-0db5-4e81 -a272-71f6018a66a6||start-4NYDFil-",
99+
expErr: false,
100+
},
97101
}
98102

99103
for _, test := range tests {

0 commit comments

Comments
 (0)