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,54 +1,56 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
module Shipit
|
4
|
+
class GithubHookTest < ActiveSupport::TestCase
|
5
|
+
def setup
|
6
|
+
@stack = shipit_stacks(:shipit)
|
7
|
+
@hook = shipit_github_hooks(:shipit_push)
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
test "#verify_signature is true if the signature matches" do
|
11
|
+
assert @hook.verify_signature('sha1=9fb52fecc2b97b7a912aca27685149d2ce571900', 'hello shipit')
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
test "#verify_signature is false if the signature doesn't match" do
|
15
|
+
refute @hook.verify_signature('sha1=9fb52fecc2b97b7a912aca27685149d2ce571900', 'hello toto')
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
18
|
+
test "#setup! create the hook on Github side" do
|
19
|
+
@hook = shipit_github_hooks(:cyclimse_push)
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
21
|
+
response = mock(id: 44, rels: {self: mock(href: 'https://api.github.com/somestuff')})
|
22
|
+
Shipit.github_api.expects(:create_hook).with(
|
23
|
+
@hook.github_repo_name,
|
24
|
+
'web',
|
25
|
+
includes(:url, :content_type, :secret),
|
26
|
+
includes(:events, :active),
|
27
|
+
).returns(response)
|
28
|
+
@hook.setup!
|
29
|
+
@hook.reload
|
30
|
+
assert_equal 44, @hook.github_id
|
31
|
+
assert_equal 'https://api.github.com/somestuff', @hook.api_url
|
32
|
+
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
34
|
+
test "#setup! update the hook it it already exist" do
|
35
|
+
response = mock(id: 44, rels: {self: mock(href: 'https://api.github.com/somestuff')})
|
36
|
+
Shipit.github_api.expects(:edit_hook).with(
|
37
|
+
@hook.github_repo_name,
|
38
|
+
@hook.github_id,
|
39
|
+
'web',
|
40
|
+
includes(:url, :content_type, :secret),
|
41
|
+
includes(:events, :active),
|
42
|
+
).returns(response)
|
43
|
+
@hook.setup!
|
44
|
+
@hook.reload
|
45
|
+
assert_equal 44, @hook.github_id
|
46
|
+
assert_equal 'https://api.github.com/somestuff', @hook.api_url
|
47
|
+
end
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
49
|
+
test "#destroy starts by removing the hook" do
|
50
|
+
Shipit.github_api.expects(:remove_hook).with(@hook.github_repo_name, @hook.github_id)
|
51
|
+
assert_difference -> { GithubHook.count }, -1 do
|
52
|
+
@hook.destroy!
|
53
|
+
end
|
52
54
|
end
|
53
55
|
end
|
54
56
|
end
|
data/test/models/hook_test.rb
CHANGED
@@ -1,57 +1,59 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
test "#url must be valid" do
|
10
|
-
@hook.url = 'file:/ad"fa/adfa'
|
11
|
-
refute @hook.valid?
|
12
|
-
assert_equal ['Url is not a valid URL'], @hook.errors.full_messages
|
13
|
-
end
|
3
|
+
module Shipit
|
4
|
+
class HookTest < ActiveSupport::TestCase
|
5
|
+
setup do
|
6
|
+
@stack = shipit_stacks(:shipit)
|
7
|
+
@hook = shipit_hooks(:shipit_deploys)
|
8
|
+
end
|
14
9
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
10
|
+
test "#url must be valid" do
|
11
|
+
@hook.url = 'file:/ad"fa/adfa'
|
12
|
+
refute @hook.valid?
|
13
|
+
assert_equal ['Url is not a valid URL'], @hook.errors.full_messages
|
14
|
+
end
|
20
15
|
|
21
|
-
|
22
|
-
|
23
|
-
|
16
|
+
test "#url must not be localhost" do
|
17
|
+
@hook.url = 'file:///etc/passwd'
|
18
|
+
refute @hook.valid?
|
19
|
+
assert_equal ['Url is not a valid URL'], @hook.errors.full_messages
|
20
|
+
end
|
24
21
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
assert_equal ["Events is not a strict subset of #{Hook::EVENTS.inspect}"], @hook.errors.full_messages
|
29
|
-
end
|
22
|
+
test "#events is accessible as an array" do
|
23
|
+
assert_equal %w(deploy rollback), @hook.events
|
24
|
+
end
|
30
25
|
|
31
|
-
|
32
|
-
|
33
|
-
|
26
|
+
test "#events can only contain a defined set of values" do
|
27
|
+
@hook.events = %w(foo)
|
28
|
+
refute @hook.valid?
|
29
|
+
assert_equal ["Events is not a strict subset of #{Hook::EVENTS.inspect}"], @hook.errors.full_messages
|
34
30
|
end
|
35
|
-
end
|
36
31
|
|
37
|
-
|
38
|
-
|
39
|
-
|
32
|
+
test ".emit enqueues an EmitEventJob with the proper payload" do
|
33
|
+
assert_enqueued_with(job: EmitEventJob) do
|
34
|
+
Hook.emit(:deploy, @stack, foo: 42)
|
35
|
+
end
|
40
36
|
end
|
41
37
|
|
42
|
-
delivery
|
38
|
+
test ".deliver schedules a delivery for each matching hook" do
|
39
|
+
assert_difference -> { Delivery.count }, 2 do
|
40
|
+
Hook.deliver(:deploy, @stack, 'foo' => 42)
|
41
|
+
end
|
43
42
|
|
44
|
-
|
45
|
-
assert_equal 'application/x-www-form-urlencoded', delivery.content_type
|
46
|
-
assert_equal 'foo=42', delivery.payload
|
47
|
-
assert_equal 'scheduled', delivery.status
|
48
|
-
end
|
43
|
+
delivery = Delivery.last
|
49
44
|
|
50
|
-
|
51
|
-
|
52
|
-
|
45
|
+
assert_equal @hook.url, delivery.url
|
46
|
+
assert_equal 'application/x-www-form-urlencoded', delivery.content_type
|
47
|
+
assert_equal 'foo=42', delivery.payload
|
48
|
+
assert_equal 'scheduled', delivery.status
|
49
|
+
end
|
50
|
+
|
51
|
+
test ".scoped? returns true if the hook has a stack_id" do
|
52
|
+
@hook.stack_id = nil
|
53
|
+
refute @hook.scoped?
|
53
54
|
|
54
|
-
|
55
|
-
|
55
|
+
@hook.stack_id = 42
|
56
|
+
assert @hook.scoped?
|
57
|
+
end
|
56
58
|
end
|
57
59
|
end
|
@@ -1,12 +1,14 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
module Shipit
|
4
|
+
class MembershipTest < ActiveSupport::TestCase
|
5
|
+
setup do
|
6
|
+
@membership = shipit_memberships(:walrus_shopify_developers)
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
test "no duplicates are accepted" do
|
10
|
+
membership = Membership.new(user: @membership.user, team: @membership.team)
|
11
|
+
refute membership.valid?
|
12
|
+
end
|
11
13
|
end
|
12
14
|
end
|
@@ -1,21 +1,23 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
module Shipit
|
4
|
+
class MissingStatusTest < ActiveSupport::TestCase
|
5
|
+
setup do
|
6
|
+
@real_status = shipit_statuses(:first_pending)
|
7
|
+
@status = MissingStatus.new(@real_status, %w(ci/very-important style/very-important-too))
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
test "#state is 'missing'" do
|
11
|
+
assert_equal 'missing', @status.state
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
test "#description explains the situation" do
|
15
|
+
message = 'ci/very-important and style/very-important-too are required for deploy but were not sent'
|
16
|
+
assert_equal message, @status.description
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
19
|
+
test "#success? is false" do
|
20
|
+
refute_predicate @status, :success?
|
21
|
+
end
|
20
22
|
end
|
21
23
|
end
|
@@ -1,18 +1,20 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
module Shipit
|
4
|
+
class OutputChunkTest < ActiveSupport::TestCase
|
5
|
+
def setup
|
6
|
+
@deploy = shipit_deploys(:shipit)
|
7
|
+
@chunks = 3.times.map { OutputChunk.create!(text: 'bla', task: @deploy) }
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
test "tail" do
|
11
|
+
start = @chunks.first
|
12
|
+
rest = @chunks - [start]
|
13
|
+
assert_equal rest, @deploy.chunks.tail(start.id)
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
test "tail without start" do
|
17
|
+
assert_equal @deploy.chunks, @deploy.chunks.tail(nil)
|
18
|
+
end
|
17
19
|
end
|
18
20
|
end
|
@@ -1,19 +1,21 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
module Shipit
|
4
|
+
class RollbackTest < ActiveSupport::TestCase
|
5
|
+
setup do
|
6
|
+
@rollback = Rollback.new
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
test "#rollback? returns true" do
|
10
|
+
assert @rollback.rollback?
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
test "#rollbackable? returns false" do
|
14
|
+
refute @rollback.rollbackable?
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
test "#supports_rollback? returns false" do
|
18
|
+
refute @rollback.supports_rollback?
|
19
|
+
end
|
18
20
|
end
|
19
21
|
end
|
data/test/models/stacks_test.rb
CHANGED
@@ -1,354 +1,356 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
module Shipit
|
4
|
+
class StacksTest < ActiveSupport::TestCase
|
5
|
+
def setup
|
6
|
+
@stack = shipit_stacks(:shipit)
|
7
|
+
@expected_base_path = Rails.root.join('data/stacks', @stack.to_param).to_s
|
8
|
+
GithubHook.any_instance.stubs(:teardown!)
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
test "repo_owner, repo_name and environment uniqueness is enforced" do
|
12
|
+
clone = Stack.new(@stack.attributes.except('id'))
|
13
|
+
refute clone.save
|
14
|
+
assert_equal ["has already been taken"], clone.errors[:repo_name]
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
test "repo_owner, repo_name, and environment can only be ASCII" do
|
18
|
+
@stack.update(repo_owner: 'héllò', repo_name: 'wørld', environment: 'pródüctïòn')
|
19
|
+
refute_predicate @stack, :valid?
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
test "repo_owner is automatically downcased" do
|
23
|
+
@stack.repo_owner = 'George'
|
24
|
+
assert_equal 'george', @stack.repo_owner
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
test "repo_name is automatically downcased" do
|
28
|
+
@stack.repo_name = 'Cyclim.se'
|
29
|
+
assert_equal 'cyclim.se', @stack.repo_name
|
30
|
+
end
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
test "branch defaults to master" do
|
33
|
+
@stack.branch = ""
|
34
|
+
assert @stack.save
|
35
|
+
assert_equal 'master', @stack.branch
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
test "environment defaults to production" do
|
39
|
+
@stack.environment = ""
|
40
|
+
assert @stack.save
|
41
|
+
assert_equal 'production', @stack.environment
|
42
|
+
end
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
44
|
+
test "environment can contain a `:`" do
|
45
|
+
@stack.environment = 'foo:bar'
|
46
|
+
assert @stack.save
|
47
|
+
assert_equal 'foo:bar', @stack.environment
|
48
|
+
end
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
test "repo_owner cannot contain a `/`" do
|
51
|
+
assert @stack.valid?
|
52
|
+
@stack.repo_owner = 'foo/bar'
|
53
|
+
refute @stack.valid?
|
54
|
+
end
|
54
55
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
56
|
+
test "repo_name cannot contain a `/`" do
|
57
|
+
assert @stack.valid?
|
58
|
+
@stack.repo_name = 'foo/bar'
|
59
|
+
refute @stack.valid?
|
60
|
+
end
|
60
61
|
|
61
|
-
|
62
|
-
|
63
|
-
|
62
|
+
test "repo_http_url" do
|
63
|
+
assert_equal "https://github.com/#{@stack.repo_owner}/#{@stack.repo_name}", @stack.repo_http_url
|
64
|
+
end
|
64
65
|
|
65
|
-
|
66
|
-
|
67
|
-
|
66
|
+
test "repo_git_url" do
|
67
|
+
assert_equal "git@github.com:#{@stack.repo_owner}/#{@stack.repo_name}.git", @stack.repo_git_url
|
68
|
+
end
|
68
69
|
|
69
|
-
|
70
|
-
|
71
|
-
|
70
|
+
test "base_path" do
|
71
|
+
assert_equal @expected_base_path, @stack.base_path.to_s
|
72
|
+
end
|
72
73
|
|
73
|
-
|
74
|
-
|
75
|
-
|
74
|
+
test "deploys_path" do
|
75
|
+
assert_equal File.join(@expected_base_path, "deploys"), @stack.deploys_path.to_s
|
76
|
+
end
|
76
77
|
|
77
|
-
|
78
|
-
|
79
|
-
|
78
|
+
test "git_path" do
|
79
|
+
assert_equal File.join(@expected_base_path, "git"), @stack.git_path.to_s
|
80
|
+
end
|
80
81
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
82
|
+
test "#trigger_deploy persist a new deploy" do
|
83
|
+
last_commit = shipit_commits(:third)
|
84
|
+
deploy = @stack.trigger_deploy(last_commit, AnonymousUser.new)
|
85
|
+
assert deploy.persisted?
|
86
|
+
assert_equal last_commit.id, deploy.until_commit_id
|
87
|
+
assert_equal shipit_deploys(:shipit_complete).until_commit_id, deploy.since_commit_id
|
88
|
+
end
|
88
89
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
90
|
+
test "#trigger_deploy deploy until the commit passed in argument" do
|
91
|
+
last_commit = shipit_commits(:third)
|
92
|
+
deploy = @stack.trigger_deploy(last_commit, AnonymousUser.new)
|
93
|
+
assert_equal last_commit.id, deploy.until_commit_id
|
94
|
+
end
|
94
95
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
96
|
+
test "#trigger_deploy since_commit is the last completed deploy until_commit if there is a previous deploy" do
|
97
|
+
last_commit = shipit_commits(:fifth)
|
98
|
+
deploy = @stack.trigger_deploy(last_commit, AnonymousUser.new)
|
99
|
+
assert_equal shipit_deploys(:shipit_complete).until_commit_id, deploy.since_commit_id
|
100
|
+
end
|
100
101
|
|
101
|
-
|
102
|
-
|
102
|
+
test "#trigger_deploy since_commit is the first stack commit if there is no previous deploy" do
|
103
|
+
@stack.deploys.destroy_all
|
103
104
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
105
|
+
last_commit = shipit_commits(:third)
|
106
|
+
deploy = @stack.trigger_deploy(last_commit, AnonymousUser.new)
|
107
|
+
assert_equal @stack.commits.first.id, deploy.since_commit_id
|
108
|
+
end
|
108
109
|
|
109
|
-
|
110
|
-
|
111
|
-
|
110
|
+
test "#trigger_deploy enqueue a deploy job" do
|
111
|
+
@stack.deploys.destroy_all
|
112
|
+
Deploy.any_instance.expects(:enqueue).once
|
112
113
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
114
|
+
last_commit = shipit_commits(:third)
|
115
|
+
deploy = @stack.trigger_deploy(last_commit, AnonymousUser.new)
|
116
|
+
assert_instance_of Deploy, deploy
|
117
|
+
end
|
117
118
|
|
118
|
-
|
119
|
-
|
120
|
-
|
119
|
+
test "#update_deployed_revision bail out if there is an active deploy" do
|
120
|
+
assert_no_difference 'Deploy.count' do
|
121
|
+
@stack.update_deployed_revision(shipit_commits(:fifth).sha)
|
122
|
+
end
|
121
123
|
end
|
122
|
-
end
|
123
124
|
|
124
|
-
|
125
|
-
|
126
|
-
|
125
|
+
test "#update_deployed_revision bail out if sha is unknown" do
|
126
|
+
assert_no_difference 'Deploy.count' do
|
127
|
+
@stack.update_deployed_revision('skldjaslkdjas')
|
128
|
+
end
|
127
129
|
end
|
128
|
-
end
|
129
130
|
|
130
|
-
|
131
|
-
|
131
|
+
test "#update_deployed_revision create a new completed deploy" do
|
132
|
+
Deploy.active.update_all(status: 'error')
|
132
133
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
134
|
+
assert_equal shipit_commits(:fourth), @stack.last_deployed_commit
|
135
|
+
assert_difference 'Deploy.count', 1 do
|
136
|
+
deploy = @stack.update_deployed_revision(shipit_commits(:fifth).sha)
|
137
|
+
assert_not_nil deploy
|
138
|
+
assert_equal shipit_commits(:fourth), deploy.since_commit
|
139
|
+
assert_equal shipit_commits(:fifth), deploy.until_commit
|
140
|
+
end
|
141
|
+
assert_equal shipit_commits(:fifth), @stack.last_deployed_commit
|
139
142
|
end
|
140
|
-
assert_equal commits(:fifth), @stack.last_deployed_commit
|
141
|
-
end
|
142
143
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
144
|
+
test "#update_deployed_revision creates a new completed deploy without previous deploys" do
|
145
|
+
stack = shipit_stacks(:undeployed_stack)
|
146
|
+
assert_empty stack.deploys_and_rollbacks
|
147
|
+
assert_difference 'Deploy.count', 1 do
|
148
|
+
deploy = stack.update_deployed_revision(shipit_commits(:undeployed_stack_first).sha)
|
149
|
+
assert_not_nil deploy
|
150
|
+
assert_equal shipit_commits(:undeployed_stack_first), deploy.since_commit
|
151
|
+
assert_equal shipit_commits(:undeployed_stack_first), deploy.until_commit
|
152
|
+
end
|
153
|
+
assert_equal shipit_commits(:undeployed_stack_first), stack.last_deployed_commit
|
151
154
|
end
|
152
|
-
assert_equal commits(:undeployed_stack_first), stack.last_deployed_commit
|
153
|
-
end
|
154
155
|
|
155
|
-
|
156
|
-
|
156
|
+
test "#update_deployed_revision works with short shas" do
|
157
|
+
Deploy.active.update_all(status: 'error')
|
157
158
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
159
|
+
assert_equal shipit_commits(:fourth), @stack.last_deployed_commit
|
160
|
+
assert_difference 'Deploy.count', 1 do
|
161
|
+
deploy = @stack.update_deployed_revision(shipit_commits(:fifth).sha[0..5])
|
162
|
+
assert_not_nil deploy
|
163
|
+
assert_equal shipit_commits(:fourth), deploy.since_commit
|
164
|
+
assert_equal shipit_commits(:fifth), deploy.until_commit
|
165
|
+
end
|
166
|
+
assert_equal shipit_commits(:fifth), @stack.last_deployed_commit
|
164
167
|
end
|
165
|
-
assert_equal commits(:fifth), @stack.last_deployed_commit
|
166
|
-
end
|
167
168
|
|
168
|
-
|
169
|
-
|
169
|
+
test "#update_deployed_revision accepts the deploy if the reported revision is consistent" do
|
170
|
+
Deploy.active.update_all(status: 'error')
|
170
171
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
172
|
+
Deploy.any_instance.expects(:accept!).once
|
173
|
+
last_deploy = @stack.deploys_and_rollbacks.completed.last
|
174
|
+
@stack.update_deployed_revision(last_deploy.until_commit.sha)
|
175
|
+
end
|
175
176
|
|
176
|
-
|
177
|
-
|
177
|
+
test "#update_deployed_revision reject the deploy if the reported revision is inconsistent" do
|
178
|
+
Deploy.active.update_all(status: 'error')
|
178
179
|
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
end
|
183
|
-
|
184
|
-
test "#create queues 2 GithubSetupWebhooksJob" do
|
185
|
-
assert_enqueued_with(job: SetupGithubHookJob) do
|
186
|
-
Stack.create!(repo_name: 'rails', repo_owner: 'rails')
|
180
|
+
Deploy.any_instance.expects(:reject!).once
|
181
|
+
last_deploy = @stack.deploys_and_rollbacks.completed.last
|
182
|
+
@stack.update_deployed_revision(last_deploy.since_commit.sha)
|
187
183
|
end
|
188
|
-
end
|
189
184
|
|
190
|
-
|
191
|
-
|
192
|
-
|
185
|
+
test "#create queues 2 GithubSetupWebhooksJob" do
|
186
|
+
assert_enqueued_with(job: SetupGithubHookJob) do
|
187
|
+
Stack.create!(repo_name: 'rails', repo_owner: 'rails')
|
188
|
+
end
|
193
189
|
end
|
194
|
-
end
|
195
190
|
|
196
|
-
|
197
|
-
|
198
|
-
|
191
|
+
test "#create queues a GithubSyncJob" do
|
192
|
+
assert_enqueued_with(job: GithubSyncJob) do
|
193
|
+
Stack.create!(repo_name: 'rails', repo_owner: 'rails')
|
194
|
+
end
|
199
195
|
end
|
200
|
-
end
|
201
196
|
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
test "#deploying? is false if stack has no deploy in either pending or running state" do
|
208
|
-
@stack.deploys.active.destroy_all
|
209
|
-
refute @stack.deploying?
|
210
|
-
end
|
197
|
+
test "#destroy also destroy associated GithubHooks" do
|
198
|
+
assert_difference -> { GithubHook.count }, -2 do
|
199
|
+
shipit_stacks(:shipit).destroy
|
200
|
+
end
|
201
|
+
end
|
211
202
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
203
|
+
test "#destroy delete all local files (git mirror and deploy clones)" do
|
204
|
+
FileUtils.expects(:rm_rf).with(Rails.root.join('data', 'stacks', 'shopify', 'shipit-engine', 'production').to_s)
|
205
|
+
shipit_stacks(:shipit).destroy
|
206
|
+
end
|
216
207
|
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
208
|
+
test "#deploying? is false if stack has no deploy in either pending or running state" do
|
209
|
+
@stack.deploys.active.destroy_all
|
210
|
+
refute @stack.deploying?
|
211
|
+
end
|
221
212
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
213
|
+
test "#deploying? is false if stack has no deploy at all" do
|
214
|
+
@stack.deploys.destroy_all
|
215
|
+
refute @stack.deploying?
|
216
|
+
end
|
226
217
|
|
227
|
-
|
228
|
-
|
229
|
-
|
218
|
+
test "#deploying? is true if stack has a deploy in either pending or running state" do
|
219
|
+
@stack.trigger_deploy(shipit_commits(:third), AnonymousUser.new)
|
220
|
+
assert @stack.deploying?
|
230
221
|
end
|
231
|
-
end
|
232
222
|
|
233
|
-
|
234
|
-
|
235
|
-
|
223
|
+
test "#deploying? is true if a rollback is ongoing" do
|
224
|
+
shipit_deploys(:shipit_complete).trigger_rollback(AnonymousUser.new)
|
225
|
+
assert @stack.deploying?
|
236
226
|
end
|
237
|
-
|
238
|
-
|
239
|
-
|
227
|
+
|
228
|
+
test "#deploying? is memoized" do
|
229
|
+
assert_queries(1) do
|
230
|
+
10.times { @stack.deploying? }
|
231
|
+
end
|
240
232
|
end
|
241
|
-
end
|
242
233
|
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
234
|
+
test "#deploying? cache is cleared if a deploy change state" do
|
235
|
+
assert_queries(1) do
|
236
|
+
10.times { @stack.deploying? }
|
237
|
+
end
|
238
|
+
@stack.tasks.where(status: 'running').first.error!
|
239
|
+
assert_queries(1) do
|
240
|
+
10.times { @stack.deploying? }
|
241
|
+
end
|
242
|
+
end
|
247
243
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
244
|
+
test "#deployable? returns true if stack is not locked and is not deploying" do
|
245
|
+
@stack.deploys.destroy_all
|
246
|
+
assert @stack.deployable?
|
247
|
+
end
|
252
248
|
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
249
|
+
test "#deployable? returns false if stack is locked" do
|
250
|
+
@stack.update!(lock_reason: 'Maintenance operation')
|
251
|
+
refute @stack.deployable?
|
252
|
+
end
|
257
253
|
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
254
|
+
test "#deployable? returns false if stack is deploying" do
|
255
|
+
@stack.trigger_deploy(shipit_commits(:third), AnonymousUser.new)
|
256
|
+
refute @stack.deployable?
|
257
|
+
end
|
262
258
|
|
263
|
-
|
264
|
-
|
265
|
-
|
259
|
+
test "#monitoring is empty if cached_deploy_spec is blank" do
|
260
|
+
@stack.cached_deploy_spec = nil
|
261
|
+
assert_equal [], @stack.monitoring
|
262
|
+
end
|
266
263
|
|
267
|
-
|
268
|
-
|
269
|
-
@stack.destroy
|
264
|
+
test "#monitoring returns deploy_spec's content" do
|
265
|
+
assert_equal [{'image' => 'https://example.com/monitor.png', 'width' => 200, 'height' => 300}], @stack.monitoring
|
270
266
|
end
|
271
|
-
end
|
272
267
|
|
273
|
-
|
274
|
-
|
275
|
-
|
268
|
+
test "#destroy deletes the related commits" do
|
269
|
+
assert_difference -> { @stack.commits.count }, -@stack.commits.count do
|
270
|
+
@stack.destroy
|
271
|
+
end
|
276
272
|
end
|
277
|
-
end
|
278
273
|
|
279
|
-
|
280
|
-
|
281
|
-
|
274
|
+
test "#destroy deletes the related tasks" do
|
275
|
+
assert_difference -> { @stack.tasks.count }, -@stack.tasks.count do
|
276
|
+
@stack.destroy
|
277
|
+
end
|
282
278
|
end
|
283
|
-
end
|
284
279
|
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
280
|
+
test "#destroy deletes the related webhooks" do
|
281
|
+
assert_difference -> { @stack.github_hooks.count }, -@stack.github_hooks.count do
|
282
|
+
@stack.destroy
|
283
|
+
end
|
284
|
+
end
|
289
285
|
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
end
|
286
|
+
test "locking the stack triggers a webhook" do
|
287
|
+
expect_hook(:lock, @stack, locked: true, stack: @stack)
|
288
|
+
@stack.update(lock_reason: "Just for fun", lock_author: shipit_users(:walrus))
|
289
|
+
end
|
295
290
|
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
end
|
291
|
+
test "unlocking the stack triggers a webhook" do
|
292
|
+
@stack.update(lock_reason: "Just for fun", lock_author: shipit_users(:walrus))
|
293
|
+
expect_hook(:lock, @stack, locked: false, stack: @stack)
|
294
|
+
@stack.update(lock_reason: nil)
|
301
295
|
end
|
302
|
-
end
|
303
296
|
|
304
|
-
|
305
|
-
called = false
|
306
|
-
stacks(:cyclimse).acquire_git_cache_lock do
|
297
|
+
test "the git cache lock prevent concurrent access to the git cache" do
|
307
298
|
@stack.acquire_git_cache_lock do
|
308
|
-
|
299
|
+
assert_raises Redis::Lock::LockTimeout do
|
300
|
+
@stack.acquire_git_cache_lock(timeout: 0.1) {}
|
301
|
+
end
|
309
302
|
end
|
310
303
|
end
|
311
|
-
assert called
|
312
|
-
end
|
313
304
|
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
305
|
+
test "the git cache lock is scoped to the stack" do
|
306
|
+
called = false
|
307
|
+
shipit_stacks(:cyclimse).acquire_git_cache_lock do
|
308
|
+
@stack.acquire_git_cache_lock do
|
309
|
+
called = true
|
310
|
+
end
|
311
|
+
end
|
312
|
+
assert called
|
313
|
+
end
|
321
314
|
|
322
|
-
|
323
|
-
|
324
|
-
|
315
|
+
test "#clear_git_cache! deletes the stack git directory" do
|
316
|
+
FileUtils.mkdir_p(@stack.git_path)
|
317
|
+
path = File.join(@stack.git_path, 'foo')
|
318
|
+
File.write(path, 'bar')
|
325
319
|
@stack.clear_git_cache!
|
320
|
+
refute File.exist?(path)
|
326
321
|
end
|
327
|
-
end
|
328
322
|
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
323
|
+
test "#clear_git_cache! does nothing if the git directory is not present" do
|
324
|
+
FileUtils.rm_rf(@stack.git_path)
|
325
|
+
assert_nothing_raised do
|
326
|
+
@stack.clear_git_cache!
|
327
|
+
end
|
328
|
+
end
|
335
329
|
|
336
|
-
|
337
|
-
|
330
|
+
test "#filter_visible_statuses removes statuses from hidden contexts" do
|
331
|
+
stack = shipit_stacks(:cyclimse)
|
332
|
+
stack.stubs(hidden_statuses: ['ci/hidden'])
|
333
|
+
commit1 = Status.new(state: 'pending', context: 'ci/valid')
|
334
|
+
commit2 = Status.new(state: 'pending', context: 'ci/valid')
|
335
|
+
hidden = Status.new(state: 'pending', context: 'ci/hidden')
|
338
336
|
|
339
|
-
|
340
|
-
|
341
|
-
stack.stubs(soft_failing_statuses: ['ci/soft-fail'])
|
342
|
-
commit1 = Status.new(state: 'pending', context: 'ci/valid')
|
343
|
-
commit2 = Status.new(state: 'pending', context: 'ci/valid')
|
344
|
-
soft_fail = Status.new(state: 'pending', context: 'ci/soft-fail')
|
337
|
+
assert_equal [commit1, commit2], stack.filter_visible_statuses([hidden, commit1, commit2])
|
338
|
+
end
|
345
339
|
|
346
|
-
|
347
|
-
|
340
|
+
test "#filter_meaningful_statuses removes statuses from soft-failing contexts" do
|
341
|
+
stack = shipit_stacks(:cyclimse)
|
342
|
+
stack.stubs(soft_failing_statuses: ['ci/soft-fail'])
|
343
|
+
commit1 = Status.new(state: 'pending', context: 'ci/valid')
|
344
|
+
commit2 = Status.new(state: 'pending', context: 'ci/valid')
|
345
|
+
soft_fail = Status.new(state: 'pending', context: 'ci/soft-fail')
|
348
346
|
|
349
|
-
|
347
|
+
assert_equal [commit1, commit2], stack.filter_meaningful_statuses([soft_fail, commit1, commit2])
|
348
|
+
end
|
349
|
+
|
350
|
+
private
|
350
351
|
|
351
|
-
|
352
|
-
|
352
|
+
def expect_hook(event, stack, payload)
|
353
|
+
Hook.expects(:emit).with(event, stack, payload)
|
354
|
+
end
|
353
355
|
end
|
354
356
|
end
|