Something went wrong on our end
Select Git revision
import_test.go
-
Volker Schukai authoredVolker Schukai authored
import_test.go 2.87 KiB
package jobqueue
import (
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"testing"
"time"
)
func TestCreateJobAndSchedulerFromInput(t *testing.T) {
tests := []struct {
name string
input JobImport
wantJob GenericJob
wantSched Scheduler
wantErr bool
}{
{
name: "Shell Runnable and Interval Scheduler",
input: JobImport{
ID: "1",
Priority: 1,
Timeout: 10 * time.Second,
MaxRetries: 3,
RetryDelay: 2 * time.Second,
Runnable: RunnableImport{
Type: "Shell",
Data: map[string]any{"ScriptPath": "script.sh"},
},
Scheduler: SchedulerImport{
Type: "Interval",
Interval: 1 * time.Minute,
},
},
wantJob: GenericJob(&Job[ShellResult]{ /* Initialization */ }),
wantSched: &IntervalScheduler{Interval: 1 * time.Minute},
wantErr: false,
},
{
name: "Shell Runnable and Cron Scheduler",
input: JobImport{
ID: "1",
Priority: 1,
Runnable: RunnableImport{
Type: "Shell",
Data: map[string]any{"ScriptPath": "script.sh"},
},
Scheduler: SchedulerImport{
Type: "Cron",
Spec: "*/5 * * * *",
},
},
wantJob: GenericJob(&Job[ShellResult]{ /* Initialization */ }),
wantSched: &CronScheduler{ /* Initialization */ },
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotJob, gotSchedule, err := CreateJobAndSchedulerFromImport(tt.input)
if (err != nil) != tt.wantErr {
t.Errorf("CreateJobAndSchedulerFromImport() error = %v, wantErr %v", err, tt.wantErr)
return
}
assert.Equal(t, JobID(tt.input.ID), gotJob.GetID(), "Job ID mismatch")
assert.Equal(t, Priority(tt.input.Priority), gotJob.GetPriority(), "Job Priority mismatch")