|
7 | 7 | tmp_path = 'C:/cygwin64/tmp'
|
8 | 8 | test_container = 'nanoserver-sac2016'
|
9 | 9 | else
|
10 |
| - if fact('os.name') == 'RedHat' |
11 |
| - docker_args = "repo_opt => '--enablerepo=localmirror-extras'" |
12 |
| - elsif fact('os.name') == 'Centos' |
13 |
| - docker_args = "repo_opt => '--enablerepo=localmirror-extras'" |
14 |
| - elsif fact('os.name') == 'Ubuntu' && fact('os.release.full') == '14.04' |
15 |
| - docker_args = "version => '18.06.1~ce~3-0~ubuntu'" |
16 |
| - else |
17 |
| - docker_args = '' |
18 |
| - end |
| 10 | + docker_args = if fact('os.name') == 'RedHat' |
| 11 | + "repo_opt => '--enablerepo=localmirror-extras'" |
| 12 | + elsif fact('os.name') == 'Centos' |
| 13 | + "repo_opt => '--enablerepo=localmirror-extras'" |
| 14 | + elsif fact('os.name') == 'Ubuntu' && fact('os.release.full') == '14.04' |
| 15 | + "version => '18.06.1~ce~3-0~ubuntu'" |
| 16 | + else |
| 17 | + '' |
| 18 | + end |
19 | 19 | install_dir = '/usr/local/bin'
|
20 | 20 | file_extension = ''
|
21 | 21 | tmp_path = '/tmp'
|
|
24 | 24 |
|
25 | 25 | describe 'docker compose' do
|
26 | 26 | before(:all) do
|
27 |
| - retry_on_error_matching(60, 5, /connection failure running/) do |
| 27 | + retry_on_error_matching(60, 5, %r{connection failure running}) do |
28 | 28 | install_code = <<-code
|
29 | 29 | class { 'docker': #{docker_args} }
|
30 | 30 | class { 'docker::compose':
|
31 | 31 | version => '1.23.2',
|
32 | 32 | }
|
33 | 33 | code
|
34 |
| - apply_manifest(install_code, :catch_failures=>true) |
| 34 | + apply_manifest(install_code, catch_failures: true) |
35 | 35 | end
|
36 | 36 | end
|
37 | 37 |
|
38 | 38 | context 'Creating compose v3 projects' do
|
39 |
| - it 'should have docker compose installed' do |
40 |
| - shell('docker-compose --help', :acceptable_exit_codes => [0]) |
| 39 | + let(:install_pp) do |
| 40 | + <<-MANIFEST |
| 41 | + docker_compose { 'web': |
| 42 | + compose_files => ['#{tmp_path}/docker-compose-v3.yml'], |
| 43 | + ensure => present, |
| 44 | + } |
| 45 | + MANIFEST |
41 | 46 | end
|
42 |
| - before(:all) do |
43 |
| - @install = <<-code |
44 |
| -docker_compose { 'web': |
45 |
| - compose_files => ['#{tmp_path}/docker-compose-v3.yml'], |
46 |
| - ensure => present, |
47 |
| -} |
48 |
| - code |
49 |
| - apply_manifest(@install, :catch_failures=>true) |
| 47 | + |
| 48 | + it 'is idempotent' do |
| 49 | + idempotent_apply(default, install_pp, {}) |
50 | 50 | end
|
51 | 51 |
|
52 |
| - it 'should be idempotent' do |
53 |
| - apply_manifest(@install, :catch_changes=>true) |
| 52 | + it 'has docker compose installed' do |
| 53 | + shell('docker-compose --help', acceptable_exit_codes: [0]) |
54 | 54 | end
|
55 | 55 |
|
56 |
| - it 'should find a docker container' do |
57 |
| - shell('docker inspect web_compose_test_1', :acceptable_exit_codes => [0]) |
| 56 | + it 'finds a docker container' do |
| 57 | + shell('docker inspect web_compose_test_1', acceptable_exit_codes: [0]) |
58 | 58 | end
|
59 | 59 | end
|
60 | 60 |
|
61 | 61 | context 'creating compose projects with multi compose files' do
|
62 | 62 | before(:all) do
|
63 |
| - @install = <<-pp1 |
64 |
| -docker_compose { 'web1': |
65 |
| - compose_files => ['#{tmp_path}/docker-compose-v3.yml', '#{tmp_path}/docker-compose-override-v3.yml'], |
66 |
| - ensure => present, |
67 |
| -} |
68 |
| - pp1 |
| 63 | + install_pp = <<-MANIFEST |
| 64 | + docker_compose { 'web1': |
| 65 | + compose_files => ['#{tmp_path}/docker-compose-v3.yml', '#{tmp_path}/docker-compose-override-v3.yml'], |
| 66 | + ensure => present, |
| 67 | + } |
| 68 | + MANIFEST |
69 | 69 |
|
70 |
| - apply_manifest(@install, :catch_failures=>true) |
| 70 | + apply_manifest(install_pp, catch_failures: true) |
71 | 71 | end
|
72 | 72 |
|
73 | 73 | it "should find container with #{test_container} tag" do
|
74 |
| - shell("docker inspect web1_compose_test_1 | grep #{test_container}", :acceptable_exit_codes => [0]) |
| 74 | + shell("docker inspect web1_compose_test_1 | grep #{test_container}", acceptable_exit_codes: [0]) |
75 | 75 | end
|
76 | 76 | end
|
77 | 77 |
|
78 | 78 | context 'Destroying project with multiple compose files' do
|
| 79 | + let(:destroy_pp) do |
| 80 | + <<-MANIFEST |
| 81 | + docker_compose { 'web1': |
| 82 | + compose_files => ['#{tmp_path}/docker-compose-v3.yml', '#{tmp_path}/docker-compose-override-v3.yml'], |
| 83 | + ensure => absent, |
| 84 | + } |
| 85 | + MANIFEST |
| 86 | + end |
| 87 | + |
79 | 88 | before(:all) do
|
80 |
| - @install = <<-pp1 |
81 |
| -docker_compose { 'web1': |
82 |
| - compose_files => ['#{tmp_path}/docker-compose-v3.yml', '#{tmp_path}/docker-compose-override-v3.yml'], |
83 |
| - ensure => present, |
84 |
| -} |
85 |
| - pp1 |
| 89 | + install_pp = <<-MANIFEST |
| 90 | + docker_compose { 'web1': |
| 91 | + compose_files => ['#{tmp_path}/docker-compose-v3.yml', '#{tmp_path}/docker-compose-override-v3.yml'], |
| 92 | + ensure => present, |
| 93 | + } |
| 94 | + MANIFEST |
86 | 95 |
|
87 |
| - @destroy = <<-pp2 |
88 |
| -docker_compose { 'web1': |
89 |
| - compose_files => ['#{tmp_path}/docker-compose-v3.yml', '#{tmp_path}/docker-compose-override-v3.yml'], |
90 |
| - ensure => absent, |
91 |
| -} |
92 |
| - pp2 |
93 |
| - apply_manifest(@install, :catch_failures=>true) |
94 |
| - apply_manifest(@destroy, :catch_failures=>true) |
| 96 | + apply_manifest(install_pp, catch_failures: true) |
95 | 97 | end
|
96 | 98 |
|
97 |
| - it 'should be idempotent' do |
98 |
| - apply_manifest(@destroy, :catch_changes=>true) |
| 99 | + it 'is idempotent' do |
| 100 | + idempotent_apply(default, destroy_pp, {}) |
99 | 101 | end
|
100 | 102 |
|
101 |
| - it 'should not find a docker container' do |
102 |
| - shell('docker inspect web1_compose_test_1', :acceptable_exit_codes => [1]) |
| 103 | + it 'does not find a docker container' do |
| 104 | + shell('docker inspect web1_compose_test_1', acceptable_exit_codes: [1]) |
103 | 105 | end
|
104 | 106 | end
|
105 | 107 |
|
106 | 108 | context 'Requesting a specific version of compose' do
|
107 |
| - before(:all) do |
108 |
| - @version = '1.21.2' |
109 |
| - @pp = <<-code |
110 |
| -class { 'docker::compose': |
111 |
| - version => '#{@version}', |
112 |
| -} |
113 |
| - code |
114 |
| - apply_manifest(@pp, :catch_failures=>true) |
| 109 | + let(:version) do |
| 110 | + '1.21.2' |
115 | 111 | end
|
116 | 112 |
|
117 |
| - it 'should be idempotent' do |
118 |
| - apply_manifest(@pp, :catch_changes=>true) |
| 113 | + it 'is idempotent' do |
| 114 | + pp = <<-MANIFEST |
| 115 | + class { 'docker::compose': |
| 116 | + version => '#{version}', |
| 117 | + } |
| 118 | + MANIFEST |
| 119 | + idempotent_apply(default, pp, {}) |
119 | 120 | end
|
120 | 121 |
|
121 |
| - it 'should have installed the requested version' do |
122 |
| - shell('docker-compose --version', :acceptable_exit_codes => [0]) do |r| |
123 |
| - expect(r.stdout).to match(/#{@version}/) |
| 122 | + it 'has installed the requested version' do |
| 123 | + shell('docker-compose --version', acceptable_exit_codes: [0]) do |r| |
| 124 | + expect(r.stdout).to match(%r{#{version}}) |
124 | 125 | end
|
125 | 126 | end
|
126 | 127 | end
|
127 | 128 |
|
128 | 129 | context 'Removing docker compose' do
|
129 |
| - before(:all) do |
130 |
| - @version = '1.21.2' |
131 |
| - @pp = <<-code |
132 |
| -class { 'docker::compose': |
133 |
| - ensure => absent, |
134 |
| - version => '#{@version}', |
135 |
| -} |
136 |
| - code |
137 |
| - apply_manifest(@pp, :catch_failures=>true) |
| 130 | + let(:version) do |
| 131 | + '1.21.2' |
138 | 132 | end
|
139 | 133 |
|
140 |
| - it 'should be idempotent' do |
141 |
| - apply_manifest(@pp, :catch_changes=>true) |
| 134 | + it 'is idempotent' do |
| 135 | + pp = <<-MANIFEST |
| 136 | + class { 'docker::compose': |
| 137 | + ensure => absent, |
| 138 | + version => '#{version}', |
| 139 | + } |
| 140 | + MANIFEST |
| 141 | + idempotent_apply(default, pp, {}) |
142 | 142 | end
|
143 | 143 |
|
144 |
| - it 'should have removed the relevant files' do |
145 |
| - shell("test -e \"#{install_dir}/docker-compose#{file_extension}\"", :acceptable_exit_codes => [1]) |
146 |
| - shell("test -e \"#{install_dir}/docker-compose-#{@version}#{file_extension}\"", :acceptable_exit_codes => [1]) |
| 144 | + it 'has removed the relevant files' do |
| 145 | + shell("test -e \"#{install_dir}/docker-compose#{file_extension}\"", acceptable_exit_codes: [1]) |
| 146 | + shell("test -e \"#{install_dir}/docker-compose-#{version}#{file_extension}\"", acceptable_exit_codes: [1]) |
147 | 147 | end
|
148 | 148 |
|
149 | 149 | after(:all) do
|
150 |
| - install_code = <<-code |
| 150 | + install_pp = <<-MANIFEST |
151 | 151 | class { 'docker': #{docker_args}}
|
152 | 152 | class { 'docker::compose': }
|
153 |
| - code |
154 |
| - apply_manifest(install_code, :catch_failures=>true) |
| 153 | + MANIFEST |
| 154 | + apply_manifest(install_pp, catch_failures: true) |
155 | 155 | end
|
156 | 156 | end
|
157 |
| - end |
| 157 | +end |
0 commit comments