File: checksummer_spec.rb

package info (click to toggle)
puppet 5.5.22-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 21,316 kB
  • sloc: ruby: 254,925; sh: 1,608; xml: 219; makefile: 153; sql: 103
file content (115 lines) | stat: -rw-r--r-- 3,811 bytes parent folder | download | duplicates (9)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
require 'spec_helper'
require 'puppet/module_tool/applications'
require 'puppet_spec/files'
require 'pathname'

describe Puppet::ModuleTool::Applications::Checksummer do
  let(:tmpdir) do
    Pathname.new(PuppetSpec::Files.tmpdir('checksummer'))
  end

  let(:checksums) { Puppet::ModuleTool::Checksums.new(tmpdir).data }

  subject do
    described_class.run(tmpdir)
  end

  before do
    File.open(tmpdir + 'README', 'w') { |f| f.puts "This is a README!" }
    File.open(tmpdir + 'CHANGES', 'w') { |f| f.puts "This is a changelog!" }
    File.open(tmpdir + 'DELETEME', 'w') { |f| f.puts "I've got a really good feeling about this!" }
    Dir.mkdir(tmpdir + 'pkg')
    File.open(tmpdir + 'pkg' + 'build-artifact', 'w') { |f| f.puts "I'm unimportant!" }
    File.open(tmpdir + 'metadata.json', 'w') { |f| f.puts '{"name": "package-name", "version": "1.0.0"}' }
    File.open(tmpdir + 'checksums.json', 'w') { |f| f.puts '{}' }
  end

  context 'with checksums.json' do
    before do
      File.open(tmpdir + 'checksums.json', 'w') { |f| f.puts checksums.to_json }
      File.open(tmpdir + 'CHANGES', 'w') { |f| f.puts "This is a changed log!" }
      File.open(tmpdir + 'pkg' + 'build-artifact', 'w') { |f| f.puts "I'm still unimportant!" }
      (tmpdir + 'DELETEME').unlink
    end

    it 'reports changed files' do
      expect(subject).to include 'CHANGES'
    end

    it 'reports removed files' do
      expect(subject).to include 'DELETEME'
    end

    it 'does not report unchanged files' do
      expect(subject).to_not include 'README'
    end

    it 'does not report build artifacts' do
      expect(subject).to_not include 'pkg/build-artifact'
    end

    it 'does not report checksums.json' do
      expect(subject).to_not include 'checksums.json'
    end
  end

  context 'without checksums.json' do
    context 'but with metadata.json containing checksums' do
      before do
        (tmpdir + 'checksums.json').unlink
        File.open(tmpdir + 'metadata.json', 'w') { |f| f.puts "{\"checksums\":#{checksums.to_json}}" }
        File.open(tmpdir + 'CHANGES', 'w') { |f| f.puts "This is a changed log!" }
        File.open(tmpdir + 'pkg' + 'build-artifact', 'w') { |f| f.puts "I'm still unimportant!" }
        (tmpdir + 'DELETEME').unlink
      end

      it 'reports changed files' do
        expect(subject).to include 'CHANGES'
      end

      it 'reports removed files' do
        expect(subject).to include 'DELETEME'
      end

      it 'does not report unchanged files' do
        expect(subject).to_not include 'README'
      end

      it 'does not report build artifacts' do
        expect(subject).to_not include 'pkg/build-artifact'
      end

      it 'does not report checksums.json' do
        expect(subject).to_not include 'checksums.json'
      end
    end

    context 'and with metadata.json that does not contain checksums' do
      before do
        (tmpdir + 'checksums.json').unlink
        File.open(tmpdir + 'CHANGES', 'w') { |f| f.puts "This is a changed log!" }
        File.open(tmpdir + 'pkg' + 'build-artifact', 'w') { |f| f.puts "I'm still unimportant!" }
        (tmpdir + 'DELETEME').unlink
      end

      it 'fails' do
        expect { subject }.to raise_error(ArgumentError, 'No file containing checksums found.')
      end
    end

    context 'and without metadata.json' do
      before do
        (tmpdir + 'checksums.json').unlink
        (tmpdir + 'metadata.json').unlink

        File.open(tmpdir + 'CHANGES', 'w') { |f| f.puts "This is a changed log!" }
        File.open(tmpdir + 'pkg' + 'build-artifact', 'w') { |f| f.puts "I'm still unimportant!" }
        (tmpdir + 'DELETEME').unlink
      end

      it 'fails' do
        expect { subject }.to raise_error(ArgumentError, 'No file containing checksums found.')
      end
    end
  end
end