Sha256: 85adae677f033427d3490900f5848fc137840f4284d696b497a5a31a71f5031f

Contents?: true

Size: 1.92 KB

Versions: 44

Compression:

Stored size: 1.92 KB

Contents

require 'spec_helper'
require 'puppet_spec/files'

describe "puppet resource", unless: Puppet::Util::Platform.jruby? do
  include PuppetSpec::Files

  let(:resource) { Puppet::Application[:resource] }

  context 'when given an invalid environment' do
    before { Puppet[:environment] = 'badenv' }

    it 'falls back to the default environment' do
      Puppet[:log_level] = 'debug'

      expect {
        resource.run
      }.to exit_with(1)
       .and output(/Debug: Specified environment 'badenv' does not exist on the filesystem, defaulting to 'production'/).to_stdout
       .and output(/Error: Could not run: You must specify the type to display/).to_stderr
    end

    it 'lists resources' do
      resource.command_line.args = ['file', Puppet[:confdir]]

      expect {
        resource.run
      }.to output(/file { '#{Puppet[:confdir]}':/).to_stdout
    end

    it 'lists types from the default environment' do
      modulepath = File.join(Puppet[:codedir], 'modules', 'test', 'lib', 'puppet', 'type')
      FileUtils.mkdir_p(modulepath)
      File.write(File.join(modulepath, 'test.rb'), 'Puppet::Type.newtype(:test)')
      resource.command_line.args = ['--types']

      expect {
        resource.run
      }.to exit_with(0).and output(/test/).to_stdout
    end
  end


  context 'when handling file and tidy types' do
    let!(:dir) { dir_containing('testdir', 'testfile' => 'contents') }

    it 'does not raise when generating file resources' do
      resource.command_line.args = ['file', dir, 'ensure=directory', 'recurse=true']

      expect {
        resource.run
      }.to output(/ensure.+=> 'directory'/).to_stdout
    end

    it 'correctly cleans up a given path' do
      resource.command_line.args = ['tidy', dir, 'rmdirs=true', 'recurse=true']

      expect {
        resource.run
      }.to output(/Notice: \/File\[#{dir}\]\/ensure: removed/).to_stdout

      expect(Puppet::FileSystem.exist?(dir)).to be false
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
puppet-6.26.0 spec/integration/application/resource_spec.rb
puppet-6.26.0-x86-mingw32 spec/integration/application/resource_spec.rb
puppet-6.26.0-x64-mingw32 spec/integration/application/resource_spec.rb
puppet-6.26.0-universal-darwin spec/integration/application/resource_spec.rb
puppet-7.14.0 spec/integration/application/resource_spec.rb
puppet-7.14.0-x86-mingw32 spec/integration/application/resource_spec.rb
puppet-7.14.0-x64-mingw32 spec/integration/application/resource_spec.rb
puppet-7.14.0-universal-darwin spec/integration/application/resource_spec.rb
puppet-7.13.1 spec/integration/application/resource_spec.rb
puppet-7.13.1-x86-mingw32 spec/integration/application/resource_spec.rb
puppet-7.13.1-x64-mingw32 spec/integration/application/resource_spec.rb
puppet-7.13.1-universal-darwin spec/integration/application/resource_spec.rb
puppet-7.12.1 spec/integration/application/resource_spec.rb
puppet-7.12.1-x86-mingw32 spec/integration/application/resource_spec.rb
puppet-7.12.1-x64-mingw32 spec/integration/application/resource_spec.rb
puppet-7.12.1-universal-darwin spec/integration/application/resource_spec.rb
puppet-6.25.1 spec/integration/application/resource_spec.rb
puppet-6.25.1-x86-mingw32 spec/integration/application/resource_spec.rb
puppet-6.25.1-x64-mingw32 spec/integration/application/resource_spec.rb
puppet-6.25.1-universal-darwin spec/integration/application/resource_spec.rb