Skip to content

Commit a052600

Browse files
author
Erick Banks
authored
Merge pull request chocolatey-archive#98 from RandomNoun7/tickets/master/MODULES-6746-convert_tests_to_respec
(MODULES-6746) Convert Tests to RSpec
2 parents 79dd265 + c9efdd4 commit a052600

12 files changed

+1286
-27
lines changed

Rakefile

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ require 'rspec/core/rake_task'
33
require 'puppetlabs_spec_helper/rake_tasks'
44
require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any?
55
require 'puppet'
6+
require 'bundler'
7+
8+
require 'pry' if Bundler.rubygems.find_name('pry').any?
9+
Bundler.require(:rake)
10+
11+
Dir.glob('build/*.rb').each { |r| import r }
12+
Dir.glob('build/*.rake').each { |r| import r }
613

714
begin
815
require 'beaker/tasks/test' unless RUBY_PLATFORM =~ /win32/

spec/acceptance/config_values_spec.rb

+169
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'Chocolatey Config' do
4+
5+
context 'MODULES-3035 - Add New Config Item' do
6+
7+
before(:all) do
8+
backup_config
9+
end
10+
11+
after(:all) do
12+
reset_config
13+
end
14+
15+
chocolatey_src = <<-PP
16+
chocolateyconfig {'hello123':
17+
ensure => present,
18+
value => 'this guy',
19+
}
20+
PP
21+
22+
it_behaves_like 'a successful config change', chocolatey_src, 'hello123', /this guy/
23+
end
24+
25+
context 'MODULES-3035 - Add a Value to an Existing Config Setting' do
26+
27+
before(:all) do
28+
backup_config
29+
end
30+
31+
after(:all) do
32+
reset_config
33+
end
34+
35+
chocolatey_src = <<-PP
36+
chocolateyconfig {'proxy':
37+
ensure => present,
38+
value => 'https://somewhere',
39+
}
40+
PP
41+
42+
it_behaves_like 'a successful config change', chocolatey_src, 'proxy', /https\:\/\/somewhere/
43+
end
44+
45+
context 'MODULES-3035 - Config Settings Change Config Value' do
46+
47+
before(:all) do
48+
backup_config
49+
end
50+
51+
after(:all) do
52+
reset_config
53+
end
54+
55+
chocolatey_src = <<-PP
56+
chocolateyconfig {'proxyUser':
57+
value => 'bob',
58+
}
59+
PP
60+
61+
chocolatey_src_change = <<-PP
62+
chocolateyconfig {'proxyuser':
63+
value => 'tim',
64+
}
65+
PP
66+
67+
# Add the config item
68+
it_behaves_like 'a successful config change', chocolatey_src, 'proxyUser', /bob/
69+
70+
# Now that it exists, change its value
71+
it_behaves_like 'a successful config change', chocolatey_src_change, 'proxyUser', /tim/
72+
end
73+
74+
context 'MODULES-3035 Ensure Config Value with Password In Name' do
75+
76+
before(:all) do
77+
backup_config
78+
end
79+
80+
after(:all) do
81+
reset_config
82+
end
83+
84+
chocolatey_src = <<-PP
85+
chocolateyconfig {'proxyPassword':
86+
value => 'secrect',
87+
}
88+
PP
89+
90+
chocolatey_src_change = <<-PP
91+
chocolateyconfig {'proxyPassword':
92+
value => 'secrect2',
93+
}
94+
PP
95+
96+
# The password should set one time and then not change.
97+
it_behaves_like 'a password that doesn\'t change', chocolatey_src, chocolatey_src_change, 'proxyPassword'
98+
end
99+
100+
context 'MODULES-3035 - Fail to Set Present With No Value' do
101+
102+
before(:all) do
103+
backup_config
104+
end
105+
106+
after(:all) do
107+
reset_config
108+
end
109+
110+
chocolatey_src = <<-PP
111+
chocolateyconfig {'bob':
112+
ensure => present,
113+
}
114+
PP
115+
116+
expected_error = /Unless ensure => absent, value is required./
117+
118+
# A manifest with present set, but no values to enforce should not run.
119+
it_behaves_like 'a failing manifest', chocolatey_src, expected_error
120+
end
121+
122+
context 'MODULES-3035 - Config Settings Remove Value with Password in the Name' do
123+
124+
before(:all) do
125+
backup_config
126+
end
127+
128+
after(:all) do
129+
reset_config
130+
end
131+
132+
chocolatey_src = <<-PP
133+
chocolateyconfig {'proxyPassword':
134+
value => 'secret',
135+
}
136+
PP
137+
138+
chocolatey_src_change = <<-PP
139+
chocolateyconfig {'proxyPassword':
140+
ensure => absent,
141+
}
142+
PP
143+
144+
# The password will end up a hash, so we specify a regex that just verifies a hash exists.
145+
it_behaves_like 'a successful config change', chocolatey_src, 'proxyPassword', /(.+)/
146+
147+
it_behaves_like 'a manifest that removes a config value', chocolatey_src_change, 'proxyPassword'
148+
end
149+
150+
context 'MODULES-3035 - Remove Value from Config Setting' do
151+
152+
before(:all) do
153+
backup_config
154+
end
155+
156+
after(:all) do
157+
reset_config
158+
end
159+
160+
chocolatey_src = <<-PP
161+
chocolateyconfig {'commandExecutionTimeoutSeconds':
162+
ensure => absent,
163+
}
164+
PP
165+
166+
it_behaves_like 'a manifest that removes a config value', chocolatey_src, 'commandExecutionTimeoutSeconds'
167+
end
168+
end
169+

0 commit comments

Comments
 (0)