-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathRakefile
94 lines (77 loc) · 2.7 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
# A Rakefile defines tasks to help maintain your project.
# Rake provides several task templates that are useful.
# This task template will make a task named 'test', and run
# the tests that it finds.
require "rake/testtask"
ENV["VAULT_DEV_ROOT_TOKEN_ID"] ||= "s.kr5NQVFlUEi7XV64W3SVhqoE"
ENV["VAULT_RELEASE"] ||= "1.2.2"
ENV["VAULT_API_ADDR"] ||= "http://127.0.0.1"
ENV["VAULT_LOG_LEVEL"] ||= "debug" # default "info" is noisy
namespace(:test) do
#------------------------------------------------------------------#
# Code Style Tasks
#------------------------------------------------------------------#
require "chefstyle"
require "rubocop/rake_task"
RuboCop::RakeTask.new(:lint)
#------------------------------------------------------------------#
# Test Runner Tasks
#------------------------------------------------------------------#
Rake::TestTask.new(:unit) do |t|
t.libs.push "lib"
t.test_files = FileList["test/unit/*_test.rb"]
end
desc "Run integration tests by starting a local Vault server"
task integration: %i{int:install_vault int:start_vault int:seed_vault int:actual_tests int:stop_vault }
def windows?
RUBY_PLATFORM =~ /cygwin|mswin|mingw/
end
def mac_os?
RUBY_PLATFORM =~ /darwin/
end
namespace(:int) do
Rake::TestTask.new(:actual_tests) do |t|
t.libs.push "lib"
t.test_files = FileList["test/integration/*_test.rb"]
end
task(:install_vault) do
if windows?
sh "test/integration/support/install-vault.windows.ps1"
elsif mac_os?
sh "test/integration/support/install-vault.macos.sh"
else
sh "test/integration/support/install-vault.linux.sh"
end
end
task(:start_vault) do
if windows?
sh %q{Start-Process -File-Path vault.exe -ArgumentList "server -dev"}
else
pid = spawn(ENV, "test/integration/support/vault server -dev &")
Process.detach(pid)
end
puts "Waiting 3 sec for vault to warm up..."
sleep(3)
end
task(:seed_vault) do
Dir.chdir("test/fixtures/vault") do
Dir["**/*.json"].each do |json_pathname|
path_parts = json_pathname.split(%r{[/\\]})
path_prefix = "secret/inspec" # TODO - custom path prefix support
profile_name = path_parts.last.sub(/\.json$/, "")
# Shell out to do a file load of secrets
sh "../../integration/support/vault kv put #{path_prefix}/#{profile_name} @#{json_pathname}"
end
end
end
task(:stop_vault) do
if windows?
sh "Stop-Process -Name vault "
else
sh "pkill vault"
end
end
end
end
task test: %i{test:unit}
task default: %i{test:lint test:unit}