-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathall_roles.rb
More file actions
85 lines (72 loc) · 3.09 KB
/
Copy pathall_roles.rb
File metadata and controls
85 lines (72 loc) · 3.09 KB
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
# frozen_string_literal: true
# Copyright (c) 2018-2019 The Regents of the University of Michigan.
# All Rights Reserved. Licensed according to the terms of the Revised
# BSD License. See LICENSE.txt for details.
require "spec_helper"
def puppet_role_name_from(path)
path.strip.gsub("/", "::").gsub(%r{^manifests}, "nebula").gsub(%r{\.pp}, "")
end
module RSpec::Puppet
module ManifestMatchers
class CompileAlongWithAllRoles < Compile
def initialize(hiera_fixture)
super()
@hiera_fixture = hiera_fixture
end
def description
"compile using #{@hiera_fixture} hieradata"
end
def failure_message
"You probably need to add a hiera_config to spec/classes/all_roles.rb:\n #{super}"
end
def failure_message_when_negated
"You probably need to add a hiera_config to spec/classes/all_roles.rb:\n #{super}"
end
end
def compile_along_with_all_roles(hiera_fixture)
RSpec::Puppet::ManifestMatchers::CompileAlongWithAllRoles.new(hiera_fixture)
end
end
end
# Tests are run in several roughly equal slices from other *_spec.rb files. This
# results in spec files that each have roughly similar run time, and thus the
# tests run much faster when parallelized.
def test_roles(slice_number = 1, slice_count = 1)
slice_index = slice_number - 1 # number is 1..n, index is 0..n; using "number" for input to be less confusing
roles = `find manifests/role -name '*.pp'`.each_line.to_a
slice = roles.each_slice(roles.size / slice_count + 1).to_a[slice_index]
slice.each do |file_path|
role_name = puppet_role_name_from(file_path)
describe role_name do
on_supported_os(supported_os: Nebula.supported_os).each do |os, os_facts|
context "on #{os}" do
let(:facts) { os_facts }
let(:hiera_config) { "spec/fixtures/hiera/#{hiera_fixture}_config.yaml" }
let(:hiera_fixture) do
[
# Each item is a pair: [<role prefix or full name>,
# <hiera fixture name>]
# The first pair that matches will be chosen.
%w[nebula::role::webhost::htvm hathitrust],
%w[nebula::role::hathitrust hathitrust],
%w[nebula::role::deb_server deb_server],
%w[nebula::role::kubernetes kubernetes/first_cluster],
%w[nebula::role::search::solr kubernetes/first_cluster],
%w[nebula::role::log_host log_host],
%w[nebula::role::webhost::www_lib_vm www_lib],
%w[nebula::role::webhost::fulcrum_www_and_app fulcrum],
%w[nebula::role::fulcrum::standalone fulcrum],
%w[nebula default]
].find { |role_base, _| role_name.start_with? role_base }[1]
end
before(:each) do
# Everything that runs puppetdb_query should be able to deal
# with empty results.
Puppet::Parser::Functions.newfunction(:puppetdb_query, type: :rvalue) { |_| [] }
end
it { is_expected.to compile_along_with_all_roles(hiera_fixture) }
end
end
end
end
end