summaryrefslogtreecommitdiff
path: root/spec/workers/trigger_schedule_worker_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/workers/trigger_schedule_worker_spec.rb')
-rw-r--r--spec/workers/trigger_schedule_worker_spec.rb58
1 files changed, 58 insertions, 0 deletions
diff --git a/spec/workers/trigger_schedule_worker_spec.rb b/spec/workers/trigger_schedule_worker_spec.rb
new file mode 100644
index 00000000000..151e1c2f7b9
--- /dev/null
+++ b/spec/workers/trigger_schedule_worker_spec.rb
@@ -0,0 +1,58 @@
+require 'spec_helper'
+
+describe TriggerScheduleWorker do
+ let(:worker) { described_class.new }
+
+ before do
+ stub_ci_pipeline_to_return_yaml_file
+ end
+
+ context 'when there is a scheduled trigger within next_run_at' do
+ before do
+ trigger_schedule = create(:ci_trigger_schedule, :nightly)
+ time_future = Time.now + 10.days
+ allow(Time).to receive(:now).and_return(time_future)
+ @next_time = Gitlab::Ci::CronParser.new(trigger_schedule.cron, trigger_schedule.cron_timezone).next_time_from(time_future)
+ end
+
+ it 'creates a new trigger request' do
+ expect { worker.perform }.to change { Ci::TriggerRequest.count }.by(1)
+ end
+
+ it 'creates a new pipeline' do
+ expect { worker.perform }.to change { Ci::Pipeline.count }.by(1)
+ expect(Ci::Pipeline.last).to be_pending
+ end
+
+ it 'updates next_run_at' do
+ expect { worker.perform }.to change { Ci::TriggerSchedule.last.next_run_at }.to(@next_time)
+ end
+ end
+
+ context 'when there are no scheduled triggers within next_run_at' do
+ before { create(:ci_trigger_schedule, :nightly) }
+
+ it 'does not create a new pipeline' do
+ expect { worker.perform }.not_to change { Ci::Pipeline.count }
+ end
+
+ it 'does not update next_run_at' do
+ expect { worker.perform }.not_to change { Ci::TriggerSchedule.last.next_run_at }
+ end
+ end
+
+ context 'when next_run_at is nil' do
+ before do
+ trigger_schedule = create(:ci_trigger_schedule, :nightly)
+ trigger_schedule.update_attribute(:next_run_at, nil)
+ end
+
+ it 'does not create a new pipeline' do
+ expect { worker.perform }.not_to change { Ci::Pipeline.count }
+ end
+
+ it 'does not update next_run_at' do
+ expect { worker.perform }.not_to change { Ci::TriggerSchedule.last.next_run_at }
+ end
+ end
+end