diff options
author | elijah <elijah@riseup.net> | 2016-08-29 16:35:14 -0700 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2016-09-01 10:13:31 -0700 |
commit | 07c0e60e6bdc5b8bfe1f42f76dae9f0a79e7abb0 (patch) | |
tree | 9f79f8fbb207896dcfe38f24831d9b2b857199a4 /tests/server-tests/helpers/os_helper.rb | |
parent | d5bac5850e4a895da5f9cfacb641fab15de1cf7b (diff) |
moved infrastructure tests run by `leap run` to tests/server-tests
Diffstat (limited to 'tests/server-tests/helpers/os_helper.rb')
-rw-r--r-- | tests/server-tests/helpers/os_helper.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/server-tests/helpers/os_helper.rb b/tests/server-tests/helpers/os_helper.rb new file mode 100644 index 00000000..9923d5b1 --- /dev/null +++ b/tests/server-tests/helpers/os_helper.rb @@ -0,0 +1,41 @@ +class LeapTest + + # + # works like pgrep command line + # return an array of hashes like so [{:pid => "1234", :process => "ls"}] + # + def pgrep(match) + output = `pgrep --full --list-name '#{match}'` + output.each_line.map{|line| + pid = line.split(' ')[0] + process = line.gsub(/(#{pid} |\n)/, '') + # filter out pgrep cmd itself + # on wheezy hosts, the "process" var contains the whole cmd including all parameters + # on jessie hosts, it only contains the first cmd (which is the default sheel invoked by 'sh') + if process =~ /^sh/ + nil + else + {:pid => pid, :process => process} + end + }.compact + end + + def assert_running(process, options={}) + processes = pgrep(process) + assert processes.any?, "No running process for #{process}" + if options[:single] + assert processes.length == 1, "More than one process for #{process}" + end + end + + # + # runs the specified command, failing on a non-zero exit status. + # + def assert_run(command) + output = `#{command} 2>&1` + if $?.exitstatus != 0 + fail "Error running `#{command}`:\n#{output}" + end + end + +end
\ No newline at end of file |