Skip to content

Commit c358f7e

Browse files
committed
Use allow_any_<action> syntax to simplify specs
We want our spec tests to focus on testing logic, not just enumerating which plans/tasks/commands are called. A big value out of these tests is just making sure they run to completion logically, assuming each of the tasks/plans doesn't fail. This commit simplifies the spec tests to allow execution actions by default, to achieve the value of making sure the plans run to completion with as little cognative overhead or unnecessary repetition as possible.
1 parent 919087c commit c358f7e

File tree

4 files changed

+20
-37
lines changed

4 files changed

+20
-37
lines changed

spec/plans/add_replica_spec.rb

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,18 @@
33
describe 'peadm::install' do
44
include BoltSpec::Plans
55

6-
def allow_standard_non_returning_calls(params)
6+
def allow_standard_non_returning_calls
77
allow_apply
8-
allow_task('peadm::agent_install')
9-
allow_task('peadm::ssl_clean')
10-
allow_task('peadm::submit_csr')
11-
allow_task('peadm::sign_csr')
12-
allow_task('peadm::puppet_runonce')
13-
allow_task('peadm::provision_replica')
14-
allow_command('systemctl start puppet.service')
15-
allow_command("puppet infrastructure forget #{params['replica_host']}")
16-
allow_command("puppet node purge #{params['replica_host']}")
8+
allow_any_task
9+
allow_any_command
1710
end
1811

1912
describe 'basic functionality' do
2013
let(:params) { { 'primary_host' => 'primary', 'replica_host' => 'replica' } }
2114
let(:certdata) { { 'certname' => 'primary', 'extensions' => { '1.3.6.1.4.1.34380.1.1.9813' => 'A' } } }
2215

2316
it 'runs successfully when the primary doesn\'t have alt-names' do
24-
allow_standard_non_returning_calls(params)
17+
allow_standard_non_returning_calls
2518
expect_task('peadm::cert_data').always_return(certdata)
2619
expect_task('peadm::agent_install')
2720
.with_params({ 'server' => 'primary',
@@ -37,7 +30,7 @@ def allow_standard_non_returning_calls(params)
3730
end
3831

3932
it 'runs successfully when the primary has alt-names' do
40-
allow_standard_non_returning_calls(params)
33+
allow_standard_non_returning_calls
4134
expect_task('peadm::cert_data').always_return(certdata.merge({ 'dns-alt-names' => ['primary', 'alt'] }))
4235
expect_task('peadm::agent_install')
4336
.with_params({ 'server' => 'primary',

spec/plans/subplans/configure_spec.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55

66
describe 'Standard architecture without DR' do
77
it 'runs successfully' do
8-
expect_task('peadm::read_file').always_return({ 'content' => 'mock' })
9-
expect_task('peadm::puppet_runonce')
10-
expect_command('systemctl start puppet')
118
allow_apply
9+
allow_any_task
10+
allow_any_plan
11+
allow_any_command
1212

13+
expect_task('peadm::read_file').always_return({ 'content' => 'mock' })
1314
expect_task('peadm::provision_replica').not_be_called
1415
expect_task('peadm::code_manager').not_be_called
1516

spec/plans/subplans/install_spec.rb

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,16 @@
55
include BoltSpec::Plans
66

77
it 'minimum variables to run' do
8+
allow_any_task
9+
allow_any_plan
10+
allow_any_command
11+
812
allow_task('peadm::precheck').return_for_targets(
913
'primary' => {
1014
'hostname' => 'primary',
1115
'platform' => 'el-7.11-x86_64'
1216
},
1317
)
14-
expect_task('peadm::mkdir_p_file').be_called_times(5)
15-
expect_plan('peadm::util::retrieve_and_upload')
16-
expect_task('peadm::read_file')
17-
expect_task('peadm::pe_install')
18-
expect_command('systemctl stop pe-puppetdb')
19-
expect_command('systemctl start pe-puppetdb')
20-
expect_task('peadm::rbac_token')
21-
expect_task('peadm::code_manager')
22-
expect_task('peadm::puppet_runonce').be_called_times(2)
23-
expect_task('peadm::wait_until_service_ready')
2418

2519
#########
2620
## <🤮>

spec/plans/upgrade_spec.rb

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,15 @@
99
end
1010

1111
it 'minimum variables to run' do
12+
allow_apply
13+
allow_any_task
14+
allow_any_plan
15+
allow_any_command
1216
allow_out_message
13-
expect_task('peadm::cert_data').return_for_targets(
14-
'primary' => trustedjson,
15-
)
17+
18+
expect_task('peadm::cert_data').return_for_targets('primary' => trustedjson)
1619
expect_task('peadm::read_file').always_return({ 'content' => 'mock' })
17-
expect_task('peadm::precheck')
18-
expect_plan('peadm::util::retrieve_and_upload')
19-
expect_command('systemctl stop puppet')
20-
allow_task('peadm::puppet_runonce')
21-
expect_plan('peadm::modify_cert_extensions')
22-
allow_apply
23-
expect_task('peadm::pe_install')
24-
allow_task('peadm::puppet_infra_upgrade')
25-
expect_task('service')
20+
2621
expect(run_plan('peadm::upgrade', 'primary_host' => 'primary', 'version' => '2019.8.6')).to be_ok
2722
end
2823
end

0 commit comments

Comments
 (0)