shipit-engine 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/concerns/shipit/api/cacheable.rb +13 -0
- data/app/controllers/concerns/shipit/api/paginable.rb +37 -0
- data/app/controllers/concerns/shipit/api/rendering.rb +25 -0
- data/app/controllers/concerns/{api/paginable.rb → shipit/pagination.rb} +5 -13
- data/app/controllers/shipit/api/base_controller.rb +68 -0
- data/app/controllers/shipit/api/deploys_controller.rb +17 -0
- data/app/controllers/shipit/api/hooks_controller.rb +53 -0
- data/app/controllers/shipit/api/locks_controller.rb +32 -0
- data/app/controllers/shipit/api/outputs_controller.rb +17 -0
- data/app/controllers/shipit/api/stacks_controller.rb +21 -0
- data/app/controllers/shipit/api/tasks_controller.rb +20 -0
- data/app/controllers/shipit/commit_checks_controller.rb +26 -0
- data/app/controllers/shipit/deploys_controller.rb +47 -0
- data/app/controllers/shipit/github_authentication_controller.rb +27 -0
- data/app/controllers/shipit/rollbacks_controller.rb +26 -0
- data/app/controllers/shipit/shipit_controller.rb +62 -0
- data/app/controllers/shipit/stacks_controller.rb +81 -0
- data/app/controllers/shipit/status_controller.rb +7 -0
- data/app/controllers/shipit/tasks_controller.rb +48 -0
- data/app/controllers/shipit/webhooks_controller.rb +101 -0
- data/app/helpers/shipit/chunks_helper.rb +8 -0
- data/app/helpers/shipit/deploys_helper.rb +28 -0
- data/app/helpers/shipit/github_url_helper.rb +48 -0
- data/app/helpers/shipit/shipit_helper.rb +64 -0
- data/app/helpers/shipit/stacks_helper.rb +78 -0
- data/app/helpers/shipit/tasks_helper.rb +11 -0
- data/app/jobs/shipit/background_job.rb +24 -0
- data/app/jobs/shipit/background_job/unique.rb +28 -0
- data/app/jobs/shipit/cache_deploy_spec_job.rb +12 -0
- data/app/jobs/shipit/chunk_rollup_job.rb +21 -0
- data/app/jobs/shipit/clear_git_cache_job.rb +9 -0
- data/app/jobs/shipit/deliver_hook_job.rb +9 -0
- data/app/jobs/shipit/destroy_stack_job.rb +9 -0
- data/app/jobs/shipit/emit_event_job.rb +10 -0
- data/app/jobs/shipit/fetch_commit_stats_job.rb +9 -0
- data/app/jobs/shipit/fetch_deployed_revision_job.rb +23 -0
- data/app/jobs/shipit/git_mirror_update_job.rb +12 -0
- data/app/jobs/shipit/github_sync_job.rb +55 -0
- data/app/jobs/shipit/perform_commit_checks_job.rb +7 -0
- data/app/jobs/shipit/perform_task_job.rb +57 -0
- data/app/jobs/shipit/refresh_github_user_job.rb +9 -0
- data/app/jobs/shipit/refresh_statuses_job.rb +14 -0
- data/app/jobs/shipit/setup_github_hook_job.rb +11 -0
- data/app/models/shipit/anonymous_user.rb +43 -0
- data/app/models/shipit/api_client.rb +44 -0
- data/app/models/shipit/commit.rb +209 -0
- data/app/models/shipit/commit_checks.rb +90 -0
- data/app/models/shipit/delivery.rb +47 -0
- data/app/models/shipit/deploy.rb +153 -0
- data/app/models/shipit/deploy_spec.rb +150 -0
- data/app/models/shipit/deploy_spec/bundler_discovery.rb +61 -0
- data/app/models/shipit/deploy_spec/capistrano_discovery.rb +29 -0
- data/app/models/shipit/deploy_spec/file_system.rb +64 -0
- data/app/models/shipit/deploy_spec/pypi_discovery.rb +34 -0
- data/app/models/shipit/deploy_spec/rubygems_discovery.rb +34 -0
- data/app/models/shipit/github_hook.rb +148 -0
- data/app/models/shipit/hook.rb +86 -0
- data/app/models/shipit/membership.rb +8 -0
- data/app/models/shipit/missing_status.rb +21 -0
- data/app/models/shipit/output_chunk.rb +11 -0
- data/app/models/shipit/rollback.rb +31 -0
- data/app/models/shipit/stack.rb +308 -0
- data/app/models/shipit/status.rb +44 -0
- data/app/models/shipit/status_group.rb +35 -0
- data/app/models/shipit/task.rb +201 -0
- data/app/models/shipit/task_definition.rb +38 -0
- data/app/models/shipit/team.rb +69 -0
- data/app/models/shipit/unknown_status.rb +43 -0
- data/app/models/shipit/user.rb +83 -0
- data/app/models/shipit/variable_definition.rb +21 -0
- data/app/serializers/concerns/shipit/conditional_attributes.rb +22 -0
- data/app/serializers/shipit/anonymous_user_serializer.rb +4 -0
- data/app/serializers/shipit/commit_serializer.rb +8 -0
- data/app/serializers/shipit/deploy_serializer.rb +15 -0
- data/app/serializers/shipit/hook_serializer.rb +12 -0
- data/app/serializers/shipit/rollback_serializer.rb +7 -0
- data/app/serializers/shipit/short_commit_serializer.rb +9 -0
- data/app/serializers/shipit/stack_serializer.rb +33 -0
- data/app/serializers/shipit/tail_task_serializer.rb +39 -0
- data/app/serializers/shipit/task_serializer.rb +30 -0
- data/app/serializers/shipit/user_serializer.rb +5 -0
- data/app/views/{commits → shipit/commits}/_commit.html.erb +1 -1
- data/app/views/{commits → shipit/commits}/_commit_author.html.erb +0 -0
- data/app/views/{deploys → shipit/deploys}/_checklist.html.erb +0 -0
- data/app/views/{deploys → shipit/deploys}/_checks.html.erb +0 -0
- data/app/views/{deploys → shipit/deploys}/_concurrent_deploy_warning.html.erb +0 -0
- data/app/views/{deploys → shipit/deploys}/_deploy.html.erb +1 -1
- data/app/views/{deploys → shipit/deploys}/_monitoring.html.erb +0 -0
- data/app/views/{deploys → shipit/deploys}/_summary.html.erb +0 -0
- data/app/views/{deploys → shipit/deploys}/new.html.erb +3 -3
- data/app/views/{deploys → shipit/deploys}/rollback.html.erb +2 -2
- data/app/views/{deploys → shipit/deploys}/show.html.erb +1 -1
- data/app/views/{github_authentication → shipit/github_authentication}/failed.html.erb +0 -0
- data/app/views/{stacks → shipit/stacks}/_header.html.erb +0 -0
- data/app/views/{stacks → shipit/stacks}/index.html.erb +0 -0
- data/app/views/{stacks → shipit/stacks}/new.html.erb +0 -0
- data/app/views/{stacks → shipit/stacks}/settings.html.erb +1 -1
- data/app/views/{stacks → shipit/stacks}/show.html.erb +2 -2
- data/app/views/{statuses → shipit/statuses}/_group.html.erb +1 -1
- data/app/views/{statuses → shipit/statuses}/_status.html.erb +0 -0
- data/app/views/{tasks → shipit/tasks}/_task.html.erb +1 -1
- data/app/views/{tasks → shipit/tasks}/_task_output.html.erb +1 -1
- data/app/views/{tasks → shipit/tasks}/index.html.erb +1 -1
- data/app/views/{tasks → shipit/tasks}/new.html.erb +1 -1
- data/app/views/{tasks → shipit/tasks}/show.html.erb +1 -1
- data/db/migrate/20160104151742_increase_tasks_type_size_back.rb +5 -0
- data/db/migrate/20160104151833_convert_sti_columns.rb +10 -0
- data/lib/shipit.rb +11 -10
- data/lib/shipit/command.rb +171 -0
- data/lib/shipit/commands.rb +25 -0
- data/lib/shipit/deploy_commands.rb +21 -0
- data/lib/shipit/engine.rb +3 -0
- data/lib/shipit/rollback_commands.rb +7 -0
- data/lib/shipit/stack_commands.rb +60 -0
- data/lib/shipit/task_commands.rb +68 -0
- data/lib/shipit/version.rb +1 -1
- data/lib/tasks/cron.rake +3 -3
- data/test/controllers/api/base_controller_test.rb +18 -14
- data/test/controllers/api/deploys_controller_test.rb +56 -52
- data/test/controllers/api/hooks_controller_test.rb +62 -58
- data/test/controllers/api/locks_controller_test.rb +38 -34
- data/test/controllers/api/outputs_controller_test.rb +15 -11
- data/test/controllers/api/stacks_controller_test.rb +56 -52
- data/test/controllers/api/tasks_controller_test.rb +30 -26
- data/test/controllers/commit_checks_controller_test.rb +29 -27
- data/test/controllers/deploys_controller_test.rb +68 -66
- data/test/controllers/github_authentication_controller_test.rb +9 -7
- data/test/controllers/rollbacks_controller_test.rb +43 -41
- data/test/controllers/stacks_controller_test.rb +131 -128
- data/test/controllers/status_controller_test.rb +8 -6
- data/test/controllers/tasks_controller_test.rb +70 -68
- data/test/controllers/webhooks_controller_test.rb +127 -125
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/schema.rb +2 -2
- data/test/dummy/db/seeds.rb +133 -131
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/fixtures/{api_clients.yml → shipit/api_clients.yml} +0 -0
- data/test/fixtures/{commits.yml → shipit/commits.yml} +0 -0
- data/test/fixtures/{deliveries.yml → shipit/deliveries.yml} +0 -0
- data/test/fixtures/{github_hooks.yml → shipit/github_hooks.yml} +4 -4
- data/test/fixtures/{hooks.yml → shipit/hooks.yml} +0 -0
- data/test/fixtures/{memberships.yml → shipit/memberships.yml} +0 -0
- data/test/fixtures/{output_chunks.yml → shipit/output_chunks.yml} +0 -0
- data/test/fixtures/{stacks.yml → shipit/stacks.yml} +0 -0
- data/test/fixtures/{statuses.yml → shipit/statuses.yml} +0 -0
- data/test/fixtures/{tasks.yml → shipit/tasks.yml} +8 -8
- data/test/fixtures/{teams.yml → shipit/teams.yml} +0 -0
- data/test/fixtures/{users.yml → shipit/users.yml} +0 -0
- data/test/helpers/api_helper.rb +1 -1
- data/test/helpers/fixture_aliases_helper.rb +4 -4
- data/test/jobs/cache_deploy_spec_job_test.rb +15 -13
- data/test/jobs/chunk_rollup_job_test.rb +30 -28
- data/test/jobs/deliver_hook_job_test.rb +11 -9
- data/test/jobs/destroy_stack_job_test.rb +11 -9
- data/test/jobs/emit_event_job_test.rb +10 -8
- data/test/jobs/fetch_commit_stats_job_test.rb +10 -8
- data/test/jobs/fetch_deployed_revision_job_test.rb +24 -22
- data/test/jobs/github_sync_job_test.rb +51 -49
- data/test/jobs/perform_task_job_test.rb +78 -76
- data/test/jobs/refresh_github_user_job_test.rb +10 -8
- data/test/jobs/refresh_status_job_test.rb +14 -12
- data/test/jobs/unique_job_test.rb +18 -15
- data/test/models/api_client_test.rb +20 -18
- data/test/models/commit_checks_test.rb +63 -61
- data/test/models/commits_test.rb +317 -314
- data/test/models/delivery_test.rb +29 -27
- data/test/models/deploys_test.rb +289 -287
- data/test/models/github_hook_test.rb +45 -43
- data/test/models/hook_test.rb +44 -42
- data/test/models/membership_test.rb +9 -7
- data/test/models/missing_status_test.rb +16 -14
- data/test/models/output_chunk_test.rb +14 -12
- data/test/models/rollbacks_test.rb +14 -12
- data/test/models/stacks_test.rb +272 -270
- data/test/models/status_group_test.rb +18 -16
- data/test/models/status_test.rb +42 -40
- data/test/models/task_definitions_test.rb +27 -25
- data/test/models/team_test.rb +39 -37
- data/test/models/users_test.rb +61 -59
- data/test/unit/command_test.rb +43 -41
- data/test/unit/commands_test.rb +8 -6
- data/test/unit/csv_serializer_test.rb +28 -26
- data/test/unit/deploy_commands_test.rb +179 -176
- data/test/unit/deploy_spec_test.rb +237 -235
- data/test/unit/github_url_helper_test.rb +19 -17
- data/test/unit/shipit_test.rb +44 -42
- metadata +139 -137
- data/app/controllers/api/base_controller.rb +0 -66
- data/app/controllers/api/deploys_controller.rb +0 -15
- data/app/controllers/api/hooks_controller.rb +0 -51
- data/app/controllers/api/locks_controller.rb +0 -30
- data/app/controllers/api/outputs_controller.rb +0 -15
- data/app/controllers/api/stacks_controller.rb +0 -19
- data/app/controllers/api/tasks_controller.rb +0 -18
- data/app/controllers/commit_checks_controller.rb +0 -24
- data/app/controllers/concerns/api/cacheable.rb +0 -11
- data/app/controllers/concerns/api/rendering.rb +0 -23
- data/app/controllers/concerns/pagination.rb +0 -25
- data/app/controllers/deploys_controller.rb +0 -45
- data/app/controllers/github_authentication_controller.rb +0 -25
- data/app/controllers/rollbacks_controller.rb +0 -24
- data/app/controllers/shipit_controller.rb +0 -54
- data/app/controllers/stacks_controller.rb +0 -79
- data/app/controllers/status_controller.rb +0 -5
- data/app/controllers/tasks_controller.rb +0 -46
- data/app/controllers/webhooks_controller.rb +0 -99
- data/app/helpers/chunks_helper.rb +0 -6
- data/app/helpers/deploys_helper.rb +0 -26
- data/app/helpers/github_url_helper.rb +0 -46
- data/app/helpers/shipit_helper.rb +0 -62
- data/app/helpers/stacks_helper.rb +0 -76
- data/app/helpers/tasks_helper.rb +0 -9
- data/app/jobs/background_job.rb +0 -22
- data/app/jobs/background_job/unique.rb +0 -26
- data/app/jobs/cache_deploy_spec_job.rb +0 -10
- data/app/jobs/chunk_rollup_job.rb +0 -19
- data/app/jobs/clear_git_cache_job.rb +0 -7
- data/app/jobs/deliver_hook_job.rb +0 -7
- data/app/jobs/destroy_stack_job.rb +0 -7
- data/app/jobs/emit_event_job.rb +0 -8
- data/app/jobs/fetch_commit_stats_job.rb +0 -7
- data/app/jobs/fetch_deployed_revision_job.rb +0 -21
- data/app/jobs/git_mirror_update_job.rb +0 -10
- data/app/jobs/github_sync_job.rb +0 -53
- data/app/jobs/perform_commit_checks_job.rb +0 -5
- data/app/jobs/perform_task_job.rb +0 -55
- data/app/jobs/refresh_github_user_job.rb +0 -7
- data/app/jobs/refresh_statuses_job.rb +0 -12
- data/app/jobs/setup_github_hook_job.rb +0 -9
- data/app/models/anonymous_user.rb +0 -41
- data/app/models/api_client.rb +0 -42
- data/app/models/commit.rb +0 -207
- data/app/models/commit_checks.rb +0 -88
- data/app/models/delivery.rb +0 -45
- data/app/models/deploy.rb +0 -151
- data/app/models/deploy_spec.rb +0 -148
- data/app/models/deploy_spec/bundler_discovery.rb +0 -59
- data/app/models/deploy_spec/capistrano_discovery.rb +0 -27
- data/app/models/deploy_spec/file_system.rb +0 -62
- data/app/models/deploy_spec/pypi_discovery.rb +0 -32
- data/app/models/deploy_spec/rubygems_discovery.rb +0 -32
- data/app/models/github_hook.rb +0 -144
- data/app/models/hook.rb +0 -84
- data/app/models/membership.rb +0 -6
- data/app/models/missing_status.rb +0 -18
- data/app/models/output_chunk.rb +0 -9
- data/app/models/rollback.rb +0 -29
- data/app/models/stack.rb +0 -306
- data/app/models/status.rb +0 -42
- data/app/models/status_group.rb +0 -33
- data/app/models/task.rb +0 -197
- data/app/models/task_definition.rb +0 -36
- data/app/models/team.rb +0 -67
- data/app/models/unknown_status.rb +0 -41
- data/app/models/user.rb +0 -81
- data/app/models/variable_definition.rb +0 -19
- data/app/serializers/anonymous_user_serializer.rb +0 -2
- data/app/serializers/commit_serializer.rb +0 -6
- data/app/serializers/concerns/conditional_attributes.rb +0 -20
- data/app/serializers/deploy_serializer.rb +0 -13
- data/app/serializers/hook_serializer.rb +0 -10
- data/app/serializers/rollback_serializer.rb +0 -5
- data/app/serializers/short_commit_serializer.rb +0 -7
- data/app/serializers/stack_serializer.rb +0 -31
- data/app/serializers/tail_task_serializer.rb +0 -37
- data/app/serializers/task_serializer.rb +0 -28
- data/app/serializers/user_serializer.rb +0 -3
- data/lib/command.rb +0 -169
- data/lib/commands.rb +0 -23
- data/lib/deploy_commands.rb +0 -19
- data/lib/rollback_commands.rb +0 -5
- data/lib/stack_commands.rb +0 -58
- data/lib/task_commands.rb +0 -66
@@ -1,21 +1,23 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
require 'tmpdir'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
module Shipit
|
5
|
+
class CacheDeploySpecJobTest < ActiveSupport::TestCase
|
6
|
+
setup do
|
7
|
+
@stack = shipit_stacks(:shipit)
|
8
|
+
@last_commit = shipit_commits(:fifth)
|
9
|
+
@job = CacheDeploySpecJob.new
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
12
|
+
test "#perform checkout the repository to the last recorded commit and cache the deploy spec" do
|
13
|
+
@stack.update!(cached_deploy_spec: DeploySpec.new('review' => {'checklist' => %w(foo bar)}))
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
dir = Pathname(Dir.tmpdir)
|
16
|
+
StackCommands.any_instance.expects(:with_temporary_working_directory).with(commit: @last_commit).yields(dir)
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
assert_equal %w(foo bar), @stack.checklist
|
19
|
+
@job.perform(@stack)
|
20
|
+
assert_equal [], @stack.reload.checklist
|
21
|
+
end
|
20
22
|
end
|
21
23
|
end
|
@@ -1,41 +1,43 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
module Shipit
|
4
|
+
class ChunkRollupJobTest < ActiveSupport::TestCase
|
5
|
+
setup do
|
6
|
+
@task = shipit_tasks(:shipit)
|
7
|
+
@job = ChunkRollupJob.new
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
test "#perform combines all the chunks into a output and sets rolled_up to true" do
|
11
|
+
expected_output = @task.chunk_output
|
12
|
+
assert @task.output.blank?
|
12
13
|
|
13
|
-
|
14
|
+
@job.perform(@task)
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
@task.reload
|
17
|
+
assert_equal 0, @task.chunks.count
|
18
|
+
assert @task.output.present?
|
19
|
+
assert_equal expected_output, @task.chunk_output
|
20
|
+
assert @task.rolled_up
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
test "#peform ignores non-finished jobs" do
|
24
|
+
logger = mock
|
25
|
+
logger.expects(:error).once
|
26
|
+
@job.stubs(logger: logger)
|
26
27
|
|
27
|
-
|
28
|
+
@task.update_attribute(:status, :pending)
|
28
29
|
|
29
|
-
|
30
|
-
|
30
|
+
@job.perform(@task)
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
test "#perform ignores tasks already rolled up" do
|
34
|
+
logger = mock
|
35
|
+
logger.expects(:error).once
|
36
|
+
@job.stubs(logger: logger)
|
36
37
|
|
37
|
-
|
38
|
+
@task.rolled_up = true
|
38
39
|
|
39
|
-
|
40
|
+
@job.perform(@task)
|
41
|
+
end
|
40
42
|
end
|
41
43
|
end
|
@@ -1,14 +1,16 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
module Shipit
|
4
|
+
class DeliverHookJobTest < ActiveSupport::TestCase
|
5
|
+
setup do
|
6
|
+
@delivery = shipit_deliveries(:scheduled_shipit_deploy)
|
7
|
+
@job = DeliverHookJob.new
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
test "#perform delivers a delivery" do
|
11
|
+
FakeWeb.register_uri(:post, @delivery.url, body: 'OK')
|
12
|
+
@job.perform(@delivery)
|
13
|
+
assert_equal 'sent', @delivery.reload.status
|
14
|
+
end
|
13
15
|
end
|
14
16
|
end
|
@@ -1,16 +1,18 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
module Shipit
|
4
|
+
class DestroyStackJobTest < ActiveSupport::TestCase
|
5
|
+
setup do
|
6
|
+
@job = DestroyStackJob.new
|
7
|
+
@stack = Stack.first
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
test "perform destroys the received stack" do
|
11
|
+
Shipit.github_api.expects(:remove_hook).times(@stack.github_hooks.count)
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
assert_difference -> { Stack.count }, -1 do
|
14
|
+
@job.perform(@stack)
|
15
|
+
end
|
14
16
|
end
|
15
17
|
end
|
16
18
|
end
|
@@ -1,14 +1,16 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
module Shipit
|
4
|
+
class EmitEventJobTest < ActiveSupport::TestCase
|
5
|
+
setup do
|
6
|
+
@stack = shipit_stacks(:shipit)
|
7
|
+
@job = EmitEventJob.new
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
test "#perform schedule deliveries" do
|
11
|
+
assert_difference -> { Delivery.scheduled.count }, 2 do
|
12
|
+
@job.perform(event: :deploy, stack_id: @stack.id, payload: {foo: 42}.to_json)
|
13
|
+
end
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
@@ -1,13 +1,15 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
module Shipit
|
4
|
+
class FetchCommitStatsJobTest < ActiveSupport::TestCase
|
5
|
+
setup do
|
6
|
+
@commit = shipit_commits(:first)
|
7
|
+
@job = FetchCommitStatsJob.new
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
test "#perform call #fetch_stats! on the provided commit" do
|
11
|
+
@commit.expects(:fetch_stats!).once
|
12
|
+
@job.perform(@commit)
|
13
|
+
end
|
12
14
|
end
|
13
15
|
end
|
@@ -1,30 +1,32 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
module Shipit
|
4
|
+
class FetchDeployedRevisionJobTest < ActiveSupport::TestCase
|
5
|
+
setup do
|
6
|
+
@stack = shipit_stacks(:shipit)
|
7
|
+
@job = FetchDeployedRevisionJob.new
|
8
|
+
@commit = shipit_commits(:fifth)
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
test 'the job abort if the stack is deploying' do
|
12
|
+
@stack.expects(:deploying?).returns(true)
|
13
|
+
assert_no_difference 'Deploy.count' do
|
14
|
+
@job.perform(@stack)
|
15
|
+
end
|
14
16
|
end
|
15
|
-
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
test 'the job abort if #fetch_deployed_revision returns nil' do
|
19
|
+
@stack.expects(:deploying?).returns(false)
|
20
|
+
StackCommands.any_instance.expects(:fetch_deployed_revision).returns(nil)
|
21
|
+
@stack.expects(:update_deployed_revision).never
|
22
|
+
@job.perform(@stack)
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
test 'the job call update_deployed_revision if #fetch_deployed_revision returns something' do
|
26
|
+
@stack.expects(:deploying?).returns(false)
|
27
|
+
StackCommands.any_instance.expects(:fetch_deployed_revision).returns(@commit.sha)
|
28
|
+
@stack.expects(:update_deployed_revision).with(@commit.sha)
|
29
|
+
@job.perform(@stack)
|
30
|
+
end
|
29
31
|
end
|
30
32
|
end
|
@@ -1,67 +1,69 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
module Shipit
|
4
|
+
class GithubSyncJobTest < ActiveSupport::TestCase
|
5
|
+
setup do
|
6
|
+
@job = GithubSyncJob.new
|
7
|
+
@stack = shipit_stacks(:shipit)
|
8
|
+
@github_commits = stub
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
test "#perform fetch commits from the API" do
|
12
|
+
Stack.any_instance.expects(:github_commits).returns(@github_commits)
|
13
|
+
@job.expects(:fetch_missing_commits).yields.returns([[], nil])
|
14
|
+
@job.perform(stack_id: @stack.id)
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
test "#perform finally enqueue a CacheDeploySpecJob" do
|
18
|
+
Stack.any_instance.stubs(:github_commits).returns(@github_commits)
|
19
|
+
@job.stubs(:fetch_missing_commits).yields.returns([[], nil])
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
assert_enqueued_with(job: CacheDeploySpecJob, args: [@stack]) do
|
22
|
+
@job.perform(stack_id: @stack.id)
|
23
|
+
end
|
22
24
|
end
|
23
|
-
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
26
|
+
test "#perform mark all childs of the common parent as detached" do
|
27
|
+
Stack.any_instance.expects(:github_commits).returns(@github_commits)
|
28
|
+
@job.expects(:fetch_missing_commits).yields.returns([[], shipit_commits(:third)])
|
28
29
|
|
29
|
-
|
30
|
-
|
30
|
+
refute shipit_commits(:fourth).reload.detached?
|
31
|
+
refute shipit_commits(:fifth).reload.detached?
|
31
32
|
|
32
|
-
|
33
|
+
@job.perform(stack_id: @stack.id)
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
assert shipit_commits(:fourth).reload.detached?
|
36
|
+
assert shipit_commits(:fifth).reload.detached?
|
37
|
+
end
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
test "#fetch_missing_commits returns the commits in the reverse order if it doesn't know the parent" do
|
40
|
+
last = stub(sha: 123)
|
41
|
+
first = stub(sha: 345)
|
42
|
+
Shipit::FirstParentCommitsIterator.any_instance.stubs(:each).multiple_yields(last, first)
|
43
|
+
@job.stubs(lookup_commit: nil)
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
commits, parent = @job.fetch_missing_commits { stub }
|
46
|
+
assert_nil parent
|
47
|
+
assert_equal [first, last], commits
|
48
|
+
end
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
50
|
+
test "#fetch_missing_commits returns the commits in the reverse order if it knows the parent" do
|
51
|
+
last = stub(sha: 123)
|
52
|
+
first = stub(sha: 345)
|
53
|
+
Shipit::FirstParentCommitsIterator.any_instance.stubs(:each).multiple_yields(last, first)
|
54
|
+
@job.stubs(:lookup_commit).with(123).returns(nil)
|
55
|
+
@job.stubs(:lookup_commit).with(345).returns(first)
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
commits, parent = @job.fetch_missing_commits { stub }
|
58
|
+
assert_equal first, parent
|
59
|
+
assert_equal [last], commits
|
60
|
+
end
|
60
61
|
|
61
|
-
|
62
|
-
|
63
|
-
|
62
|
+
test "if GitHub returns a 404, the stacks is marked as inaccessible" do
|
63
|
+
@job.expects(:fetch_missing_commits).raises(Octokit::NotFound)
|
64
|
+
@job.perform(stack_id: @stack.id)
|
64
65
|
|
65
|
-
|
66
|
+
assert_equal true, @stack.reload.inaccessible_since?
|
67
|
+
end
|
66
68
|
end
|
67
69
|
end
|
@@ -1,102 +1,104 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
test "#perform fetch commits from the API" do
|
11
|
-
@job.stubs(:capture)
|
12
|
-
@commands = stub(:commands)
|
13
|
-
Commands.expects(:for).with(@deploy).returns(@commands)
|
14
|
-
|
15
|
-
@commands.expects(:fetch).once
|
16
|
-
@commands.expects(:clone).once
|
17
|
-
@commands.expects(:checkout).with(@deploy.until_commit).once
|
18
|
-
@commands.expects(:install_dependencies).returns([]).once
|
19
|
-
@commands.expects(:perform).returns([]).once
|
3
|
+
module Shipit
|
4
|
+
class PerformTaskJobTest < ActiveSupport::TestCase
|
5
|
+
setup do
|
6
|
+
@job = PerformTaskJob.new
|
7
|
+
@deploy = shipit_deploys(:shipit_pending)
|
8
|
+
@stack = shipit_stacks(:shipit)
|
9
|
+
end
|
20
10
|
|
21
|
-
|
11
|
+
test "#perform fetch commits from the API" do
|
12
|
+
@job.stubs(:capture)
|
13
|
+
@commands = stub(:commands)
|
14
|
+
Commands.expects(:for).with(@deploy).returns(@commands)
|
22
15
|
|
23
|
-
|
24
|
-
|
16
|
+
@commands.expects(:fetch).once
|
17
|
+
@commands.expects(:clone).once
|
18
|
+
@commands.expects(:checkout).with(@deploy.until_commit).once
|
19
|
+
@commands.expects(:install_dependencies).returns([]).once
|
20
|
+
@commands.expects(:perform).returns([]).once
|
25
21
|
|
26
|
-
|
27
|
-
Dir.stubs(:chdir).yields
|
28
|
-
DeployCommands.any_instance.expects(:perform).returns([])
|
29
|
-
@job.stubs(:capture)
|
22
|
+
@deploy.expects(:clear_working_directory)
|
30
23
|
|
31
|
-
Hook.expects(:emit).twice
|
32
|
-
assert_enqueued_with(job: FetchDeployedRevisionJob, args: [@deploy.stack]) do
|
33
24
|
@job.perform(@deploy)
|
34
25
|
end
|
35
|
-
end
|
36
26
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
27
|
+
test "#perform enqueues a FetchDeployedRevisionJob" do
|
28
|
+
Dir.stubs(:chdir).yields
|
29
|
+
DeployCommands.any_instance.expects(:perform).returns([])
|
30
|
+
@job.stubs(:capture)
|
41
31
|
|
42
|
-
|
43
|
-
|
44
|
-
|
32
|
+
Hook.expects(:emit).twice
|
33
|
+
assert_enqueued_with(job: FetchDeployedRevisionJob, args: [@deploy.stack]) do
|
34
|
+
@job.perform(@deploy)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
test "marks deploy as successful" do
|
39
|
+
Dir.stubs(:chdir).yields
|
40
|
+
DeployCommands.any_instance.expects(:perform).returns([])
|
41
|
+
@job.stubs(:capture)
|
45
42
|
|
46
|
-
test "marks deploy as `error` if any application error is raised" do
|
47
|
-
@job.expects(:capture).raises("some error")
|
48
|
-
assert_nothing_raised do
|
49
43
|
@job.perform(@deploy)
|
44
|
+
assert_equal 'success', @deploy.reload.status
|
50
45
|
end
|
51
|
-
assert_equal 'error', @deploy.reload.status
|
52
|
-
assert_includes @deploy.chunk_output, 'RuntimeError: some error'
|
53
|
-
end
|
54
46
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
47
|
+
test "marks deploy as `error` if any application error is raised" do
|
48
|
+
@job.expects(:capture).raises("some error")
|
49
|
+
assert_nothing_raised do
|
50
|
+
@job.perform(@deploy)
|
51
|
+
end
|
52
|
+
assert_equal 'error', @deploy.reload.status
|
53
|
+
assert_includes @deploy.chunk_output, 'RuntimeError: some error'
|
54
|
+
end
|
60
55
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
56
|
+
test "marks deploy as `failed` if a command exit with an error code" do
|
57
|
+
@job.expects(:capture).raises(Command::Error.new('something'))
|
58
|
+
@job.perform(@deploy)
|
59
|
+
assert_equal 'failed', @deploy.reload.status
|
60
|
+
end
|
66
61
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
assert_nothing_raised do
|
62
|
+
test "bail out if deploy is not pending" do
|
63
|
+
@deploy.run!
|
64
|
+
@job.expects(:capture).never
|
71
65
|
@job.perform(@deploy)
|
72
66
|
end
|
73
|
-
assert @deploy.reload.error?
|
74
|
-
assert_includes @deploy.chunk_output, 'Timeout::Error'
|
75
|
-
end
|
76
67
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
@deploy.stubs(:clear_working_directory)
|
68
|
+
test "mark deploy as error if a command timeout" do
|
69
|
+
Timeout.expects(:timeout).raises(Timeout::Error.new)
|
70
|
+
Command.any_instance.expects(:terminate!)
|
71
|
+
assert_nothing_raised do
|
72
|
+
@job.perform(@deploy)
|
73
|
+
end
|
74
|
+
assert @deploy.reload.error?
|
75
|
+
assert_includes @deploy.chunk_output, 'Timeout::Error'
|
76
|
+
end
|
87
77
|
|
88
|
-
|
78
|
+
test "records stack support for rollbacks and fetching deployed revision" do
|
79
|
+
@job.stubs(:capture)
|
80
|
+
@commands = stub(:commands)
|
81
|
+
@commands.stubs(:fetch).returns([])
|
82
|
+
@commands.stubs(:clone).returns([])
|
83
|
+
@commands.stubs(:checkout).returns([])
|
84
|
+
@commands.stubs(:install_dependencies).returns([])
|
85
|
+
@commands.stubs(:perform).returns([])
|
86
|
+
DeployCommands.expects(:new).with(@deploy).returns(@commands)
|
87
|
+
@deploy.stubs(:clear_working_directory)
|
89
88
|
|
90
|
-
|
91
|
-
refute @stack.supports_fetch_deployed_revision?
|
89
|
+
@stack.update!(cached_deploy_spec: DeploySpec.new({}))
|
92
90
|
|
93
|
-
|
94
|
-
|
91
|
+
refute @stack.supports_rollback?
|
92
|
+
refute @stack.supports_fetch_deployed_revision?
|
95
93
|
|
96
|
-
|
97
|
-
|
94
|
+
@job.perform(@deploy)
|
95
|
+
@stack.reload
|
98
96
|
|
99
|
-
|
100
|
-
|
97
|
+
DeploySpec.any_instance.expects(:supports_fetch_deployed_revision?).returns(true)
|
98
|
+
DeploySpec.any_instance.expects(:supports_rollback?).returns(true)
|
99
|
+
|
100
|
+
assert @stack.supports_rollback?
|
101
|
+
assert @stack.supports_fetch_deployed_revision?
|
102
|
+
end
|
101
103
|
end
|
102
104
|
end
|