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,24 +1,26 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
module Shipit
|
4
|
+
class StatusGroupTest < ActiveSupport::TestCase
|
5
|
+
setup do
|
6
|
+
@commit = shipit_commits(:second)
|
7
|
+
@group = StatusGroup.new(@commit.significant_status, @commit.visible_statuses)
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
test "#description is a summary of the statuses" do
|
11
|
+
assert_equal '1 / 2 checks OK', @group.description
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
test "#group? returns true" do
|
15
|
+
assert_equal true, @group.group?
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
test "#target_url returns nil" do
|
19
|
+
assert_nil @group.target_url
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
test "#state is significant's status state" do
|
23
|
+
assert_equal @commit.significant_status.state, @group.state
|
24
|
+
end
|
23
25
|
end
|
24
26
|
end
|
data/test/models/status_test.rb
CHANGED
@@ -1,55 +1,57 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
test ".replicate_from_github! is idempotent" do
|
10
|
-
assert_difference '@commit.statuses.count', 1 do
|
11
|
-
@commit.statuses.replicate_from_github!(github_status)
|
3
|
+
module Shipit
|
4
|
+
class StatusTest < ActiveSupport::TestCase
|
5
|
+
setup do
|
6
|
+
@commit = shipit_commits(:first)
|
7
|
+
@stack = @commit.stack
|
12
8
|
end
|
13
9
|
|
14
|
-
|
15
|
-
@commit.statuses.
|
10
|
+
test ".replicate_from_github! is idempotent" do
|
11
|
+
assert_difference '@commit.statuses.count', 1 do
|
12
|
+
@commit.statuses.replicate_from_github!(github_status)
|
13
|
+
end
|
14
|
+
|
15
|
+
assert_no_difference '@commit.statuses.count' do
|
16
|
+
@commit.statuses.replicate_from_github!(github_status)
|
17
|
+
end
|
16
18
|
end
|
17
|
-
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
test "once created a commit broadcasts an update event" do
|
21
|
+
expect_event(@stack)
|
22
|
+
@commit.statuses.create!(state: 'success')
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
test ".replicate_from_github! touches the related stack" do
|
26
|
+
stack_last_updated_at = @stack.updated_at
|
27
|
+
commit_last_updated_at = @commit.updated_at
|
27
28
|
|
28
|
-
|
29
|
+
@commit.statuses.replicate_from_github!(github_status)
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
assert_not_equal commit_last_updated_at, @commit.reload.updated_at
|
32
|
+
assert_not_equal stack_last_updated_at, @stack.reload.updated_at
|
33
|
+
end
|
33
34
|
|
34
|
-
|
35
|
+
private
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
37
|
+
def github_status
|
38
|
+
@github_status ||= OpenStruct.new(
|
39
|
+
state: 'success',
|
40
|
+
description: 'This is a description',
|
41
|
+
context: 'default',
|
42
|
+
target_url: 'http://example.com',
|
43
|
+
created_at: 1.day.ago.to_time,
|
44
|
+
)
|
45
|
+
end
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
47
|
+
def expect_event(stack)
|
48
|
+
Pubsubstub::RedisPubSub.expects(:publish).at_least_once
|
49
|
+
Pubsubstub::RedisPubSub.expects(:publish).with do |channel, event|
|
50
|
+
data = JSON.load(event.data)
|
51
|
+
event.name == 'stack.update' &&
|
52
|
+
channel == "stack.#{stack.id}" &&
|
53
|
+
data['url'] == "/#{stack.to_param}"
|
54
|
+
end
|
53
55
|
end
|
54
56
|
end
|
55
57
|
end
|
@@ -1,32 +1,34 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
3
|
+
module Shipit
|
4
|
+
class TaskDefinitionsTest < ActiveSupport::TestCase
|
5
|
+
setup do
|
6
|
+
@definition = TaskDefinition.new(
|
7
|
+
'restart',
|
8
|
+
'action' => 'Restart application',
|
9
|
+
'description' => 'Restart app and job servers',
|
10
|
+
'steps' => ['touch tmp/restart'],
|
11
|
+
)
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
test ".load returns nil if payload is nil or blank" do
|
15
|
+
assert_nil TaskDefinition.load('')
|
16
|
+
assert_nil TaskDefinition.load(nil)
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
test ".dump returns nil if given nil" do
|
20
|
+
assert_nil TaskDefinition.dump(nil)
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
23
|
+
test "serialization works" do
|
24
|
+
as_json = {
|
25
|
+
id: 'restart',
|
26
|
+
action: 'Restart application',
|
27
|
+
description: 'Restart app and job servers',
|
28
|
+
steps: ['touch tmp/restart'],
|
29
|
+
checklist: [],
|
30
|
+
}
|
31
|
+
assert_equal as_json, TaskDefinition.load(TaskDefinition.dump(@definition)).as_json
|
32
|
+
end
|
31
33
|
end
|
32
34
|
end
|
data/test/models/team_test.rb
CHANGED
@@ -1,50 +1,52 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
module Shipit
|
4
|
+
class TeamTest < ActiveSupport::TestCase
|
5
|
+
setup do
|
6
|
+
@team = shipit_teams(:shopify_developers)
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
test ".find_or_create_by_handle first search in the database" do
|
10
|
+
assert_equal @team, Team.find_or_create_by_handle('Shopify/developers')
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
test ".find_or_create_by_handle fetch the team from github if it's not in the db already" do
|
14
|
+
Shipit.github_api.expects(:org_teams).with('shopify', per_page: 100)
|
15
|
+
response = stub(rels: {}, data: [new_team])
|
16
|
+
Shipit.github_api.expects(:last_response).returns(response)
|
17
|
+
assert_difference -> { Team.count }, 1 do
|
18
|
+
Team.find_or_create_by_handle('Shopify/new-team')
|
19
|
+
end
|
18
20
|
end
|
19
|
-
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
test "#refresh_members! fetch all the team members from github" do
|
23
|
+
response = stub(rels: {members: members_resource})
|
24
|
+
Shipit.github_api.expects(:get).with(@team.api_url).returns(response)
|
25
|
+
assert_difference -> { User.count }, 1 do
|
26
|
+
@team.refresh_members!
|
27
|
+
end
|
26
28
|
end
|
27
|
-
end
|
28
29
|
|
29
|
-
|
30
|
+
private
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
32
|
+
def members_resource
|
33
|
+
stub(get: stub(data: [george], rels: {}))
|
34
|
+
end
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
def george
|
37
|
+
rels = {self: stub(href: 'https://api.github.com/user/george')}
|
38
|
+
stub(id: 42, name: 'George Abitbol', login: 'george', email: 'george@cyclim.se', rels: rels)
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
41
|
+
def new_team
|
42
|
+
stub(
|
43
|
+
id: 24,
|
44
|
+
name: 'New Team',
|
45
|
+
slug: 'new-team',
|
46
|
+
url: 'https://example.com',
|
47
|
+
description: 'The Best one',
|
48
|
+
organization: 'shopify',
|
49
|
+
)
|
50
|
+
end
|
49
51
|
end
|
50
52
|
end
|
data/test/models/users_test.rb
CHANGED
@@ -1,82 +1,84 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
module Shipit
|
4
|
+
class UsersTest < ActiveSupport::TestCase
|
5
|
+
setup do
|
6
|
+
@user = shipit_users(:walrus)
|
7
|
+
rels = {self: stub(href: 'https://api.github.com/user/george')}
|
8
|
+
@github_user = stub(id: 42, name: 'George Abitbol', login: 'george', email: 'george@cyclim.se', rels: rels)
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
test "find_or_create_from_github persist a new user if he is unknown" do
|
12
|
+
assert_difference 'User.count', 1 do
|
13
|
+
fetch_user
|
14
|
+
end
|
13
15
|
end
|
14
|
-
end
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
test "find_or_create_from_github returns the existing user if he is known" do
|
18
|
+
existing = fetch_user
|
18
19
|
|
19
|
-
|
20
|
-
|
20
|
+
assert_no_difference 'User.count' do
|
21
|
+
assert_equal existing, fetch_user
|
22
|
+
end
|
21
23
|
end
|
22
|
-
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
test "find_or_create_from_github store the github_id" do
|
26
|
+
user = User.find_or_create_from_github(@github_user)
|
27
|
+
assert_equal @github_user.id, user.github_id
|
28
|
+
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
test "find_or_create_from_github store the name" do
|
31
|
+
user = User.find_or_create_from_github(@github_user)
|
32
|
+
assert_equal @github_user.name, user.name
|
33
|
+
end
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
test "find_or_create_from_github store the email" do
|
36
|
+
user = User.find_or_create_from_github(@github_user)
|
37
|
+
assert_equal @github_user.email, user.email
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
test "find_or_create_from_github store the login" do
|
41
|
+
user = User.find_or_create_from_github(@github_user)
|
42
|
+
assert_equal @github_user.login, user.login
|
43
|
+
end
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
test "#identifiers_for_ping returns a hash with the user's github_id, name, email and github_login" do
|
46
|
+
user = shipit_users(:bob)
|
47
|
+
expected_ouput = {github_id: user.github_id, name: user.name, email: user.email, github_login: user.login}
|
48
|
+
assert_equal expected_ouput, user.identifiers_for_ping
|
49
|
+
end
|
49
50
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
test "#refresh_from_github! update the user with the latest data from GitHub's API" do
|
52
|
+
Shipit.github_api.expects(:user).with('walrus').returns(@github_user)
|
53
|
+
@user.refresh_from_github!
|
54
|
+
@user.reload
|
54
55
|
|
55
|
-
|
56
|
-
|
57
|
-
|
56
|
+
assert_equal 'George Abitbol', @user.name
|
57
|
+
assert_equal 'george@cyclim.se', @user.email
|
58
|
+
end
|
58
59
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
60
|
+
test "#refresh_from_github! can identify renamed users and update commits and tasks accordingly" do
|
61
|
+
user = shipit_users(:bob)
|
62
|
+
user.update!(github_id: @github_user.id)
|
63
|
+
commit = user.authored_commits.last
|
63
64
|
|
64
|
-
|
65
|
-
|
65
|
+
Shipit.github_api.expects(:user).with(user.login).raises(Octokit::NotFound)
|
66
|
+
Shipit.github_api.expects(:commit).with(commit.github_repo_name, commit.sha).returns(mock(author: @github_user))
|
66
67
|
|
67
|
-
|
68
|
+
assert_equal 'bob', user.login
|
68
69
|
|
69
|
-
|
70
|
-
|
70
|
+
user.refresh_from_github!
|
71
|
+
user.reload
|
71
72
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
73
|
+
assert_equal 'george', user.login
|
74
|
+
assert_equal 'George Abitbol', user.name
|
75
|
+
assert_equal 'george@cyclim.se', user.email
|
76
|
+
end
|
76
77
|
|
77
|
-
|
78
|
+
private
|
78
79
|
|
79
|
-
|
80
|
-
|
80
|
+
def fetch_user
|
81
|
+
User.find_or_create_from_github(@github_user)
|
82
|
+
end
|
81
83
|
end
|
82
84
|
end
|
data/test/unit/command_test.rb
CHANGED
@@ -1,45 +1,47 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
3
|
+
module Shipit
|
4
|
+
class CommandTest < ActiveSupport::TestCase
|
5
|
+
test 'lib/snippets is added to the PATH when command is run' do
|
6
|
+
out = Command.new('which extract-gem-version', chdir: '/tmp').run
|
7
|
+
script_path = Shipit::Engine.root.join('lib', 'snippets', 'extract-gem-version').to_s
|
8
|
+
assert_equal "#{script_path}\r\n", out
|
9
|
+
end
|
10
|
+
|
11
|
+
test "#interpolate_environment_variables replace environment variables by their value" do
|
12
|
+
command = Command.new('cap $ENVIRONMENT deploy', env: {'ENVIRONMENT' => 'production'}, chdir: '.')
|
13
|
+
assert_equal [%(cap production deploy)], command.interpolated_arguments
|
14
|
+
end
|
15
|
+
|
16
|
+
test "#interpolate_environment_variables coerce nil to empty string" do
|
17
|
+
command = Command.new('cap $FOO deploy', env: {'ENVIRONMENT' => 'production'}, chdir: '.')
|
18
|
+
assert_equal [%(cap '' deploy)], command.interpolated_arguments
|
19
|
+
end
|
20
|
+
|
21
|
+
test '#interpolate_environment_variables escape the variable contents' do
|
22
|
+
malicious_string = '$(echo pwnd)'
|
23
|
+
command = Command.new('echo $FOO', env: {'FOO' => malicious_string}, chdir: '.')
|
24
|
+
assert_equal malicious_string, command.run.chomp
|
25
|
+
end
|
26
|
+
|
27
|
+
test "#interpolate_environment_variables fallback to ENV" do
|
28
|
+
command = Command.new('cap $LANG deploy', env: {'ENVIRONMENT' => 'production'}, chdir: '.')
|
29
|
+
assert_equal [%(cap #{ENV['LANG']} deploy)], command.interpolated_arguments
|
30
|
+
end
|
31
|
+
|
32
|
+
test "#timeout is 5 minutes by default" do
|
33
|
+
command = Command.new('cap $LANG deploy', env: {'ENVIRONMENT' => 'production'}, chdir: '.')
|
34
|
+
assert_equal 5.minutes.to_i, command.timeout
|
35
|
+
end
|
36
|
+
|
37
|
+
test "#timeout returns `default_timeout` if present" do
|
38
|
+
command = Command.new('cap $LANG deploy', default_timeout: 5, env: {}, chdir: '.')
|
39
|
+
assert_equal 5, command.timeout
|
40
|
+
end
|
41
|
+
|
42
|
+
test "#timeout returnsthe command option timeout over the `default_timeout` if present" do
|
43
|
+
command = Command.new({'cap $LANG deploy' => {'timeout' => 10}}, default_timeout: 5, env: {}, chdir: '.')
|
44
|
+
assert_equal 10, command.timeout
|
45
|
+
end
|
44
46
|
end
|
45
47
|
end
|