Skip to content

Commit f62989e

Browse files
committed
clean up of duplicated code
1 parent 29437d0 commit f62989e

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

_docker/lib/options.rb

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
class Options
2+
23
def self.parse(args)
34
tasks = {supporting_services: %w(-d)}
45

@@ -20,15 +21,16 @@ def self.parse(args)
2021
end
2122

2223
opts.on('-t', '--unit-test', 'Run the unit tests') do |b|
23-
tasks[:unit_tests] = ['--no-deps', '--rm', 'awestruct', "bundle exec rake test"]
24+
tasks[:unit_tests] = unit_test_tasks
2425
tasks[:decrypt] = true
2526
tasks[:set_ports] = true
2627
tasks[:build] = true
2728
end
2829

30+
2931
opts.on('-b', '--build', 'Build the containers') do |b|
3032
tasks[:decrypt] = true
31-
tasks[:unit_tests] = ['--no-deps', '--rm', 'awestruct', "bundle exec rake test"]
33+
tasks[:unit_tests] = unit_test_tasks
3234
tasks[:set_ports] = true
3335
tasks[:build] = true
3436
end
@@ -61,37 +63,37 @@ def self.parse(args)
6163
tasks[:awestruct_command_args] = ["--no-deps", "--rm", "--service-ports", "awestruct", "bundle exec rake create_pr_dirs[docker-pr,build,#{pr}] clean deploy[staging_docker]"]
6264
tasks[:kill_all] = true
6365
tasks[:build] = true
64-
tasks[:unit_tests] = ['--no-deps', '--rm', 'awestruct', "bundle exec rake test"]
66+
tasks[:unit_tests] = unit_test_tasks
6567
tasks[:set_ports] = true
6668
tasks[:supporting_services] += %w(elasticsearch mysql searchisko searchiskoconfigure)
6769
end
6870

6971
opts.on('--acceptance_test_docker', String, 'runs the cucumber features against the local running docker stack.') do
7072
tasks[:acceptance_test_target_task] = ["--no-deps", "--rm", "--service-ports", "awestruct_acceptance", "bundle exec rake features"]
7173
tasks[:build] = true
72-
tasks[:unit_tests] = ['--no-deps', '--rm', 'awestruct', "bundle exec rake test"]
74+
tasks[:unit_tests] = unit_test_tasks
7375
end
7476

7577
opts.on('--acceptance_test_target HOST_TO_TEST', String, 'runs the cucumber features against the specified HOST_TO_TEST') do |f|
7678
ENV['HOST_TO_TEST'] = f
7779
tasks[:acceptance_test_target_task] = ["--no-deps", "--rm", "--service-ports", "awestruct", "bundle exec rake features"]
7880
tasks[:build] = true
79-
tasks[:unit_tests] = ['--no-deps', '--rm', 'awestruct', "bundle exec rake test"]
81+
tasks[:unit_tests] = unit_test_tasks
8082
end
8183

8284
opts.on('--docker-nightly', 'build for PR Staging') do |pr|
8385
tasks[:awestruct_command_args] = ["--no-deps", "--rm", "--service-ports", "awestruct", "bundle exec rake create_pr_dirs[docker-nightly,build,docker-nightly] clean deploy[staging_docker]"]
8486
tasks[:kill_all] = true
8587
tasks[:build] = true
8688
tasks[:set_ports] = true
87-
tasks[:unit_tests] = ['--no-deps', '--rm', 'awestruct', "bundle exec rake test"]
89+
tasks[:unit_tests] = unit_test_tasks
8890
tasks[:supporting_services] += %w(elasticsearch mysql searchisko searchiskoconfigure)
8991
end
9092

9193
opts.on('--run-the-stack', 'build, restart and preview') do |rts|
9294
tasks[:decrypt] = true
9395
tasks[:set_ports] = true
94-
tasks[:unit_tests] = ['--no-deps', '--rm', 'awestruct', "bundle exec rake test"]
96+
tasks[:unit_tests] = unit_test_tasks
9597
tasks[:build] = true
9698
tasks[:kill_all] = true
9799
tasks[:supporting_services] += %w(elasticsearch mysql searchisko searchiskoconfigure)
@@ -119,5 +121,10 @@ def self.parse(args)
119121
tasks[:should_start_supporting_services] = tasks[:supporting_services].size > 1
120122
tasks
121123
end
124+
125+
def self.unit_test_tasks
126+
['--no-deps', '--rm', 'awestruct', "bundle exec rake test"]
127+
end
128+
122129
end
123130

_docker/test/test_options.rb

+11-7
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_decrypt
3232
def test_set_ports
3333
tasks = Options.parse (["-b"])
3434
assert(tasks[:set_ports])
35-
assert_equal(tasks[:unit_tests], ['--no-deps', '--rm', 'awestruct', 'bundle exec rake test'])
35+
assert_equal(tasks[:unit_tests], expected_unit_test_tasks)
3636

3737
tasks = Options.parse (["-r"])
3838
assert(tasks[:set_ports])
@@ -81,7 +81,7 @@ def test_acceptance_test_target_task_default_value
8181
ClimateControl.modify HOST_TO_TEST: nil, AWESTRUCT_HOST_PORT: '32768' do
8282
tasks = Options.parse (["--acceptance_test_docker"])
8383
assert(tasks[:build])
84-
assert_equal(tasks[:unit_tests], ['--no-deps', '--rm', 'awestruct', 'bundle exec rake test'])
84+
assert_equal(tasks[:unit_tests], expected_unit_test_tasks)
8585
refute(tasks[:set_ports])
8686
assert_equal(nil, ENV['HOST_TO_TEST'])
8787
assert_equal(["--no-deps", "--rm", "--service-ports", "awestruct_acceptance", "bundle exec rake features"], tasks[:acceptance_test_target_task])
@@ -91,7 +91,7 @@ def test_acceptance_test_target_task_default_value
9191
def test_acceptance_test_target_task
9292
tasks = Options.parse (["--acceptance_test_target=http://example.com"])
9393
assert(tasks[:build])
94-
assert_equal(tasks[:unit_tests], ['--no-deps', '--rm', 'awestruct', 'bundle exec rake test'])
94+
assert_equal(tasks[:unit_tests], expected_unit_test_tasks)
9595
assert_equal('http://example.com', ENV['HOST_TO_TEST'])
9696
refute(tasks[:set_ports])
9797
assert_equal(["--no-deps", "--rm", "--service-ports", "awestruct", "bundle exec rake features"], tasks[:acceptance_test_target_task])
@@ -102,7 +102,7 @@ def test_run_docker_nightly
102102
refute_equal(["--no-deps", "--rm", "--service-ports", "awestruct", "bundle exec rake acceptance_test_target"], tasks[:acceptance_test_target_task])
103103
assert_equal(["--no-deps", "--rm", "--service-ports", "awestruct", "bundle exec rake create_pr_dirs[docker-nightly,build,docker-nightly] clean deploy[staging_docker]"], tasks[:awestruct_command_args])
104104
assert(tasks[:kill_all])
105-
assert_equal(tasks[:unit_tests], ['--no-deps', '--rm', 'awestruct', 'bundle exec rake test'])
105+
assert_equal(tasks[:unit_tests], expected_unit_test_tasks)
106106
assert(tasks[:set_ports])
107107
assert(tasks[:build])
108108
assert_equal(tasks[:supporting_services], %w(-d elasticsearch mysql searchisko searchiskoconfigure))
@@ -112,15 +112,15 @@ def test_run_stage_pr
112112
tasks = Options.parse (["--stage-pr", "6"])
113113
assert(tasks[:kill_all])
114114
assert(tasks[:build])
115-
assert_equal(tasks[:unit_tests], ['--no-deps', '--rm', 'awestruct', 'bundle exec rake test'])
115+
assert_equal(tasks[:unit_tests], expected_unit_test_tasks)
116116
assert(tasks[:set_ports])
117117
assert_equal(tasks[:supporting_services], %w(-d elasticsearch mysql searchisko searchiskoconfigure))
118118
end
119119

120120
def test_run_the_stack
121121
tasks = Options.parse (["--run-the-stack"])
122122
assert(tasks[:kill_all])
123-
assert_equal(tasks[:unit_tests], ['--no-deps', '--rm', 'awestruct', 'bundle exec rake test'])
123+
assert_equal(tasks[:unit_tests], expected_unit_test_tasks)
124124
assert_equal(tasks[:supporting_services], %w(-d elasticsearch mysql searchisko searchiskoconfigure))
125125
assert_equal(['--no-deps', '--rm', '--service-ports', 'awestruct', 'rake git_setup clean preview[docker]'], tasks[:awestruct_command_args])
126126
end
@@ -130,12 +130,16 @@ def test_test_task
130130
assert(tasks[:build])
131131
assert(tasks[:set_ports])
132132
assert(tasks[:decrypt])
133-
assert_equal(tasks[:unit_tests], ['--no-deps', '--rm', 'awestruct', 'bundle exec rake test'])
133+
assert_equal(tasks[:unit_tests], expected_unit_test_tasks)
134134
end
135135

136136
def test_docker_url
137137
tasks = Options.parse (["-d", "SOMETHING"])
138138
assert_equal("SOMETHING",tasks[:docker])
139139
end
140+
141+
private def expected_unit_test_tasks
142+
['--no-deps', '--rm', 'awestruct', 'bundle exec rake test']
143+
end
140144
end
141145

0 commit comments

Comments
 (0)