File: generator_spec.rb

package info (click to toggle)
ruby-beaker-hostgenerator 1.7.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,556 kB
  • sloc: ruby: 3,059; makefile: 3
file content (154 lines) | stat: -rw-r--r-- 5,186 bytes parent folder | download | duplicates (2)
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
require 'find'

require 'spec_helper'

require 'beaker-hostgenerator'
require 'util/generator_helpers'

module BeakerHostGenerator
  describe Generator do
    let(:generator) { BeakerHostGenerator::Generator.new }

    describe 'get_host_roles' do
      it 'Expands default roles and merges in arbitrary roles' do
        {
          {
            "roles" => "aulcdfm",
            "arbitrary_roles" => [],
          } => [
            'agent',
            'ca',
            'classifier',
            'dashboard',
            'database',
            'frictionless',
            'master',
          ],
          {
            "roles" => "a",
            "arbitrary_roles" => ["meow","hello","compile_master"],
          } => [
            'agent',
            'meow',
            'hello',
            'compile_master',
          ],
          {
            "roles" => "",
            "arbitrary_roles" => ["compile_master"],
          } => [
            'compile_master'
          ],
          {
            "roles" => "",
            "arbitrary_roles" => [],
          } => [],
        }.each do |node_info, roles|
          expect( generator.get_host_roles(node_info) ).to eq( roles )
        end
      end
    end

    shared_examples "fixtures" do |fixture_hash|
      arguments = fixture_hash["arguments_string"]
      it "beaker-hostgenerator #{arguments}" do
        arguments = arguments.split
        fixture_hash['environment_variables'].each do |key, value|
          ENV[key] = value
        end

        cli = BeakerHostGenerator::CLI.new(arguments)
        if fixture_hash['expected_exception']
          # Turn fully-qualified classname string into actual Class object.
          # We have to manually descend into each Module that makes up the
          # fully-qualified path to the error class.
          qualified_classname = fixture_hash['expected_exception'].split('::')
          expected_class = qualified_classname.reduce(Object) do |accum, e|
            accum.const_get(e)
          end
          expect { cli.execute }.to raise_error(expected_class)
        else
          test_hash = YAML.load(cli.execute)
          expect(test_hash).to eq(fixture_hash['expected_hash'])
        end

        fixture_hash['environment_variables'].each_key do |key|
          ENV[key] = nil
        end
      end
    end

    context "Fixtures" do
      Find.find 'test/fixtures' do |f|
        context "#{f}" do
          if File.directory?(f)
            next
          end
          include_examples "fixtures", YAML.load_file(f)
        end
      end
    end

    context "pe_dir for versions < 2021.0" do
      let(:dev_version) { '2019.8.0-rc4-11-g123abcd' }
      let(:dev_version_no_rc) { '2019.8.0-1-g123abcd' }
      let(:pez_version) { '2019.8.0-rc4-11-g123abcd-PEZ_foo' }
      let(:release_version) { '2019.8.2' }
      let(:rc_version) { '2019.8.0-rc4' }

      it "returns ci-ready for a dev version" do
        expect(BeakerHostGenerator::Data.pe_dir(dev_version)).to match(%r{2019\.8/ci-ready})
        expect(BeakerHostGenerator::Data.pe_dir(dev_version_no_rc)).to match(%r{2019\.8/ci-ready})
      end

      it "returns archives/releases for a release version" do
        expect(BeakerHostGenerator::Data.pe_dir(release_version)).to match(%r{archives/releases/2019\.8})
      end

      it "returns archives/internal for an rc version" do
        expect(BeakerHostGenerator::Data.pe_dir(rc_version)).to match(%r{archives/internal/2019\.8})
      end

      it "returns feature/ci-ready for a PEZ version" do
        expect(BeakerHostGenerator::Data.pe_dir(pez_version)).to match(%r{2019\.8/feature/ci-ready})
      end

      it "returns nil if version is nil" do
        expect(BeakerHostGenerator::Data.pe_dir(nil)).to be_nil
      end

      it "returns nil if version is an empty string" do
        expect(BeakerHostGenerator::Data.pe_dir('')).to be_nil
      end

      it "returns an empty string if version isn't parseable" do
        expect(BeakerHostGenerator::Data.pe_dir('wtf')).to eq('')
      end
    end

    context "pe_dir for versions >= 2021.0" do
      let(:dev_version) { '2021.0.0-rc4-11-g123abcd' }
      let(:dev_version_no_rc) { '2021.0.0-1-g123abcd' }
      let(:pez_version) { '2021.0.0-rc4-11-g123abcd-pez_foo' } # Some jobs use "PEZ" and some "pez"
      let(:release_version) { '2021.0.0' }
      let(:rc_version) { '2021.0.0-rc4' }

      it "returns main/ci-ready for a dev version" do
        expect(BeakerHostGenerator::Data.pe_dir(dev_version)).to match(%r{main/ci-ready})
        expect(BeakerHostGenerator::Data.pe_dir(dev_version_no_rc)).to match(%r{main/ci-ready})
      end

      it "returns archives/releases/<version> for a release version" do
        expect(BeakerHostGenerator::Data.pe_dir(release_version)).to match(%r{archives/releases/2021\.0\.0})
      end

      it "returns archives/internal/main for an rc version" do
        expect(BeakerHostGenerator::Data.pe_dir(rc_version)).to match(%r{archives/internal/2021.0})
      end

      it "returns main/feature/ci-ready for a PEZ version" do
        expect(BeakerHostGenerator::Data.pe_dir(pez_version)).to match('main/feature')
      end
    end
  end
end