Skip to content

Commit 6c49620

Browse files
committed
(PUP-11764) DRY module integration tests
Also delete last remnants of the test forge
1 parent 0b8c976 commit 6c49620

File tree

2 files changed

+23
-32
lines changed

2 files changed

+23
-32
lines changed

acceptance/.beaker.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ xml: true
77
timesync: false
88
repo_proxy: true
99
add_el_extras: false
10-
forge_host: api-forge-aio02-petest.puppet.com
1110
'master-start-curl-retries': 30
1211
log_level: debug
1312
preserve_hosts: onfail

spec/integration/application/module_spec.rb

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -102,27 +102,39 @@
102102
end
103103

104104
context 'changes' do
105-
it 'reports an error when the install path is invalid' do
105+
let(:tmp) { tmpdir('module_changes') }
106+
107+
before :each do
106108
Puppet.initialize_settings(['-E', 'direnv'])
107109
Puppet[:color] = false
110+
end
111+
112+
def use_local_fixture
108113
Puppet[:environmentpath] = File.join(my_fixture_dir, 'environments')
109-
dir = tmpdir('module_changes')
114+
end
115+
116+
def create_working_copy
117+
Puppet[:environmentpath] = File.join(tmp, 'environments')
118+
FileUtils.cp_r(File.join(my_fixture_dir, 'environments'), tmp)
119+
end
120+
121+
it 'reports an error when the install path is invalid' do
122+
use_local_fixture
110123

111124
pattern = Regexp.new([
112-
%Q{.*Error: Could not find a valid module at "#{dir}/nginx".*},
125+
%Q{.*Error: Could not find a valid module at "#{tmp}/nginx".*},
113126
%Q{.*Error: Try 'puppet help module changes' for usage.*},
114127
].join("\n"), Regexp::MULTILINE)
115128

116129
expect {
117-
app.command_line.args = ['changes', File.join(dir, 'nginx')]
130+
app.command_line.args = ['changes', File.join(tmp, 'nginx')]
118131
app.run
119132
}.to exit_with(1)
120133
.and output(pattern).to_stderr
121134
end
122135

123136
it 'reports when checksums are missing from metadata.json' do
124-
tmp = tmpdir('module_invalid_checksums')
125-
FileUtils.cp_r(File.join(my_fixture_dir, 'environments'), tmp)
137+
create_working_copy
126138

127139
# overwrite checksums in metadata.json
128140
nginx_dir = File.join(tmp, 'environments', 'direnv', 'modules', 'nginx')
@@ -133,10 +145,6 @@
133145
}
134146
END
135147

136-
Puppet.initialize_settings(['-E', 'direnv'])
137-
Puppet[:color] = false
138-
Puppet[:environmentpath] = File.join(tmp, 'environments')
139-
140148
pattern = Regexp.new([
141149
%Q{.*Error: No file containing checksums found.*},
142150
%Q{.*Error: Try 'puppet help module changes' for usage.*},
@@ -150,17 +158,12 @@
150158
end
151159

152160
it 'reports module not found when metadata.json is missing' do
153-
tmp = tmpdir('module_missing_metadata')
154-
FileUtils.cp_r(File.join(my_fixture_dir, 'environments'), tmp)
161+
create_working_copy
155162

156163
# overwrite checksums in metadata.json
157164
nginx_dir = File.join(tmp, 'environments', 'direnv', 'modules', 'nginx')
158165
File.unlink(File.join(nginx_dir, 'metadata.json'))
159166

160-
Puppet.initialize_settings(['-E', 'direnv'])
161-
Puppet[:color] = false
162-
Puppet[:environmentpath] = File.join(tmp, 'environments')
163-
164167
pattern = Regexp.new([
165168
%Q{.*Error: Could not find a valid module at.*},
166169
%Q{.*Error: Try 'puppet help module changes' for usage.*},
@@ -174,17 +177,12 @@
174177
end
175178

176179
it 'reports when a file is modified' do
177-
tmp = tmpdir('module_modified_metadata')
178-
FileUtils.cp_r(File.join(my_fixture_dir, 'environments'), tmp)
180+
create_working_copy
179181

180182
# overwrite README so checksum doesn't match
181183
nginx_dir = File.join(tmp, 'environments', 'direnv', 'modules', 'nginx')
182184
File.write(File.join(nginx_dir, 'README'), '')
183185

184-
Puppet.initialize_settings(['-E', 'direnv'])
185-
Puppet[:color] = false
186-
Puppet[:environmentpath] = File.join(tmp, 'environments')
187-
188186
pattern = Regexp.new([
189187
%Q{.*Warning: 1 files modified.*},
190188
].join("\n"), Regexp::MULTILINE)
@@ -198,17 +196,12 @@
198196
end
199197

200198
it 'reports when a file is missing' do
201-
tmp = tmpdir('module_missing_file')
202-
FileUtils.cp_r(File.join(my_fixture_dir, 'environments'), tmp)
199+
create_working_copy
203200

204201
# delete README so checksum doesn't match
205202
nginx_dir = File.join(tmp, 'environments', 'direnv', 'modules', 'nginx')
206203
File.unlink(File.join(nginx_dir, 'README'))
207204

208-
Puppet.initialize_settings(['-E', 'direnv'])
209-
Puppet[:color] = false
210-
Puppet[:environmentpath] = File.join(tmp, 'environments')
211-
212205
# odd that it says modified
213206
pattern = Regexp.new([
214207
%Q{.*Warning: 1 files modified.*},
@@ -223,9 +216,8 @@
223216
end
224217

225218
it 'reports when there are no changes' do
226-
Puppet.initialize_settings(['-E', 'direnv'])
227-
Puppet[:color] = false
228-
Puppet[:environmentpath] = File.join(my_fixture_dir, 'environments')
219+
use_local_fixture
220+
229221
nginx_dir = File.join(Puppet[:environmentpath], 'direnv', 'modules', 'nginx')
230222

231223
expect {

0 commit comments

Comments
 (0)