Sha256: 5a4bf3c070e7417b0619f9b943d0104588a47a036247835c6fb5c7408c91c0ab

Contents?: true

Size: 1.57 KB

Versions: 3

Compression:

Stored size: 1.57 KB

Contents

require 'spec_helper'

describe Chef::Sugar::Init do
  it_behaves_like 'a chef sugar'

  before(:each) do
    allow(IO).to receive(:read)
      .with("/proc/1/comm")
      .and_return("init")
    allow(File).to receive(:executable?)
      .with("/sbin/initctl")
      .and_return(false)
    allow(File).to receive(:executable?)
      .with("/sbin/runit-init")
      .and_return(false)
  end

  describe '#systemd?' do
    it 'is true when /proc/1/comm is systemd' do
      allow(IO).to receive(:read)
        .with("/proc/1/comm")
        .and_return("systemd")

      node = {}
      expect(described_class.systemd?(node)).to be true 
    end

    it 'is false when /proc/1/comm is not systemd' do
      node = {}
      expect(described_class.systemd?(node)).to be false
    end
  end

  describe '#upstart?' do
    it 'is true when /sbin/initctl is executable' do
      allow(File).to receive(:executable?)
        .with("/sbin/initctl")
        .and_return(true)

      node = {}
      expect(described_class.upstart?(node)).to be true
    end

    it 'is false when /sbin/initctl is not executable' do
      node = {}
      expect(described_class.upstart?(node)).to be false
    end
  end

  describe '#runit?' do
    it 'is true when /sbin/runit-init is executable' do
      allow(File).to receive(:executable?)
        .with("/sbin/runit-init")
        .and_return(true)

      node = {}
      expect(described_class.runit?(node)).to be true
    end

    it 'is false when /sbin/runit-init is not executable' do
      node = {}
      expect(described_class.runit?(node)).to be false
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
chef-sugar-3.4.0 spec/unit/chef/sugar/init_spec.rb
chef-sugar-3.3.0 spec/unit/chef/sugar/init_spec.rb
chef-sugar-3.2.0 spec/unit/chef/sugar/init_spec.rb