This repository has been archived by the owner on Nov 29, 2019. It is now read-only.
forked from voxpupuli/puppet-elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
179 lines (157 loc) · 4.81 KB
/
Rakefile
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
require 'digest/sha1'
require 'rubygems'
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet_blacksmith/rake_tasks'
require 'net/http'
require 'nokogiri'
require 'uri'
require 'fileutils'
require 'rspec/core/rake_task'
require 'open-uri'
require 'puppet-strings'
require 'puppet-strings/tasks'
require 'yaml'
require 'json'
require_relative 'spec/spec_utilities'
# Workaround for certain rspec/beaker versions
module TempFixForRakeLastComment
def last_comment
last_description
end
end
Rake::Application.send :include, TempFixForRakeLastComment
exclude_paths = [
'pkg/**/*',
'vendor/**/*',
'spec/**/*'
]
require 'puppet-lint/tasks/puppet-lint'
require 'puppet-syntax/tasks/puppet-syntax'
PuppetSyntax.exclude_paths = exclude_paths
PuppetSyntax.future_parser = true if ENV['FUTURE_PARSER'] == 'true'
%w[
80chars
class_inherits_from_params_class
class_parameter_defaults
single_quote_string_with_variable
].each do |check|
PuppetLint.configuration.send("disable_#{check}")
end
PuppetLint.configuration.ignore_paths = exclude_paths
PuppetLint.configuration.log_format = \
'%{path}:%{line}:%{check}:%{KIND}:%{message}'
desc 'remove outdated module fixtures'
task :spec_prune do
mods = 'spec/fixtures/modules'
fixtures = YAML.load_file '.fixtures.yml'
fixtures['fixtures']['forge_modules'].each do |mod, params|
next unless params.is_a? Hash \
and params.key? 'ref' \
and File.exist? "#{mods}/#{mod}"
metadata = JSON.parse(File.read("#{mods}/#{mod}/metadata.json"))
FileUtils.rm_rf "#{mods}/#{mod}" unless metadata['version'] == params['ref']
end
end
task :spec_prep => [:spec_prune]
RSpec::Core::RakeTask.new(:spec_verbose) do |t|
t.pattern = 'spec/{classes,defines,unit,functions,templates}/**/*_spec.rb'
t.rspec_opts = [
'--format documentation',
'--require "ci/reporter/rspec"',
'--format CI::Reporter::RSpecFormatter',
'--color'
]
end
task :spec_verbose => :spec_prep
RSpec::Core::RakeTask.new(:spec_puppet) do |t|
t.pattern = 'spec/{classes,defines,functions,templates,unit/facter}/**/*_spec.rb'
t.rspec_opts = ['--color']
end
task :spec_puppet => :spec_prep
RSpec::Core::RakeTask.new(:spec_unit) do |t|
t.pattern = 'spec/unit/{type,provider}/**/*_spec.rb'
t.rspec_opts = ['--color']
end
task :spec_unit => :spec_prep
task :beaker => [:spec_prep, 'artifacts:prep']
desc 'Run all linting/unit tests.'
task :intake => %i[
syntax
lint
validate
spec_unit
spec_puppet
]
desc 'Run snapshot tests'
RSpec::Core::RakeTask.new('beaker:snapshot') do |c|
c.pattern = 'spec/acceptance/snapshot.rb'
end
task 'beaker:snapshot' => [
'artifacts:prep',
'artifacts:snapshot:deb',
'artifacts:snapshot:rpm',
:spec_prep
]
desc 'Run acceptance tests'
RSpec::Core::RakeTask.new('beaker:acceptance') do |c|
c.pattern = 'spec/acceptance/0*_spec.rb'
end
task 'beaker:acceptance' => [:spec_prep, 'artifacts:prep']
namespace :artifacts do
desc 'Fetch artifacts for tests'
task :prep do
dl_base = 'https://download.elastic.co/elasticsearch/elasticsearch'
fetch_archives(
'https://github.com/lmenezes/elasticsearch-kopf/archive/v2.1.1.zip' => \
'elasticsearch-kopf.zip',
"#{dl_base}/elasticsearch-2.3.5.deb" => 'elasticsearch-2.3.5.deb',
"#{dl_base}/elasticsearch-2.3.5.rpm" => 'elasticsearch-2.3.5.rpm'
)
end
namespace :snapshot do
dls = Nokogiri::HTML(open('https://www.elastic.co/downloads/elasticsearch'))
dls
.at_css('#preview-release-id')
.at_css('.downloads')
.xpath('li/a[contains(text(), "rpm") or contains(text(), "deb")]')
.each do |anchor|
filename = artifact(anchor.attr('href'))
link = artifact("elasticsearch-snapshot.#{anchor.text.split(' ').first.downcase}")
checksum = filename + '.sha1'
task anchor.text.split(' ').first.downcase => link
file link => filename do
unless File.exist?(link) and File.symlink?(link) \
and File.readlink(link) == filename
File.delete link if File.exist? link
File.symlink File.basename(filename), link
end
end
file filename => checksum do
get anchor.attr('href'), filename
end
task checksum do
File.delete checksum if File.exist? checksum
get "#{anchor.attr('href')}.sha1", checksum
end
end
end
desc 'Purge fetched artifacts'
task :clean do
FileUtils.rm_rf(Dir.glob('spec/fixtures/artifacts/*'))
end
end
def fetch_archives(archives)
archives.each do |url, orig_fp|
fp = "spec/fixtures/artifacts/#{orig_fp}"
if File.exist? fp
if fp.end_with? 'tar.gz' and !system("tar -tzf #{fp} &>/dev/null")
puts "Archive #{fp} corrupt, re-fetching..."
File.delete fp
else
puts "Already retrieved intact archive #{fp}..."
next
end
end
get url, fp
end
end