Sha256: bb666d99449f7d2d5aeae81ff7a3331ab04f79c7fa90ad916c4e772c932dea8a

Contents?: true

Size: 983 Bytes

Versions: 192

Compression:

Stored size: 983 Bytes

Contents

require 'spec_helper'
require 'puppet/node'
require 'puppet/indirector/node/json'

describe Puppet::Node::Json do
  describe '#save' do
    subject(:indirection) { described_class.indirection }

    let(:env) { Puppet::Node::Environment.create(:testing, []) }
    let(:node) { Puppet::Node.new('node_name', :environment => env) }
    let(:file) { File.join(Puppet[:client_datadir], "node", "node_name.json") }

    before do
      indirection.terminus_class = :json
    end

    it 'saves the instance of the node as JSON to disk' do
      indirection.save(node)
      json = Puppet::FileSystem.read(file, :encoding => 'bom|utf-8')
      content = Puppet::Util::Json.load(json)
      expect(content["name"]).to eq('node_name')
    end

    context 'when node cannot be saved' do
      it 'raises Errno::EISDIR' do
        FileUtils.mkdir_p(file)
        expect {
          indirection.save(node)
         }.to raise_error(Errno::EISDIR, /node_name.json/)
      end
    end
  end
end

Version data entries

192 entries across 192 versions & 1 rubygems

Version Path
puppet-8.3.0 spec/unit/indirector/node/json_spec.rb
puppet-8.3.0-x86-mingw32 spec/unit/indirector/node/json_spec.rb
puppet-8.3.0-x64-mingw32 spec/unit/indirector/node/json_spec.rb
puppet-8.3.0-universal-darwin spec/unit/indirector/node/json_spec.rb
puppet-8.4.0 spec/unit/indirector/node/json_spec.rb
puppet-8.4.0-x86-mingw32 spec/unit/indirector/node/json_spec.rb
puppet-8.4.0-x64-mingw32 spec/unit/indirector/node/json_spec.rb
puppet-8.4.0-universal-darwin spec/unit/indirector/node/json_spec.rb
puppet-7.28.0 spec/unit/indirector/node/json_spec.rb
puppet-7.28.0-x86-mingw32 spec/unit/indirector/node/json_spec.rb
puppet-7.28.0-x64-mingw32 spec/unit/indirector/node/json_spec.rb
puppet-7.28.0-universal-darwin spec/unit/indirector/node/json_spec.rb
puppet-8.3.1 spec/unit/indirector/node/json_spec.rb
puppet-8.3.1-x86-mingw32 spec/unit/indirector/node/json_spec.rb
puppet-8.3.1-x64-mingw32 spec/unit/indirector/node/json_spec.rb
puppet-8.3.1-universal-darwin spec/unit/indirector/node/json_spec.rb
puppet-7.27.0 spec/unit/indirector/node/json_spec.rb
puppet-7.27.0-x86-mingw32 spec/unit/indirector/node/json_spec.rb
puppet-7.27.0-x64-mingw32 spec/unit/indirector/node/json_spec.rb
puppet-7.27.0-universal-darwin spec/unit/indirector/node/json_spec.rb