rspec-terraspace 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 35a489c43cf46b2b9fef6abe99450214d03c06e967c24ab2f01dac34dd101521
4
- data.tar.gz: d5b2b8dc3df0e0c5afb2c950872518cc060b899a06b5f2323218344161a41582
3
+ metadata.gz: 54ad8cf08fa4c6c27cae1858bf26c3519e3687a6c5c2e29a142ccea6ffce66f9
4
+ data.tar.gz: ad84fe683514e979be0a0b528ced6c93998553183f39aec960133b143fa69620
5
5
  SHA512:
6
- metadata.gz: 8c5a2ca7bcd5a8c303775d33662669ac206f9b2863a18e444c68dc31bbca5970ce5d52747d58d828957eea73892217fdbd43364ca2b1be2360da1da6201afe87
7
- data.tar.gz: 4a30979a383439cda48ea216519dce5d38442a655062bd93ab2925b4a7f6cf4628547ed0f526931295fd3b60c5fbf1dc0bf7444a1385e0e5cb0b11b4a450fbfb
6
+ metadata.gz: 1615ec5212492fafc800243e546c0755f99b77ac86ac92f911f2d277ebd613b18f7dafe5d6edebdd5181031ad8fb4639d4127186454fa56eb871684b1aba3a64
7
+ data.tar.gz: 4201be145491631a431a65e5916a9ac92928ec584911d269552a6fff815fc18abe314b6a5d816afd14b69f9b53f875970173cc207c76fe4242a99c410b345634
@@ -3,5 +3,9 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *tries* to adhere to [Semantic Versioning](http://semver.org/).
5
5
 
6
+ ## [0.2.0] - 2020-11-15
7
+ - [#2](https://github.com/boltops-tools/rspec-terraspace/pull/2) stack test like module test template, reconfigure logger
8
+ - stack test like module test template, reconfigure logger
9
+
6
10
  ## [0.1.0]
7
11
  - Initial release
@@ -2,6 +2,13 @@ module RSpec::Terraspace
2
2
  module Helpers
3
3
  extend Memoist
4
4
 
5
+ def reconfigure_logging(level="info")
6
+ path = "/tmp/terraspace/log/test.log"
7
+ FileUtils.mkdir_p(File.dirname(path))
8
+ Terraspace.logger = Terraspace::Logger.new(path)
9
+ puts "Terraspace.logger has been reconfigured to #{path}"
10
+ end
11
+
5
12
  def ts
6
13
  Ts.new
7
14
  end
@@ -16,6 +16,7 @@ module RSpec::Terraspace
16
16
  end
17
17
 
18
18
  def create
19
+ puts "Building test harness at: #{build_dir}"
19
20
  clean
20
21
  build_project
21
22
  build_config
@@ -23,7 +24,7 @@ module RSpec::Terraspace
23
24
  build_stacks
24
25
  build_tfvars
25
26
  build_folders
26
- puts "Test harness built: #{build_dir}"
27
+ puts "Test harness built."
27
28
  build_dir
28
29
  end
29
30
 
@@ -43,7 +44,7 @@ module RSpec::Terraspace
43
44
  FileUtils.mkdir_p(parent_dir)
44
45
  Dir.chdir(parent_dir) do
45
46
  project_name = File.basename(build_dir)
46
- ::Terraspace::CLI::New::Project.start([project_name, "--no-config"])
47
+ ::Terraspace::CLI::New::Project.start([project_name, "--no-config", "--quiet"])
47
48
  end
48
49
  end
49
50
 
@@ -7,7 +7,6 @@ module RSpec::Terraspace
7
7
  CLI = ::Terraspace::CLI
8
8
 
9
9
  def build_test_harness(options={})
10
- puts "Building test harness..."
11
10
  project = Project.new(options)
12
11
  root = project.create
13
12
  Terraspace.root = root # switch root to the generated test harness
@@ -37,8 +36,11 @@ module RSpec::Terraspace
37
36
  end
38
37
 
39
38
  def output(mod, name)
40
- data = JSON.load(IO.read(out_path))
41
- data.dig(name, "value")
39
+ outputs.dig(name, "value")
40
+ end
41
+
42
+ def outputs(mod)
43
+ JSON.load(IO.read(out_path))
42
44
  end
43
45
 
44
46
  def out_path
@@ -1,5 +1,5 @@
1
1
  module Rspec
2
2
  module Terraspace
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -1,5 +1,6 @@
1
1
  describe "main" do
2
2
  before(:all) do
3
+ reconfigure_logging # reconfigure Terraspace.logger to a file
3
4
  mod_path = File.expand_path("../..", __dir__) # the source of the module to test is 2 levels up
4
5
  # Build terraspace project to use as a test harness
5
6
  # Will be located at: /tmp/terraspace/test-harnesses/<%= name %>-harness
@@ -18,6 +19,7 @@ describe "main" do
18
19
  # Replace with your own test
19
20
  expect(true).to be true
20
21
  # Example
22
+ # pp terraspace.outputs("<%= name %>")
21
23
  # output_value = terraspace.output("<%= name %>", "some-output")
22
24
  # expect(output_value).to include("some-value")
23
25
  end
@@ -0,0 +1,5 @@
1
+ describe "<%= test_name %>" do
2
+ it "the truth" do
3
+ expect(true).to be true
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format documentation
3
+ --require spec_helper
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ <%=
4
+ build_gemfile(
5
+ "terraspace",
6
+ "rspec-terraspace",
7
+ plugin_gem_name,
8
+ )
9
+ %>
@@ -0,0 +1,31 @@
1
+ describe "main" do
2
+ before(:all) do
3
+ reconfigure_logging # reconfigure Terraspace.logger to a file
4
+ stack_path = File.expand_path("../..", __dir__) # the source of the stack to test is 2 levels up
5
+ ts_root = File.expand_path("../../..", stack_path) # original Terraspace.root
6
+ # Build terraspace project to use as a test harness
7
+ # Will be located at: /tmp/terraspace/test-harnesses/<%= name %>-harness
8
+ terraspace.build_test_harness(
9
+ name: "<%= name %>-harness",
10
+ modules: "#{ts_root}/app/modules", # include all modules in folder
11
+ stacks: {<%= name %>: stack_path},
12
+ # override demo stack tfvars for testing
13
+ tfvars: {demo: "#{stack_path}/test/spec/fixtures/tfvars/demo.tfvars"},
14
+ # create config if needed. The folder will be copied over
15
+ # config: "#{stack_path}/spec/fixtures/config",
16
+ )
17
+ terraspace.up("<%= name %>")
18
+ end
19
+ after(:all) do
20
+ terraspace.down("<%= name %>")
21
+ end
22
+
23
+ it "successful deploy" do
24
+ # Replace with your own test
25
+ expect(true).to be true
26
+ # Example
27
+ # pp terraspace.outputs("<%= name %>")
28
+ # output_value = terraspace.output("<%= name %>", "some-output")
29
+ # expect(output_value).to include("some-value")
30
+ end
31
+ 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
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.1.0
4
+ version: 0.2.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-07-23 00:00:00.000000000 Z
11
+ date: 2020-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -110,8 +110,12 @@ files:
110
110
  - lib/templates/module/test/spec/fixtures/stack/outputs.tf
111
111
  - lib/templates/module/test/spec/main_spec.rb.tt
112
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
113
+ - lib/templates/project/spec/%test_name%_spec.rb.tt
114
+ - lib/templates/stack/test/.rspec
115
+ - lib/templates/stack/test/Gemfile.tt
116
+ - lib/templates/stack/test/spec/fixtures/tfvars/%name%.tfvars
117
+ - lib/templates/stack/test/spec/main_spec.rb.tt
118
+ - lib/templates/stack/test/spec/spec_helper.rb
115
119
  - rspec-terraspace.gemspec
116
120
  homepage: https://github.com/boltops-tools/rspec-terraspace
117
121
  licenses:
@@ -132,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
136
  - !ruby/object:Gem::Version
133
137
  version: '0'
134
138
  requirements: []
135
- rubygems_version: 3.1.2
139
+ rubygems_version: 3.1.4
136
140
  signing_key:
137
141
  specification_version: 4
138
142
  summary: Terraspace RSpec support
@@ -1,28 +0,0 @@
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