summaryrefslogtreecommitdiff
path: root/tests/helpers/os_helper.rb
diff options
context:
space:
mode:
authorMicah Anderson <micah@leap.se>2014-11-11 18:43:31 -0500
committerMicah Anderson <micah@leap.se>2014-11-11 18:43:31 -0500
commit54849ae1d7407b2a6fd2f7d801e80e1632c20c70 (patch)
treeb6d83d0433edfd6ff101cac112aa4240987ae866 /tests/helpers/os_helper.rb
parent51d581583ca354232f6ccbfb771c1cad00ec2db3 (diff)
parent9299574b45de02d417e7237ba49b0222002bbc21 (diff)
Merge remote-tracking branch 'elijah/newtests' into develop
Diffstat (limited to 'tests/helpers/os_helper.rb')
-rw-r--r--tests/helpers/os_helper.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/helpers/os_helper.rb b/tests/helpers/os_helper.rb
new file mode 100644
index 00000000..529e899f
--- /dev/null
+++ b/tests/helpers/os_helper.rb
@@ -0,0 +1,34 @@
+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)/, '')
+ if process =~ /pgrep --full --list-name/
+ nil
+ else
+ {:pid => pid, :process => process}
+ end
+ }.compact
+ end
+
+ def assert_running(process)
+ assert pgrep(process).any?, "No running process for #{process}"
+ end
+
+ #
+ # runs the specified command, failing on a non-zero exit status.
+ #
+ def assert_run(command)
+ output = `#{command}`
+ if $?.exitstatus != 0
+ fail "Error running `#{command}`:\n#{output}"
+ end
+ end
+
+end \ No newline at end of file