Skip to content

Commit d111ff2

Browse files
reidmvtimidri
andcommitted
Create basic spec test for add_replica plan
This helps validate that the plan is syntactically valid, uses data correctly, etc. Useful for potential refactors. Co-authored-by: Dimitri Tischenko <[email protected]>
1 parent 8780ee7 commit d111ff2

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

Diff for: spec/plans/add_replica_spec.rb

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
require 'spec_helper'
2+
3+
describe 'peadm::install' do
4+
include BoltSpec::Plans
5+
6+
def allow_standard_non_returning_calls(params)
7+
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']}")
17+
end
18+
19+
describe 'basic functionality' do
20+
let(:params) { { 'primary_host' => 'primary', 'replica_host' => 'replica' } }
21+
let(:certdata) { { 'certname' => 'primary', 'extensions' => { '1.3.6.1.4.1.34380.1.1.9813' => 'A' } } }
22+
23+
it 'runs successfully when the primary doesn\'t have alt-names' do
24+
allow_standard_non_returning_calls(params)
25+
expect_task('peadm::cert_data').always_return(certdata)
26+
expect_task('peadm::agent_install')
27+
.with_params({ 'server' => 'primary',
28+
'install_flags' => [
29+
'--puppet-service-ensure', 'stopped',
30+
'extension_requests:1.3.6.1.4.1.34380.1.1.9812=puppet/server',
31+
'extension_requests:1.3.6.1.4.1.34380.1.1.9813=B',
32+
'main:certname=replica',
33+
'main:dns_alt_names=replica'
34+
] })
35+
36+
expect(run_plan('peadm::add_replica', params)).to be_ok
37+
end
38+
39+
it 'runs successfully when the primary has alt-names' do
40+
allow_standard_non_returning_calls(params)
41+
expect_task('peadm::cert_data').always_return(certdata.merge({ 'dns-alt-names' => ['primary', 'alt'] }))
42+
expect_task('peadm::agent_install')
43+
.with_params({ 'server' => 'primary',
44+
'install_flags' => [
45+
'--puppet-service-ensure', 'stopped',
46+
'extension_requests:1.3.6.1.4.1.34380.1.1.9812=puppet/server',
47+
'extension_requests:1.3.6.1.4.1.34380.1.1.9813=B',
48+
'main:certname=replica',
49+
'main:dns_alt_names=replica,alt'
50+
] })
51+
52+
expect(run_plan('peadm::add_replica', params)).to be_ok
53+
end
54+
end
55+
end

0 commit comments

Comments
 (0)