File: store_spec.rb

package info (click to toggle)
puppet-agent 7.23.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 19,092 kB
  • sloc: ruby: 245,074; sh: 456; makefile: 38; xml: 33
file content (67 lines) | stat: -rw-r--r-- 1,977 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
require 'spec_helper'

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

describe Puppet::Reports.report(:store) do
  describe "#process" do
    include PuppetSpec::Files

    before :each do
      Puppet[:reportdir] = File.join(tmpdir('reports'), 'reports')
    end

    let(:report) do
      if RUBY_VERSION < "3.0"
        report = YAML.load_file(File.join(PuppetSpec::FIXTURE_DIR, 'yaml/report2.6.x.yaml'))
      else
        report = YAML.unsafe_load_file(File.join(PuppetSpec::FIXTURE_DIR, 'yaml/report2.6.x.yaml'))
      end
      report.extend(described_class)
      report
    end

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

      expect(File).to be_directory(File.join(Puppet[:reportdir], report.host))
    end

    it "should write the report to the file in YAML" do
      allow(Time).to receive(:now).and_return(Time.utc(2011,01,06,12,00,00))
      report.process

      expect(File.read(File.join(Puppet[:reportdir], report.host, "201101061200.yaml"))).to eq(report.to_yaml)
    end

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

  describe "::destroy" do
    it "rejects invalid hostnames" do
      expect(Puppet::FileSystem).not_to receive(:unlink)
      expect { described_class.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 { described_class.validate_host(node) }.to raise_error(ArgumentError, /Invalid node/)
      end
    end

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