File: run_command_test.rb

package info (click to toggle)
ruby-train 3.13.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,208 kB
  • sloc: ruby: 10,002; sh: 17; makefile: 8
file content (46 lines) | stat: -rw-r--r-- 1,364 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
describe "run_command" do
  let(:backend) { get_backend.call }

  it "can echo commands" do
    res = backend.run_command("echo hello world")
    _(res.stdout).must_equal("hello world\n")
    _(res.stderr).must_equal("")
    _(res.exit_status).must_equal(0)
  end

  it "can run frozen commands" do
    res = backend.run_command("echo hello world".freeze)
    _(res.stdout).must_equal("hello world\n")
    _(res.stderr).must_equal("")
    _(res.exit_status).must_equal(0)
  end

  it "can echo commands to stderr" do
    # TODO: Specinfra often fails on this test.
    # Fix and re-enable it.
    res = backend.run_command(">&2 echo hello world")
    _(res.stdout).must_equal("")
    _(res.stderr).must_equal("hello world\n")
    _(res.exit_status).must_equal(0)
  end

  it "prints a correct exit status" do
    res = backend.run_command("exit 123")
    _(res.stdout).must_equal("")
    _(res.stderr).must_equal("")
    _(res.exit_status).must_equal(123)
  end

  it "completes a command with ample timeout" do
    res = backend.run_command("echo hello world", timeout: 5)
    _(res.stdout).must_equal("hello world\n")
    _(res.stderr).must_equal("")
    _(res.exit_status).must_equal(0)
  end

  it "raises CommandTimeoutReached on timeout" do
    assert_raises Train::CommandTimeoutReached do
      backend.run_command("sleep 2", timeout: 1)
    end
  end
end