Files
cookbook-pacemaker/spec/libraries/pacemaker/resource_spec.rb
Adam Spiers c0e3907ba0 tidy up requires
It's really ugly to have to keep repeating File.dirname(__FILE__),
so we use a temporary variable, even in the case of a single require.
This minimises long "requires" lines and "requires" statements with
needing line-breaks, and should make search-and-replace a bit easier
if we later want to migrate to __dir__ (Ruby >= 2.0) or require_relative.

  http://stackoverflow.com/questions/4333286/ruby-require-vs-require-relative-best-practice-to-workaround-running-in-both

I've deliberately rejected the pattern:

  require File.expand_path('../relative/path', __FILE__)

because it relies on inconsistent semantics and inconsistent
documentation in File.expand_path:

  http://stackoverflow.com/questions/4333286/ruby-require-vs-require-relative-best-practice-to-workaround-running-in-both#comment34147297_4333552
2014-03-25 18:37:50 +00:00

50 lines
1.6 KiB
Ruby

require 'spec_helper'
this_dir = File.dirname(__FILE__)
require File.expand_path('../../../libraries/pacemaker/resource', this_dir)
require File.expand_path('../../fixtures/keystone_primitive', this_dir)
describe Pacemaker::Resource do
describe "#running?" do
let(:rsc) { Pacemaker::Resource.new('keystone') }
before(:each) do
@cmd = double(Mixlib::ShellOut)
expect(rsc).to receive(:shell_out!) \
.with(*%w(crm resource status keystone)) \
.and_return(@cmd)
end
it "should return true" do
expect(@cmd).to receive(:stdout).at_least(:once) \
.and_return("resource #{rsc.name} is running on: d52-54-00-e5-6b-a0")
expect(rsc.running?).to be(true)
end
it "should return false" do
expect(@cmd).to receive(:stdout).at_least(:once) \
.and_return("resource #{rsc.name} is NOT running")
expect(rsc.running?).to be(false)
end
end
describe "::extract_hash" do
let(:fixture) { Chef::RSpec::Pacemaker::Config::KEYSTONE_PRIMITIVE.dup }
it "should extract a params hash from config" do
expect(fixture.class.extract_hash(fixture.definition_string, "params")).to \
eq(Hash[fixture.params])
end
it "should extract an op start hash from config" do
expect(fixture.class.extract_hash(fixture.definition_string, 'op start')).to \
eq(Hash[fixture.op]['start'])
end
it "should extract an op monitor hash from config" do
expect(fixture.class.extract_hash(fixture.definition_string, 'op monitor')).to \
eq(Hash[fixture.op]['monitor'])
end
end
end