Sha256: 2131d9675a0adb5bdb1c9ef56b70b0a364e20d50298de5a1a9eb487ce4d54f91

Contents?: true

Size: 1.18 KB

Versions: 57

Compression:

Stored size: 1.18 KB

Contents

#! /usr/bin/env ruby
require 'spec_helper'

require 'puppet/util/json_lockfile'

describe Puppet::Util::JsonLockfile do
  require 'puppet_spec/files'
  include PuppetSpec::Files

  before(:each) do
    @lockfile = tmpfile("lock")
    @lock = Puppet::Util::JsonLockfile.new(@lockfile)
  end

  describe "#lock" do
    it "should create a lock file containing a json hash" do
      data = { "foo" => "foofoo", "bar" => "barbar" }
      @lock.lock(data)

      PSON.parse(File.read(@lockfile)).should == data
    end
  end

  describe "reading lock data" do
    it "returns deserialized JSON from the lockfile" do
      data = { "foo" => "foofoo", "bar" => "barbar" }
      @lock.lock(data)
      expect(@lock.lock_data).to eq data
    end

    it "returns nil if the file read returned nil" do
      @lock.lock
      File.stubs(:read).returns nil
      expect(@lock.lock_data).to be_nil
    end

    it "returns nil if the file was empty" do
      @lock.lock
      File.stubs(:read).returns ''
      expect(@lock.lock_data).to be_nil
    end

    it "returns nil if the file was not in PSON" do
      @lock.lock
      File.stubs(:read).returns ']['
      expect(@lock.lock_data).to be_nil
    end

  end
end

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
puppet-3.8.7 spec/unit/util/json_lockfile_spec.rb
puppet-3.8.7-x86-mingw32 spec/unit/util/json_lockfile_spec.rb
puppet-3.8.7-x64-mingw32 spec/unit/util/json_lockfile_spec.rb
puppet-3.8.6 spec/unit/util/json_lockfile_spec.rb
puppet-3.8.6-x86-mingw32 spec/unit/util/json_lockfile_spec.rb
puppet-3.8.6-x64-mingw32 spec/unit/util/json_lockfile_spec.rb
puppet-3.8.5 spec/unit/util/json_lockfile_spec.rb
puppet-3.8.5-x86-mingw32 spec/unit/util/json_lockfile_spec.rb
puppet-3.8.5-x64-mingw32 spec/unit/util/json_lockfile_spec.rb
puppet-3.8.4 spec/unit/util/json_lockfile_spec.rb
puppet-3.8.4-x86-mingw32 spec/unit/util/json_lockfile_spec.rb
puppet-3.8.4-x64-mingw32 spec/unit/util/json_lockfile_spec.rb
puppet-3.8.3 spec/unit/util/json_lockfile_spec.rb
puppet-3.8.3-x86-mingw32 spec/unit/util/json_lockfile_spec.rb
puppet-3.8.3-x64-mingw32 spec/unit/util/json_lockfile_spec.rb
puppet-3.8.2 spec/unit/util/json_lockfile_spec.rb
puppet-3.8.2-x86-mingw32 spec/unit/util/json_lockfile_spec.rb
puppet-3.8.2-x64-mingw32 spec/unit/util/json_lockfile_spec.rb
puppet-3.8.1 spec/unit/util/json_lockfile_spec.rb
puppet-3.8.1-x86-mingw32 spec/unit/util/json_lockfile_spec.rb