Files
GoMFT/internal/scheduler/mock_scheduler_test.go
T
StarFleetCPTN 8607f2098a feat: Integrate Google Drive support and enhance configuration handling
- Add Google Drive as a source and destination option in the configuration forms.
- Implement Google Drive authentication flow and token management.
- Update job and configuration handlers to support Google Drive-specific settings.
- Enhance UI components to include Google Drive configuration templates.
- Introduce new tests for Google Drive integration and ensure proper handling of authentication and configuration.
- Update database migrations to accommodate new fields related to Google Drive configurations.
2025-03-15 17:36:36 -07:00

76 lines
2.1 KiB
Go

package scheduler
import (
"testing"
"github.com/starfleetcptn/gomft/internal/db"
"github.com/stretchr/testify/assert"
)
func TestMockScheduler_MultiConfig(t *testing.T) {
// Create a new mock scheduler
mockScheduler := NewMockScheduler()
// Create a job with multiple configurations
job := &db.Job{
ID: 1,
Name: "Multi-Config Test Job",
Schedule: "*/5 * * * *",
ConfigID: 1, // Primary config ID
}
job.SetEnabled(true)
// Set multiple config IDs
job.SetConfigIDsList([]uint{1, 2, 3})
// Schedule the job
err := mockScheduler.ScheduleJob(job)
assert.NoError(t, err)
// Check if the job is marked as scheduled
assert.True(t, mockScheduler.ScheduledJobs[job.ID])
// Verify that the job is detected as having multiple configs
assert.True(t, mockScheduler.IsJobWithMultipleConfigs(job.ID))
// Verify the configs associated with the job
configs := mockScheduler.GetConfigsForJob(job.ID)
assert.Len(t, configs, 3)
assert.Contains(t, configs, uint(1))
assert.Contains(t, configs, uint(2))
assert.Contains(t, configs, uint(3))
// Test unscheduling the job
mockScheduler.UnscheduleJob(job.ID)
assert.True(t, mockScheduler.UnscheduledJobs[job.ID])
assert.False(t, mockScheduler.ScheduledJobs[job.ID])
// Verify the job is no longer tracked in multi-config jobs
assert.False(t, mockScheduler.IsJobWithMultipleConfigs(job.ID))
assert.Empty(t, mockScheduler.GetConfigsForJob(job.ID))
// Test a job with a single config
singleConfigJob := &db.Job{
ID: 2,
Name: "Single Config Job",
Schedule: "0 0 * * *",
ConfigID: 4,
}
singleConfigJob.SetEnabled(true)
// Set a single config ID
singleConfigJob.SetConfigIDsList([]uint{4})
// Schedule the job
err = mockScheduler.ScheduleJob(singleConfigJob)
assert.NoError(t, err)
// Not considered a multi-config job if it has only one config
assert.False(t, mockScheduler.IsJobWithMultipleConfigs(singleConfigJob.ID))
// Should still contain the single config
singleConfigs := mockScheduler.GetConfigsForJob(singleConfigJob.ID)
assert.Len(t, singleConfigs, 1)
assert.Contains(t, singleConfigs, uint(4))
}