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,37 +1,39 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
module Shipit
|
4
|
+
class DeliveryTest < ActiveSupport::TestCase
|
5
|
+
setup do
|
6
|
+
@hook = shipit_hooks(:shipit_deploys)
|
7
|
+
@delivery = shipit_deliveries(:scheduled_shipit_deploy)
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
test "#schedule! enqueue a DeliverHookJob and update the status to `scheduled`" do
|
11
|
+
delivery = @hook.deliveries.create!(
|
12
|
+
event: 'deploy',
|
13
|
+
url: 'http://example.com',
|
14
|
+
content_type: 'application/json',
|
15
|
+
payload: '{}',
|
16
|
+
)
|
17
|
+
assert_equal 'pending', delivery.status
|
17
18
|
|
18
|
-
|
19
|
-
|
19
|
+
assert_enqueued_with(job: DeliverHookJob, args: [delivery]) do
|
20
|
+
delivery.schedule!
|
21
|
+
end
|
22
|
+
assert_equal 'scheduled', delivery.status
|
20
23
|
end
|
21
|
-
assert_equal 'scheduled', delivery.status
|
22
|
-
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
test "#send! post the payload and update the status to `sent`" do
|
26
|
+
headers = {'content-type' => 'text/plain', 'content-length' => '2'}
|
27
|
+
FakeWeb.register_uri(:post, @delivery.url, headers.merge(body: 'OK'))
|
27
28
|
|
28
|
-
|
29
|
-
|
29
|
+
assert_equal 'scheduled', @delivery.status
|
30
|
+
@delivery.send!
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
assert_equal 'sent', @delivery.status
|
33
|
+
assert_not_nil @delivery.delivered_at
|
34
|
+
assert_equal 200, @delivery.response_code
|
35
|
+
assert_equal headers, @delivery.response_headers
|
36
|
+
assert_equal 'OK', @delivery.response_body
|
37
|
+
end
|
36
38
|
end
|
37
39
|
end
|
data/test/models/deploys_test.rb
CHANGED
@@ -1,392 +1,394 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
module Shipit
|
4
|
+
class DeploysTest < ActiveSupport::TestCase
|
5
|
+
def setup
|
6
|
+
@deploy = shipit_deploys(:shipit)
|
7
|
+
@deploy.pid = 42
|
8
|
+
@stack = shipit_stacks(:shipit)
|
9
|
+
@user = shipit_users(:walrus)
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
test "#rollback? returns false" do
|
13
|
+
refute @deploy.rollback?
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
test "enqueue" do
|
17
|
+
assert_enqueued_with(job: PerformTaskJob, args: [@deploy]) do
|
18
|
+
@deploy.enqueue
|
19
|
+
end
|
18
20
|
end
|
19
|
-
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
test "enqueue when not persisted" do
|
23
|
+
assert_raise(RuntimeError) { Deploy.new.enqueue }
|
24
|
+
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
26
|
+
test "working_directory" do
|
27
|
+
assert_equal File.join(@deploy.stack.deploys_path, @deploy.id.to_s), @deploy.working_directory
|
28
|
+
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
test "#since_commit_id returns the database value if present" do
|
31
|
+
@deploy.since_commit_id = 1
|
32
|
+
assert_equal 1, @deploy.since_commit_id
|
33
|
+
end
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
test "#since_commit_id returns nil if stack_id isn't set" do
|
36
|
+
deploy = Deploy.new
|
37
|
+
assert_nil deploy.since_commit_id
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
test "#since_commit_id returns a default value if stack_id is set" do
|
41
|
+
stack = shipit_stacks(:shipit)
|
42
|
+
deploy = stack.deploys.new
|
43
|
+
last = stack.deploys.success.last.until_commit_id
|
44
|
+
assert_equal last, deploy.since_commit_id
|
45
|
+
end
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
test "#commits returns empty array if stack isn't set" do
|
48
|
+
@deploy.expects(:stack).returns(nil)
|
49
|
+
assert_equal [], @deploy.commits
|
50
|
+
end
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
52
|
+
test "additions and deletions are denormalized on before create" do
|
53
|
+
stack = shipit_stacks(:shipit)
|
54
|
+
first = shipit_commits(:first)
|
55
|
+
third = shipit_commits(:third)
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
deploy = stack.deploys.create!(
|
58
|
+
since_commit: first,
|
59
|
+
until_commit: third,
|
60
|
+
)
|
60
61
|
|
61
|
-
|
62
|
-
|
63
|
-
|
62
|
+
assert_equal 13, deploy.additions
|
63
|
+
assert_equal 65, deploy.deletions
|
64
|
+
end
|
64
65
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
66
|
+
test "#commits returns the commits in the id range" do
|
67
|
+
stack = shipit_stacks(:shipit)
|
68
|
+
first = shipit_commits(:first)
|
69
|
+
last = shipit_commits(:third)
|
69
70
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
71
|
+
deploy = stack.deploys.new(
|
72
|
+
since_commit: first,
|
73
|
+
until_commit: last,
|
74
|
+
)
|
74
75
|
|
75
|
-
|
76
|
+
commits = deploy.commits
|
76
77
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
78
|
+
assert_not_empty commits
|
79
|
+
assert_equal last.id, commits.map(&:id).max
|
80
|
+
assert_not_equal first.id, commits.map(&:id).min
|
81
|
+
end
|
81
82
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
83
|
+
test "#commits returns commits from newer to older" do
|
84
|
+
stack = shipit_stacks(:shipit)
|
85
|
+
first = shipit_commits(:first)
|
86
|
+
last = shipit_commits(:fourth)
|
86
87
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
88
|
+
deploy = stack.deploys.new(
|
89
|
+
since_commit: first,
|
90
|
+
until_commit: last,
|
91
|
+
)
|
91
92
|
|
92
|
-
|
93
|
-
|
93
|
+
assert_equal [4, 3, 2], deploy.commits.pluck(:id)
|
94
|
+
end
|
94
95
|
|
95
|
-
|
96
|
-
|
96
|
+
test "transitioning to success causes an event to be broadcasted" do
|
97
|
+
deploy = shipit_deploys(:shipit_pending)
|
97
98
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
99
|
+
expect_hook(:deploy, deploy.stack, status: 'success', deploy: deploy, stack: deploy.stack)
|
100
|
+
expect_event(deploy)
|
101
|
+
deploy.status = 'running'
|
102
|
+
deploy.complete!
|
103
|
+
end
|
103
104
|
|
104
|
-
|
105
|
-
|
105
|
+
test "transitioning to failed causes an event to be broadcasted" do
|
106
|
+
deploy = shipit_deploys(:shipit_pending)
|
106
107
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
108
|
+
expect_hook(:deploy, deploy.stack, status: 'failed', deploy: deploy, stack: deploy.stack)
|
109
|
+
expect_event(deploy)
|
110
|
+
deploy.status = 'running'
|
111
|
+
deploy.failure!
|
112
|
+
end
|
112
113
|
|
113
|
-
|
114
|
-
|
114
|
+
test "transitioning to error causes an event to be broadcasted" do
|
115
|
+
deploy = shipit_deploys(:shipit_pending)
|
115
116
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
117
|
+
expect_hook(:deploy, deploy.stack, status: 'error', deploy: deploy, stack: deploy.stack)
|
118
|
+
expect_event(deploy)
|
119
|
+
deploy.status = 'running'
|
120
|
+
deploy.error!
|
121
|
+
end
|
121
122
|
|
122
|
-
|
123
|
-
|
123
|
+
test "transitioning to running causes an event to be broadcasted" do
|
124
|
+
deploy = shipit_deploys(:shipit_pending)
|
124
125
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
126
|
+
expect_hook(:deploy, deploy.stack, status: 'running', deploy: deploy, stack: deploy.stack)
|
127
|
+
expect_event(deploy)
|
128
|
+
deploy.status = 'pending'
|
129
|
+
deploy.run!
|
130
|
+
end
|
130
131
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
132
|
+
test "creating a deploy causes an event to be broadcasted" do
|
133
|
+
shipit = shipit_stacks(:shipit)
|
134
|
+
deploy = shipit.deploys.build(
|
135
|
+
since_commit: shipit.commits.first,
|
136
|
+
until_commit: shipit.commits.last,
|
137
|
+
)
|
137
138
|
|
138
|
-
|
139
|
-
|
140
|
-
|
139
|
+
expect_event(deploy)
|
140
|
+
deploy.save!
|
141
|
+
end
|
141
142
|
|
142
|
-
|
143
|
-
|
143
|
+
test "transitioning to success triggers next deploy when stack uses CD" do
|
144
|
+
shipit_commits(:fifth).statuses.create!(state: 'success')
|
144
145
|
|
145
|
-
|
146
|
-
|
146
|
+
deploy = shipit_deploys(:shipit_running)
|
147
|
+
deploy.stack.update(continuous_deployment: true)
|
147
148
|
|
148
|
-
|
149
|
-
|
149
|
+
assert_difference "Deploy.count" do
|
150
|
+
deploy.complete!
|
151
|
+
end
|
150
152
|
end
|
151
|
-
end
|
152
153
|
|
153
|
-
|
154
|
-
|
154
|
+
test "transitioning to success skips CD deploy when stack doesn't use it" do
|
155
|
+
shipit_commits(:fifth).statuses.create!(state: 'success')
|
155
156
|
|
156
|
-
|
157
|
+
deploy = shipit_deploys(:shipit_running)
|
157
158
|
|
158
|
-
|
159
|
-
|
159
|
+
assert_no_difference "Deploy.count" do
|
160
|
+
deploy.complete!
|
161
|
+
end
|
160
162
|
end
|
161
|
-
end
|
162
163
|
|
163
|
-
|
164
|
-
|
165
|
-
|
164
|
+
test "transitioning to success skips CD when no successful commits after until_commit" do
|
165
|
+
deploy = shipit_deploys(:shipit_running)
|
166
|
+
deploy.stack.update(continuous_deployment: true)
|
166
167
|
|
167
|
-
|
168
|
-
|
168
|
+
assert_no_difference "Deploy.count" do
|
169
|
+
deploy.complete!
|
170
|
+
end
|
169
171
|
end
|
170
|
-
end
|
171
172
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
173
|
+
test "transitioning to success schedule a fetch of the deployed revision" do
|
174
|
+
@deploy = shipit_deploys(:shipit_running)
|
175
|
+
assert_enqueued_with(job: FetchDeployedRevisionJob, args: [@deploy.stack]) do
|
176
|
+
@deploy.complete!
|
177
|
+
end
|
176
178
|
end
|
177
|
-
end
|
178
179
|
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
180
|
+
test "transitioning to failure schedule a fetch of the deployed revision" do
|
181
|
+
@deploy = shipit_deploys(:shipit_running)
|
182
|
+
assert_enqueued_with(job: FetchDeployedRevisionJob, args: [@deploy.stack]) do
|
183
|
+
@deploy.failure!
|
184
|
+
end
|
183
185
|
end
|
184
|
-
end
|
185
186
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
187
|
+
test "transitioning to error schedule a fetch of the deployed revision" do
|
188
|
+
@deploy = shipit_deploys(:shipit_running)
|
189
|
+
assert_enqueued_with(job: FetchDeployedRevisionJob, args: [@deploy.stack]) do
|
190
|
+
@deploy.error!
|
191
|
+
end
|
190
192
|
end
|
191
|
-
end
|
192
193
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
194
|
+
test "transitioning to aborted schedule a rollback if required" do
|
195
|
+
@deploy = shipit_deploys(:shipit_running)
|
196
|
+
@deploy.pid = 42
|
197
|
+
@deploy.abort!(rollback_once_aborted: true)
|
197
198
|
|
198
|
-
|
199
|
-
|
200
|
-
|
199
|
+
assert_difference -> { @stack.rollbacks.count }, 1 do
|
200
|
+
assert_enqueued_with(job: PerformTaskJob) do
|
201
|
+
@deploy.aborted!
|
202
|
+
end
|
201
203
|
end
|
202
204
|
end
|
203
|
-
end
|
204
205
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
test "#build_rollback returns a rollback" do
|
210
|
-
assert @deploy.build_rollback.rollback?
|
211
|
-
end
|
206
|
+
test "#build_rollback returns an unsaved record" do
|
207
|
+
assert @deploy.build_rollback.new_record?
|
208
|
+
end
|
212
209
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
end
|
210
|
+
test "#build_rollback returns a rollback" do
|
211
|
+
assert @deploy.build_rollback.rollback?
|
212
|
+
end
|
217
213
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
214
|
+
test "#build_rollback set the id of the rollbacked deploy" do
|
215
|
+
rollback = @deploy.build_rollback
|
216
|
+
assert_equal @deploy.id, rollback.parent_id
|
217
|
+
end
|
222
218
|
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
rollback.complete!
|
228
|
-
assert_equal commits(:second), @stack.last_deployed_commit
|
229
|
-
end
|
219
|
+
test "#build_rollback set the last_deployed_commit as the rollback since_commit" do
|
220
|
+
rollback = @deploy.build_rollback
|
221
|
+
assert_equal @stack.last_deployed_commit, rollback.since_commit
|
222
|
+
end
|
230
223
|
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
224
|
+
test "#trigger_rollback rolls the stack back to this deploy" do
|
225
|
+
assert_equal shipit_commits(:fourth), @stack.last_deployed_commit
|
226
|
+
rollback = @deploy.trigger_rollback
|
227
|
+
rollback.run!
|
228
|
+
rollback.complete!
|
229
|
+
assert_equal shipit_commits(:second), @stack.last_deployed_commit
|
230
|
+
end
|
238
231
|
|
239
|
-
|
240
|
-
|
241
|
-
@deploy.
|
232
|
+
test "#trigger_revert rolls the stack back to before this deploy" do
|
233
|
+
assert_equal shipit_commits(:fourth), @stack.last_deployed_commit
|
234
|
+
rollback = @deploy.trigger_revert
|
235
|
+
rollback.run!
|
236
|
+
rollback.complete!
|
237
|
+
assert_equal shipit_commits(:first), @stack.last_deployed_commit
|
242
238
|
end
|
243
|
-
end
|
244
239
|
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
240
|
+
test "#trigger_rollback creates a new Rollback" do
|
241
|
+
assert_difference -> { Rollback.count }, 1 do
|
242
|
+
@deploy.trigger_rollback(@user)
|
243
|
+
end
|
249
244
|
end
|
250
|
-
end
|
251
245
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
246
|
+
test "#trigger_rollback schedule the task" do
|
247
|
+
Hook.expects(:emit).at_least_once
|
248
|
+
assert_enqueued_with(job: PerformTaskJob) do
|
249
|
+
@deploy.trigger_rollback(@user)
|
250
|
+
end
|
251
|
+
end
|
258
252
|
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
253
|
+
test "#trigger_rollback locks the stack" do
|
254
|
+
refute @stack.locked?
|
255
|
+
@deploy.trigger_rollback(@user)
|
256
|
+
assert @stack.reload.locked?
|
257
|
+
assert_equal @user, @stack.lock_author
|
258
|
+
end
|
263
259
|
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
260
|
+
test "pid is persisted" do
|
261
|
+
clone = Deploy.find(@deploy.id)
|
262
|
+
assert_equal 42, clone.pid
|
263
|
+
end
|
268
264
|
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
265
|
+
test "abort! transition to `aborting`" do
|
266
|
+
@deploy.abort!
|
267
|
+
assert_equal 'aborting', @deploy.status
|
268
|
+
end
|
273
269
|
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
270
|
+
test "abort! schedule the rollback if `rollback_once_aborted` is true" do
|
271
|
+
@deploy.abort!(rollback_once_aborted: true)
|
272
|
+
assert @deploy.reload.rollback_once_aborted?
|
273
|
+
end
|
278
274
|
|
279
|
-
|
280
|
-
|
281
|
-
assert_nothing_raised do
|
275
|
+
test "abort! sends a SIGTERM to the recorded PID" do
|
276
|
+
Process.expects(:kill).with('TERM', @deploy.pid)
|
282
277
|
@deploy.abort!
|
283
278
|
end
|
284
|
-
end
|
285
279
|
|
286
|
-
|
287
|
-
|
288
|
-
|
280
|
+
test "abort! still succeeds if the process is already dead" do
|
281
|
+
Process.expects(:kill).with('TERM', @deploy.pid).raises(Errno::ESRCH)
|
282
|
+
assert_nothing_raised do
|
283
|
+
@deploy.abort!
|
284
|
+
end
|
285
|
+
end
|
289
286
|
|
290
|
-
|
291
|
-
|
287
|
+
test "abort! transition to `aborted` if the process is already dead" do
|
288
|
+
@deploy = shipit_deploys(:shipit_running)
|
289
|
+
@deploy.pid = 42
|
292
290
|
|
293
|
-
|
294
|
-
|
295
|
-
assert_equal 'aborted', @deploy.status
|
296
|
-
end
|
291
|
+
@deploy.abort!
|
292
|
+
assert_equal 'aborting', @deploy.status
|
297
293
|
|
298
|
-
|
299
|
-
Process.expects(:kill).never
|
300
|
-
@deploy.pid = nil
|
301
|
-
assert_nothing_raised do
|
294
|
+
Process.expects(:kill).with('TERM', @deploy.pid).raises(Errno::ESRCH)
|
302
295
|
@deploy.abort!
|
296
|
+
assert_equal 'aborted', @deploy.status
|
303
297
|
end
|
304
|
-
end
|
305
298
|
|
306
|
-
|
307
|
-
|
308
|
-
@deploy.
|
299
|
+
test "abort! bails out if the PID is nil" do
|
300
|
+
Process.expects(:kill).never
|
301
|
+
@deploy.pid = nil
|
302
|
+
assert_nothing_raised do
|
303
|
+
@deploy.abort!
|
304
|
+
end
|
309
305
|
end
|
310
|
-
end
|
311
306
|
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
307
|
+
test "destroy deletes the related output chunks" do
|
308
|
+
assert_difference -> { @deploy.chunks.count }, -@deploy.chunks.count do
|
309
|
+
@deploy.destroy
|
310
|
+
end
|
311
|
+
end
|
317
312
|
|
318
|
-
|
319
|
-
|
320
|
-
|
313
|
+
test "#chunk_output joins all chunk test if logs not rolled up" do
|
314
|
+
assert_equal @deploy.chunks.count, @deploy.chunks.count
|
315
|
+
assert_equal @deploy.chunks.pluck(:text).join, @deploy.chunk_output
|
316
|
+
refute @deploy.rolled_up
|
317
|
+
end
|
318
|
+
|
319
|
+
test "#chunk_output returns logs from records if rolled up" do
|
320
|
+
expected_output = @deploy.chunks.pluck(:text).join
|
321
|
+
@deploy.rollup_chunks
|
321
322
|
|
322
|
-
|
323
|
-
|
324
|
-
|
323
|
+
assert_no_queries do
|
324
|
+
assert_equal expected_output, @deploy.chunk_output
|
325
|
+
assert @deploy.rolled_up
|
326
|
+
end
|
325
327
|
end
|
326
|
-
end
|
327
328
|
|
328
|
-
|
329
|
-
|
329
|
+
test "#accept! bails out if the deploy is successful already" do
|
330
|
+
assert_predicate @deploy, :success?
|
331
|
+
|
332
|
+
Deploy::CONFIRMATIONS_REQUIRED.times do
|
333
|
+
@deploy.accept!
|
334
|
+
assert_predicate @deploy, :success?
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
338
|
+
test "#accept! first transition to flapping then ultimately to success if the deploy was failed" do
|
339
|
+
@deploy = shipit_deploys(:shipit2)
|
340
|
+
assert_predicate @deploy, :failed?
|
341
|
+
|
342
|
+
(Deploy::CONFIRMATIONS_REQUIRED - 1).times do
|
343
|
+
@deploy.accept!
|
344
|
+
assert_predicate @deploy, :flapping?
|
345
|
+
end
|
330
346
|
|
331
|
-
Deploy::CONFIRMATIONS_REQUIRED.times do
|
332
347
|
@deploy.accept!
|
333
348
|
assert_predicate @deploy, :success?
|
334
349
|
end
|
335
|
-
end
|
336
350
|
|
337
|
-
|
338
|
-
|
339
|
-
|
351
|
+
test "#reject! bails out if the deploy is failed already" do
|
352
|
+
@deploy = shipit_deploys(:shipit2)
|
353
|
+
assert_predicate @deploy, :failed?
|
340
354
|
|
341
|
-
|
342
|
-
|
343
|
-
|
355
|
+
Deploy::CONFIRMATIONS_REQUIRED.times do
|
356
|
+
@deploy.reject!
|
357
|
+
assert_predicate @deploy, :failed?
|
358
|
+
end
|
344
359
|
end
|
345
360
|
|
346
|
-
|
347
|
-
|
348
|
-
end
|
361
|
+
test "#reject! first transition to flapping then ultimately to failed if the deploy was successful" do
|
362
|
+
assert_predicate @deploy, :success?
|
349
363
|
|
350
|
-
|
351
|
-
|
352
|
-
|
364
|
+
(Deploy::CONFIRMATIONS_REQUIRED - 1).times do
|
365
|
+
@deploy.reject!
|
366
|
+
assert_predicate @deploy, :flapping?
|
367
|
+
end
|
353
368
|
|
354
|
-
Deploy::CONFIRMATIONS_REQUIRED.times do
|
355
369
|
@deploy.reject!
|
356
370
|
assert_predicate @deploy, :failed?
|
357
371
|
end
|
358
|
-
end
|
359
|
-
|
360
|
-
test "#reject! first transition to flapping then ultimately to failed if the deploy was successful" do
|
361
|
-
assert_predicate @deploy, :success?
|
362
372
|
|
363
|
-
|
364
|
-
|
373
|
+
test "entering flapping state triggers webhooks" do
|
374
|
+
assert_enqueued_with job: EmitEventJob do
|
375
|
+
@deploy.reject!
|
376
|
+
end
|
365
377
|
assert_predicate @deploy, :flapping?
|
366
378
|
end
|
367
379
|
|
368
|
-
|
369
|
-
assert_predicate @deploy, :failed?
|
370
|
-
end
|
380
|
+
private
|
371
381
|
|
372
|
-
|
373
|
-
|
374
|
-
|
382
|
+
def expect_event(deploy)
|
383
|
+
Pubsubstub::RedisPubSub.expects(:publish).at_least_once
|
384
|
+
Pubsubstub::RedisPubSub.expects(:publish).with do |channel, event|
|
385
|
+
data = JSON.load(event.data)
|
386
|
+
channel == "stack.#{deploy.stack.id}" && data['url'] == "/#{deploy.stack.to_param}"
|
387
|
+
end
|
375
388
|
end
|
376
|
-
assert_predicate @deploy, :flapping?
|
377
|
-
end
|
378
389
|
|
379
|
-
|
380
|
-
|
381
|
-
def expect_event(deploy)
|
382
|
-
Pubsubstub::RedisPubSub.expects(:publish).at_least_once
|
383
|
-
Pubsubstub::RedisPubSub.expects(:publish).with do |channel, event|
|
384
|
-
data = JSON.load(event.data)
|
385
|
-
channel == "stack.#{deploy.stack.id}" && data['url'] == "/#{deploy.stack.to_param}"
|
390
|
+
def expect_hook(event, stack, payload)
|
391
|
+
Hook.expects(:emit).with(event, stack, payload)
|
386
392
|
end
|
387
393
|
end
|
388
|
-
|
389
|
-
def expect_hook(event, stack, payload)
|
390
|
-
Hook.expects(:emit).with(event, stack, payload)
|
391
|
-
end
|
392
394
|
end
|