Skip to content

Commit 33faa4d

Browse files
justinstollerspan786
authored andcommitted
(maint) update tests for newer beaker & minitest
This patch contains two changes: 1. Beaker TestCases used to have the methods `stdout`, `stderr`, and `exit_code` defined on them. These methods would delegate to the result of the last host command (usually executed via the `on` helper). Those delegating readers were like magical global variables, akin to Ruby's $1 returning the first match group of the last regex performed. These have been removed. Instead we have one of two options. `on` and friends will return a result object with `stdout`, etc defined on it, OR we can pass a block to `on` and it will pass a result object to the given block. We do whichever was most expedient. 2. The regex assertion `assert_no_match` has become `refute_match`.
1 parent ac5503f commit 33faa4d

File tree

13 files changed

+162
-142
lines changed

13 files changed

+162
-142
lines changed

acceptance/lib/helper.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,7 @@ def get_defaults_file
229229
def get_defaults_var(host, varname)
230230
defaults_file = get_defaults_file
231231

232-
on(host, "source #{defaults_file}; echo -n $#{varname}")
233-
stdout
232+
on(host, "source #{defaults_file}; echo -n $#{varname}").stdout
234233
end
235234

236235
# If we are getting the certificate for the first time, store it in the

acceptance/lib/puppetserver/acceptance/gem_utils.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ def get_gem_list(host, gem_list_command)
77
#
88
gem_list_regex = Regexp.new('(?<package>[\w-]*) (?<version>.*)')
99
array = []
10-
on(host, "#{gem_list_command}") do
11-
split_output = stdout.split
10+
on(host, "#{gem_list_command}") do |result|
11+
split_output = result.stdout.split
1212
split_output.each do |line|
1313
match = gem_list_regex.match(line)
1414
if match

acceptance/suites/puppet3_tests/puppet3_version_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
legacy_agents = agents.reject { |agent| agent == master }
55

66
step "Check that legacy agents have Puppet 3.x installed"
7-
on(legacy_agents, puppet("--version")) do
8-
assert(stdout.start_with? "3.", "puppet --version does not start with major version 3.")
7+
on(legacy_agents, puppet("--version")) do |result|
8+
assert(result.stdout.start_with? "3.", "puppet --version does not start with major version 3.")
99
end
1010

1111
step "Check that Puppet Server has Puppet 6.x installed"
12-
on(master, puppet("--version")) do
13-
assert_match(/\A6/, stdout, "puppet --version does not start with major version 6.x")
12+
on(master, puppet("--version")) do |result|
13+
assert_match(/\A6/, result.stdout, "puppet --version does not start with major version 6.x")
1414
end
1515

1616
step "Check that the agent on the master runs against the master"

acceptance/suites/tests/00_smoke/puppetdb_integration.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@
101101
# ISO 8601 timestamp, with milliseconds and time zone. Local time is used
102102
# instead of UTC as both PuppetDB and Puppet Server log in local time.
103103
run_timestamp = Time.iso8601(on(master, 'date +"%Y-%m-%dT%H:%M:%S.%3N%:z"').stdout.chomp)
104-
on(master, puppet_agent("--test"), :acceptable_exit_codes => [0,2]) do
105-
assert_match(/Notice: #{random_string}/, stdout,
104+
on(master, puppet_agent("--test"), :acceptable_exit_codes => [0,2]) do |result|
105+
assert_match(/Notice: #{random_string}/, result.stdout,
106106
'Puppet run collects exported Notify')
107107
end
108108
end

acceptance/suites/tests/010-puppetserver-cli/subcommand/SERVER-297_common_behavior.rb

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
proxy_env_vars = "HTTP_PROXY=foo http_proxy=foo HTTPS_PROXY=foo https_proxy=foo NO_PROXY=foo no_proxy=foo"
66

77
step "ruby: Check that PATH, HOME, GEM_HOME JARS_REQUIRE and JARS_NO_REQUIRE are present"
8-
on(master, "puppetserver ruby -rjson -e 'puts JSON.pretty_generate(ENV.to_hash)'") do
9-
env = JSON.parse(stdout)
8+
on(master, "puppetserver ruby -rjson -e 'puts JSON.pretty_generate(ENV.to_hash)'") do |result|
9+
env = JSON.parse(result.stdout)
1010
assert(env['PATH'], "PATH missing")
1111
assert(env['HOME'], "HOME missing")
1212
assert(env['GEM_HOME'], "GEM_HOME missing")
@@ -15,8 +15,8 @@
1515
end
1616

1717
step "ruby: Check that proxy env-variables are present"
18-
on(master, "#{proxy_env_vars} puppetserver ruby -rjson -e 'puts JSON.pretty_generate(ENV.to_hash)'") do
19-
env = JSON.parse(stdout)
18+
on(master, "#{proxy_env_vars} puppetserver ruby -rjson -e 'puts JSON.pretty_generate(ENV.to_hash)'") do |result|
19+
env = JSON.parse(result.stdout)
2020
assert_equal(env['HTTP_PROXY'], "foo",
2121
"HTTP_PROXY is missing or has wrong value: '#{env['HTTP_PROXY']}'")
2222
assert_equal(env['http_proxy'], "foo",
@@ -32,20 +32,20 @@
3232
end
3333

3434
step "irb: Check that PATH, HOME, GEM_HOME JARS_REQUIRE and JARS_NO_REQUIRE are present"
35-
on(master, "echo 'puts JSON.pretty_generate(ENV.to_hash)' | puppetserver irb -f -rjson") do
36-
assert_match(/\bPATH\b/, stdout, "PATH missing")
37-
assert_match(/\bHOME\b/, stdout, "HOME missing")
38-
assert_match(/\bGEM_HOME\b/, stdout, "GEM_HOME missing")
39-
assert_match(/\bJARS_REQUIRE\b/, stdout, "JARS_REQUIRE missing")
40-
assert_match(/\bJARS_NO_REQUIRE\b/, stdout, "JARS_NO_REQUIRE missing")
35+
on(master, "echo 'puts JSON.pretty_generate(ENV.to_hash)' | puppetserver irb -f -rjson") do |result|
36+
assert_match(/\bPATH\b/, result.stdout, "PATH missing")
37+
assert_match(/\bHOME\b/, result.stdout, "HOME missing")
38+
assert_match(/\bGEM_HOME\b/, result.stdout, "GEM_HOME missing")
39+
assert_match(/\bJARS_REQUIRE\b/, result.stdout, "JARS_REQUIRE missing")
40+
assert_match(/\bJARS_NO_REQUIRE\b/, result.stdout, "JARS_NO_REQUIRE missing")
4141
end
4242

4343
step "irb: Check that proxy env-variables are present"
44-
on(master, "echo 'puts JSON.pretty_generate(ENV.to_hash)' | #{proxy_env_vars} puppetserver irb -f -rjson") do
45-
assert_match(/\bHTTP_PROXY\b\W\W\s\W\bfoo\b/, stdout, "HTTP_PROXY missing or has wrong value")
46-
assert_match(/\bhttp_proxy\b\W\W\s\W\bfoo\b/, stdout, "http_proxy missing or has wrong value")
47-
assert_match(/\bHTTPS_PROXY\b\W\W\s\W\bfoo\b/, stdout, "HTTPS_PROXY missing or has wrong value")
48-
assert_match(/\bhttps_proxy\b\W\W\s\W\bfoo\b/, stdout, "https_proxy missing or has wrong value")
49-
assert_match(/\bNO_PROXY\b\W\W\s\W\bfoo\b/, stdout, "NO_PROXY missing or has wrong value")
50-
assert_match(/\bno_proxy\b\W\W\s\W\bfoo\b/, stdout, "no_proxy missing or has wrong value")
44+
on(master, "echo 'puts JSON.pretty_generate(ENV.to_hash)' | #{proxy_env_vars} puppetserver irb -f -rjson") do |result|
45+
assert_match(/\bHTTP_PROXY\b\W\W\s\W\bfoo\b/, result.stdout, "HTTP_PROXY missing or has wrong value")
46+
assert_match(/\bhttp_proxy\b\W\W\s\W\bfoo\b/, result.stdout, "http_proxy missing or has wrong value")
47+
assert_match(/\bHTTPS_PROXY\b\W\W\s\W\bfoo\b/, result.stdout, "HTTPS_PROXY missing or has wrong value")
48+
assert_match(/\bhttps_proxy\b\W\W\s\W\bfoo\b/, result.stdout, "https_proxy missing or has wrong value")
49+
assert_match(/\bNO_PROXY\b\W\W\s\W\bfoo\b/, result.stdout, "NO_PROXY missing or has wrong value")
50+
assert_match(/\bno_proxy\b\W\W\s\W\bfoo\b/, result.stdout, "no_proxy missing or has wrong value")
5151
end

acceptance/suites/tests/010-puppetserver-cli/subcommand/foreground.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
test_name "Puppetserver 'foreground' subcommand tests."
22

3-
if (master['platform'] =~ /el-5/)
4-
skip_test("RHEL5 is not supported by this test case. See SERVER-653")
5-
end
6-
73
cli = "puppetserver"
84
service = options['puppetservice']
95

@@ -25,7 +21,7 @@
2521

2622
step "Run #{cli} with foreground subcommand, wait for #{timout_length}"
2723
on(master, timeout_cmd, :acceptable_exit_codes => [124]) do |result|
28-
assert_no_match(/error:/i, result.stderr, "Unexpected error running puppetserver!")
24+
refute_match(/error:/i, result.stderr, "Unexpected error running puppetserver!")
2925

3026
step "Check that #{cli} ran successfully and shutdown triggered"
3127
expected_messages.each do |message, explanation|

acceptance/suites/tests/010-puppetserver-cli/subcommand/gem.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
on(master, "#{gem_install} #{gem_name} -v #{gem_version}")
4444

4545
step "Check that test gem is present."
46-
on(master, "#{gem_list}") do
47-
assert(/^#{gem_name}/.match(stdout), "#{gem_name} was not found after installation.")
46+
on(master, "#{gem_list}") do |result|
47+
assert(/^#{gem_name}/.match(result.stdout), "#{gem_name} was not found after installation.")
4848
end
4949

5050
if gem_name == 'excon'
@@ -56,8 +56,8 @@
5656
end
5757
on(master, "su #{runuser} -s /bin/bash -c "\
5858
"'/opt/puppetlabs/bin/puppetserver ruby "\
59-
"-rexcon -e \"puts Excon::VERSION\"'") do
60-
assert_equal(gems['excon'], stdout.strip,
59+
"-rexcon -e \"puts Excon::VERSION\"'") do |result|
60+
assert_equal(gems['excon'], result.stdout.strip,
6161
"Unexpected output for excon version")
6262
end
6363
end
@@ -67,8 +67,8 @@
6767
on(master, "#{gem_uninstall} #{gem_name}")
6868

6969
step "Check that test gem is no longer present."
70-
on(master, "#{gem_list}") do
71-
assert_no_match(/^#{gem_name}/, stdout, "#{gem_name} was found after uninstallation.")
70+
on(master, "#{gem_list}") do |result|
71+
refute_match(/^#{gem_name}/, result.stdout, "#{gem_name} was found after uninstallation.")
7272
end
7373
end
7474

@@ -88,14 +88,14 @@
8888
on(master, "#{cli} gem env", :acceptable_exit_codes => [0])
8989

9090
step "Verify that Java cli args passed through to gem command"
91-
on(master, "JAVA_ARGS_CLI=-Djruby.cli.version=true #{cli} gem help") do
92-
assert_match(/jruby \d\.\d\.\d.*$/, stdout,
91+
on(master, "JAVA_ARGS_CLI=-Djruby.cli.version=true #{cli} gem help") do |result|
92+
assert_match(/jruby \d\.\d\.\d.*$/, result.stdout,
9393
'jruby version not included in gem command output')
9494
end
9595

9696
step "(SERVER-1759) Verify that installing a non-existent gem produces a non-zero exit return value"
9797

9898
gem_name = 'if-this-gem-exists-then-someone-has-a-cruel-sense-of-humor'
99-
on(master, "#{cli} gem install #{gem_name}", :acceptable_exit_codes => [2]) do
100-
assert_match(/Could not find a valid gem/, stderr)
99+
on(master, "#{cli} gem install #{gem_name}", :acceptable_exit_codes => [2]) do |result|
100+
assert_match(/Could not find a valid gem/, result.stderr)
101101
end

acceptance/suites/tests/010-puppetserver-cli/subcommand/irb.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,28 @@
1010

1111
step "Check that GEM_HOME is managed"
1212
cmd = "echo 'puts ENV.to_hash.to_yaml' | GEM_HOME=UHOH #{cli} irb -ryaml -f"
13-
on(master, cmd) do
14-
assert_match(/GEM_HOME/, stdout)
15-
assert_no_match(/UHOH/, stdout)
13+
on(master, cmd) do |result|
14+
assert_match(/GEM_HOME/, result.stdout)
15+
refute_match(/UHOH/, result.stdout)
1616
end
1717

1818
step "Check that FOO_DEBUG is filtered"
1919
cmd = "echo 'puts ENV[%{FOO_DEBUG}] || %{OK}' | FOO_DEBUG=BAD #{cli} irb -f"
20-
on(master, cmd) do
21-
assert_match(/^OK$/, stdout)
22-
assert_no_match(/^BAD$/, stdout, "FOO_DEBUG is not being filtered out")
20+
on(master, cmd) do |result|
21+
assert_match(/^OK$/, result.stdout)
22+
refute_match(/^BAD$/, result.stdout, "FOO_DEBUG is not being filtered out")
2323
end
2424

2525
step "Check that puppet is loadable"
2626
cmd = "echo 'puts %{GOOD: } + Puppet.version' | #{cli} irb -rpuppet -f"
27-
on(master, cmd) do
28-
assert_match(/GOOD:/, stdout)
29-
assert_no_match(/error/i, stdout)
27+
on(master, cmd) do |result|
28+
assert_match(/GOOD:/, result.stdout)
29+
refute_match(/error/i, result.stdout)
3030
end
3131

3232
step "Verify that Java cli args passed through to irb command"
33-
on(master, "echo '' | JAVA_ARGS_CLI=-Djruby.cli.version=true #{cli} irb -f") do
34-
assert_match(/jruby \d\.\d\.\d.*$/, stdout,
33+
on(master, "echo '' | JAVA_ARGS_CLI=-Djruby.cli.version=true #{cli} irb -f") do |result|
34+
assert_match(/jruby \d\.\d\.\d.*$/, result.stdout,
3535
'jruby version not included in irb command output')
3636
end
3737

acceptance/suites/tests/010-puppetserver-cli/subcommand/ruby.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,27 @@
1010

1111
step "Check that GEM_HOME is managed"
1212
cmd = "GEM_HOME=UHOH #{cli} ruby -ryaml -e 'puts ENV.to_hash.to_yaml'"
13-
on(master, cmd) do
14-
assert_match(/GEM_HOME/, stdout)
15-
assert_no_match(/UHOH/, stdout)
13+
on(master, cmd) do |result|
14+
assert_match(/GEM_HOME/, result.stdout)
15+
refute_match(/UHOH/, result.stdout)
1616
end
1717

1818
step "Check that FOO_DEBUG is filtered out"
19-
on(master, "FOO_DEBUG=BAD #{cli} ruby -e 'puts ENV[%{FOO_DEBUG}] || %{OK}'") do
20-
assert_match(/^OK$/, stdout)
21-
assert_no_match(/BAD/, stdout, "FOO_DEBUG is not being filtered out")
19+
on(master, "FOO_DEBUG=BAD #{cli} ruby -e 'puts ENV[%{FOO_DEBUG}] || %{OK}'") do |result|
20+
assert_match(/^OK$/, result.stdout)
21+
refute_match(/BAD/, result.stdout, "FOO_DEBUG is not being filtered out")
2222
end
2323

2424
step "Check that puppet is loadable"
2525
cmd = "#{cli} ruby -rpuppet -e 'puts %{GOOD: } + Puppet.version'"
26-
on(master, cmd) do
27-
assert_match(/GOOD:/, stdout)
28-
assert_no_match(/error/i, stdout)
26+
on(master, cmd) do |result|
27+
assert_match(/GOOD:/, result.stdout)
28+
refute_match(/error/i, result.stdout)
2929
end
3030

3131
step "Verify that Java cli args passed through to ruby command"
32-
on(master, "JAVA_ARGS_CLI=-Djruby.cli.version=true #{cli} ruby -e ''") do
33-
assert_match(/jruby \d\.\d\.\d.*$/, stdout,
32+
on(master, "JAVA_ARGS_CLI=-Djruby.cli.version=true #{cli} ruby -e ''") do |result|
33+
assert_match(/jruby \d\.\d\.\d.*$/, result.stdout,
3434
'jruby version not included in ruby command output')
3535
end
3636

0 commit comments

Comments
 (0)