diff options
author | Philip Hands <phil@hands.com> | 2016-03-14 15:36:16 +0100 |
---|---|---|
committer | Holger Levsen <holger@layer-acht.org> | 2016-04-28 21:52:10 +0200 |
commit | da080c472fc415b0ce918f4dd4a1ab143bb1bca4 (patch) | |
tree | bf63179f32f0eda0c2d5796e3e31c18c3c1185cf /features/support/helpers/chatbot_helper.rb | |
parent | 26a9e8ec2bcae03db4d663d87b44d8708d64fdc2 (diff) | |
download | jenkins.debian.net-da080c472fc415b0ce918f4dd4a1ab143bb1bca4.tar.xz |
rough attempt to grab the good cucumber bits from recent tails
Diffstat (limited to 'features/support/helpers/chatbot_helper.rb')
-rw-r--r-- | features/support/helpers/chatbot_helper.rb | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/features/support/helpers/chatbot_helper.rb b/features/support/helpers/chatbot_helper.rb new file mode 100644 index 00000000..23ce3e1a --- /dev/null +++ b/features/support/helpers/chatbot_helper.rb @@ -0,0 +1,59 @@ +require 'tempfile' + +class ChatBot + + def initialize(account, password, otr_key, opts = Hash.new) + @account = account + @password = password + @otr_key = otr_key + @opts = opts + @pid = nil + @otr_key_file = nil + end + + def start + @otr_key_file = Tempfile.new("otr_key.", $config["TMPDIR"]) + @otr_key_file << @otr_key + @otr_key_file.close + + cmd_helper(['/usr/bin/convertkey', @otr_key_file.path]) + cmd_helper(["mv", "#{@otr_key_file.path}3", @otr_key_file.path]) + + cmd = [ + "#{GIT_DIR}/features/scripts/otr-bot.py", + @account, + @password, + @otr_key_file.path + ] + cmd += ["--connect-server", @opts["connect_server"]] if @opts["connect_server"] + cmd += ["--auto-join"] + @opts["auto_join"] if @opts["auto_join"] + cmd += ["--log-file", DEBUG_LOG_PSEUDO_FIFO] + + job = IO.popen(cmd) + @pid = job.pid + end + + def stop + @otr_key_file.delete + begin + Process.kill("TERM", @pid) + rescue + # noop + end + end + + def active? + begin + ret = Process.kill(0, @pid) + rescue Errno::ESRCH => e + if e.message == "No such process" + return false + else + raise e + end + end + assert_equal(1, ret, "This shouldn't happen") + return true + end + +end |