rspec-terraspace 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +4 -0
- data/lib/rspec/terraspace.rb +6 -1
- data/lib/rspec/terraspace/project.rb +78 -11
- data/lib/rspec/terraspace/ts.rb +13 -9
- data/lib/rspec/terraspace/version.rb +1 -1
- data/lib/templates/bootstrap/.rspec +3 -0
- data/lib/templates/bootstrap/spec/spec_helper.rb +13 -0
- data/lib/templates/module/test/.rspec +3 -0
- data/lib/templates/module/test/Gemfile.tt +9 -0
- data/lib/templates/module/test/spec/fixtures/stack/main.tf.tt +6 -0
- data/lib/templates/module/test/spec/fixtures/stack/outputs.tf +1 -0
- data/lib/templates/module/test/spec/main_spec.rb.tt +24 -0
- data/lib/templates/module/test/spec/spec_helper.rb +18 -0
- data/lib/templates/project/spec/fixtures/tfvars/%name%.tfvars +1 -0
- data/lib/templates/project/spec/stacks/%name%/main_spec.rb.tt +28 -0
- metadata +13 -3
- data/Gemfile.lock +0 -54
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35a489c43cf46b2b9fef6abe99450214d03c06e967c24ab2f01dac34dd101521
|
4
|
+
data.tar.gz: d5b2b8dc3df0e0c5afb2c950872518cc060b899a06b5f2323218344161a41582
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c5a2ca7bcd5a8c303775d33662669ac206f9b2863a18e444c68dc31bbca5970ce5d52747d58d828957eea73892217fdbd43364ca2b1be2360da1da6201afe87
|
7
|
+
data.tar.gz: 4a30979a383439cda48ea216519dce5d38442a655062bd93ab2925b4a7f6cf4628547ed0f526931295fd3b60c5fbf1dc0bf7444a1385e0e5cb0b11b4a450fbfb
|
data/.gitignore
CHANGED
data/CHANGELOG.md
ADDED
data/Gemfile
CHANGED
data/lib/rspec/terraspace.rb
CHANGED
@@ -12,6 +12,11 @@ RSpec::Terraspace::Autoloader.setup
|
|
12
12
|
module Rspec
|
13
13
|
module Terraspace
|
14
14
|
class Error < StandardError; end
|
15
|
-
# Your code goes here...
|
16
15
|
end
|
17
16
|
end
|
17
|
+
|
18
|
+
require "terraspace"
|
19
|
+
|
20
|
+
Terraspace::Tester.register("rspec",
|
21
|
+
root: File.expand_path("../..", __dir__)
|
22
|
+
)
|
@@ -5,9 +5,12 @@ module RSpec::Terraspace
|
|
5
5
|
class Project
|
6
6
|
def initialize(options={})
|
7
7
|
@options = options
|
8
|
-
@name = options[:name]
|
8
|
+
@name = options[:name]
|
9
|
+
@config = options[:config]
|
9
10
|
@modules = options[:modules]
|
10
11
|
@stacks = options[:stacks]
|
12
|
+
@tfvars = options[:tfvars]
|
13
|
+
@folders = options[:folders]
|
11
14
|
|
12
15
|
@remove_test_folder = options[:remove_test_folder].nil? ? true : options[:remove_test_folder]
|
13
16
|
end
|
@@ -15,31 +18,91 @@ module RSpec::Terraspace
|
|
15
18
|
def create
|
16
19
|
clean
|
17
20
|
build_project
|
21
|
+
build_config
|
18
22
|
build_modules
|
19
23
|
build_stacks
|
24
|
+
build_tfvars
|
25
|
+
build_folders
|
20
26
|
puts "Test harness built: #{build_dir}"
|
21
27
|
build_dir
|
22
28
|
end
|
23
29
|
|
30
|
+
# folders at any-level, including top-level can be copied with the folders option
|
31
|
+
def build_folders
|
32
|
+
return unless @folders
|
33
|
+
|
34
|
+
@folders.each do |folder|
|
35
|
+
dest = "#{build_dir}/#{folder}"
|
36
|
+
FileUtils.mkdir_p(File.dirname(dest))
|
37
|
+
FileUtils.cp_r(folder, dest)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
24
41
|
def build_project
|
25
42
|
parent_dir = File.dirname(build_dir)
|
26
43
|
FileUtils.mkdir_p(parent_dir)
|
27
44
|
Dir.chdir(parent_dir) do
|
28
45
|
project_name = File.basename(build_dir)
|
29
|
-
::Terraspace::CLI::New::Project.start([project_name])
|
46
|
+
::Terraspace::CLI::New::Project.start([project_name, "--no-config"])
|
30
47
|
end
|
48
|
+
end
|
31
49
|
|
32
|
-
|
33
|
-
|
34
|
-
|
50
|
+
def build_config
|
51
|
+
return unless @config
|
52
|
+
|
53
|
+
config_folder = "#{build_dir}/config"
|
54
|
+
FileUtils.rm_rf(config_folder) # wipe current config folder
|
55
|
+
FileUtils.mkdir_p(File.dirname(config_folder))
|
56
|
+
src = @config
|
57
|
+
FileUtils.cp_r(src, config_folder)
|
35
58
|
end
|
36
59
|
|
37
60
|
def build_modules
|
38
|
-
|
61
|
+
return unless @modules
|
62
|
+
build_type_folder("modules", @modules)
|
39
63
|
end
|
40
64
|
|
41
65
|
def build_stacks
|
42
|
-
|
66
|
+
return unless @stacks
|
67
|
+
build_type_folder("stacks", @stacks)
|
68
|
+
end
|
69
|
+
|
70
|
+
# If a file has been supplied, then it gets copied over.
|
71
|
+
#
|
72
|
+
# # File
|
73
|
+
# terraspace.build_test_harness(
|
74
|
+
# tfvars: {demo: "spec/fixtures/tfvars/demo.tfvars"},
|
75
|
+
# end
|
76
|
+
#
|
77
|
+
# # Results in:
|
78
|
+
# app/stacks/#{stack}/tfvars/test.tfvars
|
79
|
+
#
|
80
|
+
# If a directory has been supplied, then the folder fully gets copied over.
|
81
|
+
#
|
82
|
+
# # Directory
|
83
|
+
# terraspace.build_test_harness(
|
84
|
+
# tfvars: {demo: "spec/fixtures/tfvars/demo"},
|
85
|
+
# end
|
86
|
+
#
|
87
|
+
# # Results in (whatever is in the folder):
|
88
|
+
# app/stacks/#{stack}/tfvars/base.tfvars
|
89
|
+
# app/stacks/#{stack}/tfvars/test.tfvars
|
90
|
+
#
|
91
|
+
def build_tfvars
|
92
|
+
return unless @tfvars
|
93
|
+
@tfvars.each do |stack, src|
|
94
|
+
tfvars_folder = "#{build_dir}/app/stacks/#{stack}/tfvars"
|
95
|
+
FileUtils.rm_rf(tfvars_folder) # wipe current tfvars folder. dont use any of the live values
|
96
|
+
|
97
|
+
if File.directory?(src)
|
98
|
+
FileUtils.mkdir_p(File.dirname(tfvars_folder))
|
99
|
+
FileUtils.cp_r(src, tfvars_folder)
|
100
|
+
else # if only a single file, then generate a test.tfvars since this runs under TS_ENV=test
|
101
|
+
dest = "#{tfvars_folder}/test.tfvars"
|
102
|
+
FileUtils.mkdir_p(File.dirname(dest))
|
103
|
+
FileUtils.cp(src, dest)
|
104
|
+
end
|
105
|
+
end
|
43
106
|
end
|
44
107
|
|
45
108
|
# Inputs:
|
@@ -58,7 +121,7 @@ module RSpec::Terraspace
|
|
58
121
|
# If provide a String, it should be a path to folder containing all modules or stacks.
|
59
122
|
# This provides less fine-grain control but is easier to use and shorter.
|
60
123
|
#
|
61
|
-
def
|
124
|
+
def build_type_folder(type_dir, list)
|
62
125
|
case list
|
63
126
|
when Hash
|
64
127
|
list.each do |name, src|
|
@@ -89,11 +152,15 @@ module RSpec::Terraspace
|
|
89
152
|
end
|
90
153
|
|
91
154
|
def build_dir
|
92
|
-
"#{
|
155
|
+
"#{tmp_root}/#{@name}"
|
156
|
+
end
|
157
|
+
|
158
|
+
def tmp_root
|
159
|
+
self.class.tmp_root
|
93
160
|
end
|
94
161
|
|
95
|
-
def
|
96
|
-
|
162
|
+
def self.tmp_root
|
163
|
+
"#{Terraspace.tmp_root}/test-harnesses"
|
97
164
|
end
|
98
165
|
end
|
99
166
|
end
|
data/lib/rspec/terraspace/ts.rb
CHANGED
@@ -9,12 +9,15 @@ module RSpec::Terraspace
|
|
9
9
|
def build_test_harness(options={})
|
10
10
|
puts "Building test harness..."
|
11
11
|
project = Project.new(options)
|
12
|
-
|
13
|
-
|
12
|
+
root = project.create
|
13
|
+
Terraspace.root = root # switch root to the generated test harness
|
14
14
|
end
|
15
15
|
|
16
16
|
def up(args)
|
17
17
|
run("up #{args} -y")
|
18
|
+
mod = args.split(' ').first
|
19
|
+
@mod = ::Terraspace::Mod.new(mod)
|
20
|
+
save_output
|
18
21
|
end
|
19
22
|
|
20
23
|
def down(args)
|
@@ -22,23 +25,24 @@ module RSpec::Terraspace
|
|
22
25
|
end
|
23
26
|
|
24
27
|
def run(command)
|
28
|
+
puts "=> terraspace #{command}".color(:green)
|
25
29
|
args = command.split(' ')
|
26
30
|
CLI.start(args)
|
27
31
|
end
|
28
32
|
|
29
|
-
|
30
|
-
|
33
|
+
# Note: a terraspace.down will remove the output.json since it does a clean
|
34
|
+
def save_output
|
35
|
+
FileUtils.mkdir_p(File.dirname(out_path))
|
36
|
+
run("output #{@mod.name} --format json --out #{out_path}")
|
31
37
|
end
|
32
|
-
memoize :save_output
|
33
38
|
|
34
39
|
def output(mod, name)
|
35
|
-
|
36
|
-
data = JSON.load(IO.read(saved_output_path))
|
40
|
+
data = JSON.load(IO.read(out_path))
|
37
41
|
data.dig(name, "value")
|
38
42
|
end
|
39
43
|
|
40
|
-
def
|
41
|
-
"#{
|
44
|
+
def out_path
|
45
|
+
"#{Terraspace.tmp_root}/rspec/output.json"
|
42
46
|
end
|
43
47
|
end
|
44
48
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
# This is where you put your output declarations
|
@@ -0,0 +1,24 @@
|
|
1
|
+
describe "main" do
|
2
|
+
before(:all) do
|
3
|
+
mod_path = File.expand_path("../..", __dir__) # the source of the module to test is 2 levels up
|
4
|
+
# Build terraspace project to use as a test harness
|
5
|
+
# Will be located at: /tmp/terraspace/test-harnesses/<%= name %>-harness
|
6
|
+
terraspace.build_test_harness(
|
7
|
+
name: "<%= name %>-harness",
|
8
|
+
modules: {<%= name %>: mod_path},
|
9
|
+
stacks: {<%= name %>: "#{mod_path}/test/spec/fixtures/stack"}, # folder with the stack module files
|
10
|
+
)
|
11
|
+
terraspace.up("<%= name %>")
|
12
|
+
end
|
13
|
+
after(:all) do
|
14
|
+
terraspace.down("<%= name %>")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "successful deploy" do
|
18
|
+
# Replace with your own test
|
19
|
+
expect(true).to be true
|
20
|
+
# Example
|
21
|
+
# output_value = terraspace.output("<%= name %>", "some-output")
|
22
|
+
# expect(output_value).to include("some-value")
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
ENV["TS_ENV"] = "test"
|
2
|
+
|
3
|
+
require "terraspace"
|
4
|
+
require "rspec/terraspace"
|
5
|
+
|
6
|
+
module Helper
|
7
|
+
def execute(cmd)
|
8
|
+
puts "Running: #{cmd}" if ENV['SHOW_COMMAND']
|
9
|
+
out = `#{cmd}`
|
10
|
+
puts out if ENV['SHOW_COMMAND']
|
11
|
+
out
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
RSpec.configure do |c|
|
16
|
+
c.include Helper
|
17
|
+
c.include RSpec::Terraspace::Helpers
|
18
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
# This is where you put your tfvars
|
@@ -0,0 +1,28 @@
|
|
1
|
+
describe "main" do
|
2
|
+
before(:all) do
|
3
|
+
# Build terraspace project to use as a test harness
|
4
|
+
# Will be located at: /tmp/terraspace/test-harnesses/<%= name %>-harness
|
5
|
+
terraspace.build_test_harness(
|
6
|
+
name: "<%= name %>-harness",
|
7
|
+
modules: "app/modules", # include all modules in this folder
|
8
|
+
stacks: "app/stacks", # include all stacks in this folder
|
9
|
+
# override demo stack tfvars for testing
|
10
|
+
# copied over to test harness' app/stacks/demo/tfvars/test.tfvars
|
11
|
+
tfvars: {demo: "spec/fixtures/tfvars/demo.tfvars"},
|
12
|
+
# create config if needed. The folder will be copied over
|
13
|
+
# config: "spec/fixtures/config",
|
14
|
+
)
|
15
|
+
terraspace.up("<%= name %>") # provision real resources
|
16
|
+
end
|
17
|
+
after(:all) do
|
18
|
+
terraspace.down("<%= name %>") # destroy real resources
|
19
|
+
end
|
20
|
+
|
21
|
+
it "successful deploy" do
|
22
|
+
# Replace with your actual test
|
23
|
+
expect(true).to be true
|
24
|
+
# Example
|
25
|
+
# output_value = terraspace.output("<%= name %>", "some-output")
|
26
|
+
# expect(output_value).to include("some-value")
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-terraspace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tung Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -89,8 +89,8 @@ extra_rdoc_files: []
|
|
89
89
|
files:
|
90
90
|
- ".gitignore"
|
91
91
|
- ".rspec"
|
92
|
+
- CHANGELOG.md
|
92
93
|
- Gemfile
|
93
|
-
- Gemfile.lock
|
94
94
|
- LICENSE.txt
|
95
95
|
- README.md
|
96
96
|
- Rakefile
|
@@ -102,6 +102,16 @@ files:
|
|
102
102
|
- lib/rspec/terraspace/project.rb
|
103
103
|
- lib/rspec/terraspace/ts.rb
|
104
104
|
- lib/rspec/terraspace/version.rb
|
105
|
+
- lib/templates/bootstrap/.rspec
|
106
|
+
- lib/templates/bootstrap/spec/spec_helper.rb
|
107
|
+
- lib/templates/module/test/.rspec
|
108
|
+
- lib/templates/module/test/Gemfile.tt
|
109
|
+
- lib/templates/module/test/spec/fixtures/stack/main.tf.tt
|
110
|
+
- lib/templates/module/test/spec/fixtures/stack/outputs.tf
|
111
|
+
- lib/templates/module/test/spec/main_spec.rb.tt
|
112
|
+
- lib/templates/module/test/spec/spec_helper.rb
|
113
|
+
- lib/templates/project/spec/fixtures/tfvars/%name%.tfvars
|
114
|
+
- lib/templates/project/spec/stacks/%name%/main_spec.rb.tt
|
105
115
|
- rspec-terraspace.gemspec
|
106
116
|
homepage: https://github.com/boltops-tools/rspec-terraspace
|
107
117
|
licenses:
|
data/Gemfile.lock
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
rspec-terraspace (0.1.0)
|
5
|
-
activesupport
|
6
|
-
memoist
|
7
|
-
rainbow
|
8
|
-
zeitwerk
|
9
|
-
|
10
|
-
GEM
|
11
|
-
remote: https://rubygems.org/
|
12
|
-
specs:
|
13
|
-
activesupport (6.0.3.1)
|
14
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
15
|
-
i18n (>= 0.7, < 2)
|
16
|
-
minitest (~> 5.1)
|
17
|
-
tzinfo (~> 1.1)
|
18
|
-
zeitwerk (~> 2.2, >= 2.2.2)
|
19
|
-
concurrent-ruby (1.1.6)
|
20
|
-
diff-lcs (1.3)
|
21
|
-
i18n (1.8.2)
|
22
|
-
concurrent-ruby (~> 1.0)
|
23
|
-
memoist (0.16.2)
|
24
|
-
minitest (5.14.1)
|
25
|
-
rainbow (3.0.0)
|
26
|
-
rake (12.3.3)
|
27
|
-
rspec (3.9.0)
|
28
|
-
rspec-core (~> 3.9.0)
|
29
|
-
rspec-expectations (~> 3.9.0)
|
30
|
-
rspec-mocks (~> 3.9.0)
|
31
|
-
rspec-core (3.9.2)
|
32
|
-
rspec-support (~> 3.9.3)
|
33
|
-
rspec-expectations (3.9.2)
|
34
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
-
rspec-support (~> 3.9.0)
|
36
|
-
rspec-mocks (3.9.1)
|
37
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
-
rspec-support (~> 3.9.0)
|
39
|
-
rspec-support (3.9.3)
|
40
|
-
thread_safe (0.3.6)
|
41
|
-
tzinfo (1.2.7)
|
42
|
-
thread_safe (~> 0.1)
|
43
|
-
zeitwerk (2.3.0)
|
44
|
-
|
45
|
-
PLATFORMS
|
46
|
-
ruby
|
47
|
-
|
48
|
-
DEPENDENCIES
|
49
|
-
rake (~> 12.0)
|
50
|
-
rspec (~> 3.0)
|
51
|
-
rspec-terraspace!
|
52
|
-
|
53
|
-
BUNDLED WITH
|
54
|
-
2.1.4
|