Sha256: 594916aca303624da8e17b58c061f3c26f613a33b2a7b36e1632f6e77af5fa44

Contents?: true

Size: 1.56 KB

Versions: 192

Compression:

Stored size: 1.56 KB

Contents

require 'spec_helper'
require 'puppet_spec/compiler'
require 'matchers/resource'
require 'puppet_spec/files'

describe 'the binary_file function' do
  include PuppetSpec::Compiler
  include Matchers::Resource
  include PuppetSpec::Files

  def with_file_content(content)
    path = tmpfile('find-file-function')
    file = File.new(path, 'wb')
    file.sync = true
    file.print content
    yield path
  end

  it 'reads an existing absolute file' do
    with_file_content('one') do |one|
      # Note that Binary to String produced Base64 encoded version of 'one' which is 'b23l'
      expect(compile_to_catalog("notify { String(binary_file('#{one}')):}")).to have_resource("Notify[b25l]")
    end
  end

  it 'errors on non existing files' do
    expect do
      with_file_content('one') do |one|
        compile_to_catalog("notify { binary_file('#{one}/nope'):}")
      end
    end.to raise_error(/The given file '.+\/nope' does not exist/)
  end

  it 'reads an existing file in a module' do
    with_file_content('binary_data') do |name|
      mod = mock 'module'
      mod.stubs(:file).with('myfile').returns(name)
      Puppet[:code] = "notify { String(binary_file('mymod/myfile')):}"
      node = Puppet::Node.new('localhost')
      compiler = Puppet::Parser::Compiler.new(node)
      compiler.environment.stubs(:module).with('mymod').returns(mod)
      # Note that the Binary to string produces Base64 encoded version of 'binary_data' which is 'YmluYXJ5X2RhdGE='
      expect(compiler.compile().filter { |r| r.virtual? }).to have_resource("Notify[YmluYXJ5X2RhdGE=]")
    end
  end
end

Version data entries

192 entries across 192 versions & 1 rubygems

Version Path
puppet-6.4.0 spec/unit/functions/binary_file_spec.rb
puppet-6.4.0-x86-mingw32 spec/unit/functions/binary_file_spec.rb
puppet-6.4.0-x64-mingw32 spec/unit/functions/binary_file_spec.rb
puppet-6.4.0-universal-darwin spec/unit/functions/binary_file_spec.rb
puppet-6.0.7 spec/unit/functions/binary_file_spec.rb
puppet-6.0.7-x86-mingw32 spec/unit/functions/binary_file_spec.rb
puppet-6.0.7-x64-mingw32 spec/unit/functions/binary_file_spec.rb
puppet-6.0.7-universal-darwin spec/unit/functions/binary_file_spec.rb
puppet-5.5.12 spec/unit/functions/binary_file_spec.rb
puppet-5.5.12-x86-mingw32 spec/unit/functions/binary_file_spec.rb
puppet-5.5.12-x64-mingw32 spec/unit/functions/binary_file_spec.rb
puppet-5.5.12-universal-darwin spec/unit/functions/binary_file_spec.rb
puppet-6.3.0 spec/unit/functions/binary_file_spec.rb
puppet-6.3.0-x86-mingw32 spec/unit/functions/binary_file_spec.rb
puppet-6.3.0-x64-mingw32 spec/unit/functions/binary_file_spec.rb
puppet-6.3.0-universal-darwin spec/unit/functions/binary_file_spec.rb
puppet-6.2.0 spec/unit/functions/binary_file_spec.rb
puppet-6.2.0-x86-mingw32 spec/unit/functions/binary_file_spec.rb
puppet-6.2.0-x64-mingw32 spec/unit/functions/binary_file_spec.rb
puppet-6.2.0-universal-darwin spec/unit/functions/binary_file_spec.rb