Sha256: c1ec3c724d5b6ac5b3212b2aea15a8b8c906d99c08d7321721316bcdacaef8f6

Contents?: true

Size: 1.72 KB

Versions: 39

Compression:

Stored size: 1.72 KB

Contents

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

require 'puppet/reports'
require 'time'
require 'pathname'
require 'tempfile'
require 'fileutils'

processor = Puppet::Reports.report(:store)

describe processor do
  describe "#process" do
    include PuppetSpec::Files
    before :each do
      Puppet[:reportdir] = File.join(tmpdir('reports'), 'reports')
      @report = YAML.load_file(File.join(PuppetSpec::FIXTURE_DIR, 'yaml/report2.6.x.yaml')).extend processor
    end

    it "should create a report directory for the client if one doesn't exist" do
      @report.process

      File.should be_directory(File.join(Puppet[:reportdir], @report.host))
    end

    it "should write the report to the file in YAML" do
      Time.stubs(:now).returns(Time.parse("2011-01-06 12:00:00 UTC"))
      @report.process

      File.read(File.join(Puppet[:reportdir], @report.host, "201101061200.yaml")).should == @report.to_yaml
    end

    it "rejects invalid hostnames" do
      @report.host = ".."
      Puppet::FileSystem.expects(:exist?).never
      expect { @report.process }.to raise_error(ArgumentError, /Invalid node/)
    end
  end

  describe "::destroy" do
    it "rejects invalid hostnames" do
      Puppet::FileSystem.expects(:unlink).never
      expect { processor.destroy("..") }.to raise_error(ArgumentError, /Invalid node/)
    end
  end

  describe "::validate_host" do
    ['..', 'hello/', '/hello', 'he/llo', 'hello/..', '.'].each do |node|
      it "rejects #{node.inspect}" do
        expect { processor.validate_host(node) }.to raise_error(ArgumentError, /Invalid node/)
      end
    end

    ['.hello', 'hello.', '..hi', 'hi..'].each do |node|
      it "accepts #{node.inspect}" do
        processor.validate_host(node)
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

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