Sha256: 3c429f99450ae2bed7fc6c025225689e3cf182b6ad43690cc42bd2087927530d

Contents?: true

Size: 1.26 KB

Versions: 10

Compression:

Stored size: 1.26 KB

Contents

require 'spec_helper'

describe LitmusPaper::Metric::Script do
  describe "#result" do
    it "is 1 when the script outputs 1" do
      check = LitmusPaper::Metric::Script.new("echo 1", 1)
      check.current_health.should == 1
    end

    it "is zero when the script exits 1" do
      check = LitmusPaper::Metric::Script.new("false", 1)
      check.current_health.should == 0
    end

    it "is zero when the script exceeds the timeout" do
      check = LitmusPaper::Metric::Script.new("sleep 10", 1, :timeout => 1)
      check.current_health.should == 0
    end

    it "kills the child process when script check exceeds timeout" do
      check = LitmusPaper::Metric::Script.new("sleep 50", 1, :timeout => 1)
      check.current_health.should == 0
      expect { Process.kill(0, check.script_pid) }.to raise_error(Errno::ESRCH)
    end

    it "can handle pipes" do
      check = LitmusPaper::Metric::Script.new("echo 'a' | tr a 1", 1)
      check.current_health.should == 1

      check = LitmusPaper::Metric::Script.new("echo 'a' | tr a 0", 0)
      check.current_health.should == 0
    end
  end

  describe "to_s" do
    it "returns the command" do
      check = LitmusPaper::Metric::Script.new("sleep 10", 1)
      check.to_s.should == "Metric::Script(sleep 10, 1)"
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
litmus_paper-0.9.6 spec/litmus_paper/metric/script_spec.rb
litmus_paper-0.9.5 spec/litmus_paper/metric/script_spec.rb
litmus_paper-0.9.4 spec/litmus_paper/metric/script_spec.rb
litmus_paper-0.9.3 spec/litmus_paper/metric/script_spec.rb
litmus_paper-0.9.2 spec/litmus_paper/metric/script_spec.rb
litmus_paper-0.9.1 spec/litmus_paper/metric/script_spec.rb
litmus_paper-0.9.0 spec/litmus_paper/metric/script_spec.rb
litmus_paper-0.8.9 spec/litmus_paper/metric/script_spec.rb
litmus_paper-0.8.8 spec/litmus_paper/metric/script_spec.rb
litmus_paper-0.8.7 spec/litmus_paper/metric/script_spec.rb