rspec-lono 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ad12201659965d9231ce7d1686cf72b975c2ce6b0f77ce1436e36cad161ce9c3
4
+ data.tar.gz: 7e4495012447d2078e7d067457fd25f39dcb635cc5d136ef864cb28f52824446
5
+ SHA512:
6
+ metadata.gz: 1643aa43dd672fb76333181500c5777e3981ed6437fdc8eeb05350fefccbc73ed23d66b02a3fa12cb37bc43ecf22b919f4078ac765dbf18830ff398c3f87fc7a
7
+ data.tar.gz: 22835255cc072515f0aad1a88b5f7a37f867b3dc033b114b870e7bc21841dcf197609eeba5f1af520c405acd30eabb6aaf6d81c016a452116b77d5035827d592
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ This project *tries* to adhere to [Semantic Versioning](http://semver.org/).
5
+
6
+ ## [0.1.0] - 2022-02-21
7
+
8
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in rspec-lono.gemspec
6
+ gemspec
7
+
8
+ gem "rake", ">= 13.0"
9
+ gem "rspec", ">= 3.0"
10
+
11
+ group :development, :test do
12
+ gem "lono", git: "https://github.com/boltops-tools/lono", branch: "v8"
13
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # rspec-lono
2
+
3
+ [![BoltOps Badge](https://img.boltops.com/boltops/badges/boltops-badge.png)](https://www.boltops.com)
4
+
5
+ Terraspec rspec helper methods. The usual testing process is:
6
+
7
+ 1. Build a test harness. The test harness is a generated lono project with the specified blueprint.
8
+ 2. Runs a `lono up` to create real resources.
9
+ 3. Check the resources. In many cases, check the CloudFormation resources and outputs.
10
+ 4. Runs a `lono down` to clean up the real resources.
11
+
12
+ ## Test harness location
13
+
14
+ Where is the generated test harness located?
15
+
16
+ The test hardness is materialized into `/tmp/lono/test-harnesses/NAME`.
17
+
18
+ ## Blueprint-Level and Project-Level Tests
19
+
20
+ The test helpers support both blueprint-level and project-level tests. See:
21
+
22
+ * [Lono Testing](https://lono.cloud/docs/testing/)
23
+
24
+ ## Installation
25
+
26
+ Add this line to your application's Gemfile:
27
+
28
+ ```ruby
29
+ gem 'rspec-lono'
30
+ ```
31
+
32
+ And then execute:
33
+
34
+ $ bundle install
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,24 @@
1
+ require "zeitwerk"
2
+
3
+ module RSpec
4
+ module Lono
5
+ class Autoloader
6
+ class Inflector < Zeitwerk::Inflector
7
+ def camelize(basename, _abspath)
8
+ map = { cli: "CLI", rspec: "RSpec", version: "VERSION" }
9
+ map[basename.to_sym] || super
10
+ end
11
+ end
12
+
13
+ class << self
14
+ def setup
15
+ loader = Zeitwerk::Loader.new
16
+ loader.inflector = Inflector.new
17
+ lib = File.expand_path("../..", __dir__)
18
+ loader.push_dir(lib) # lib
19
+ loader.setup
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,7 @@
1
+ module RSpec::Lono::Concerns
2
+ module Logging
3
+ def logger
4
+ RSpec::Lono.logger
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ module RSpec::Lono
2
+ module Concerns
3
+ extend Memoist
4
+ include Logging
5
+
6
+ def detection
7
+ Detector.new
8
+ end
9
+ memoize :detection
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ module RSpec::Lono
2
+ module Core
3
+ cattr_writer :logger
4
+ def logger
5
+ @@logger ||= Lono.logger
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,25 @@
1
+ module RSpec::Lono
2
+ class Detector
3
+ def blueprint
4
+ md = calling_file.match(%r{/blueprints/(.*)/test/spec/})
5
+ md[1]
6
+ end
7
+
8
+ def root
9
+ calling_file.sub(%r{/test/spec/.*}, '') # IE: /home/user/lono-project/app/blueprints/demo
10
+ end
11
+
12
+ # Automatically discover the blueprint root path
13
+ #
14
+ # Caller lines are different for OSes:
15
+ #
16
+ # windows: "C:/Users/user/lono-project/app/blueprints/demo/test/spec/blueprint_spec.rb:12:in `block (2 levels) in <top (required)>'"
17
+ # linux: "/home/user/lono-project/app/blueprints/demo/test/spec/blueprint_spec.rb:12:in `block (2 levels) in <top (required)>'"
18
+ #
19
+ def calling_file
20
+ caller_line = caller.find { |l| l.include?("_spec.rb") }
21
+ parts = caller_line.split(':')
22
+ caller_line.match(/^[a-zA-Z]:/) ? parts[1] : parts[0]
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,174 @@
1
+ require "fileutils"
2
+ require "tmpdir"
3
+
4
+ class RSpec::Lono::Harness
5
+ class Project
6
+ include RSpec::Lono::Concerns
7
+
8
+ def initialize(options={})
9
+ @config = options[:config] || "spec/fixtures/config"
10
+ @blueprint = options[:blueprint] || detection.blueprint # String. IE: demo
11
+ @params = options[:params] || "spec/fixtures/params"
12
+ @vars = options[:vars] || "spec/fixtures/vars"
13
+ @folders = options[:folders]
14
+ @plugin = options[:plugin]
15
+
16
+ @root = options[:root] || detection.root # IE: /home/user/lono-project/app/blueprints/demo
17
+ @remove_test_folder = options[:remove_test_folder].nil? ? true : options[:remove_test_folder]
18
+ end
19
+
20
+ def create
21
+ puts "Building test harness at: #{build_dir}"
22
+ clean
23
+ build_project
24
+ build_config
25
+ build_blueprint
26
+ build_params
27
+ build_vars
28
+ build_folders
29
+ puts "Test harness built."
30
+ build_dir
31
+ end
32
+
33
+ # folders at any-level, including top-level can be copied with the folders option
34
+ def build_folders
35
+ return unless @folders
36
+
37
+ @folders.each do |folder|
38
+ dest = "#{build_dir}/#{folder}"
39
+ FileUtils.mkdir_p(File.dirname(dest))
40
+ FileUtils.cp_r(folder, dest)
41
+ end
42
+ end
43
+
44
+ def build_project
45
+ parent_dir = File.dirname(build_dir)
46
+ FileUtils.mkdir_p(parent_dir)
47
+ Dir.chdir(parent_dir) do
48
+ project_name = File.basename(build_dir)
49
+ args = [project_name, "--quiet"]
50
+ Lono::CLI::New::Project.start(args)
51
+ end
52
+ end
53
+
54
+ def build_config
55
+ return unless File.exist?(@config)
56
+ config_folder = "#{build_dir}/config"
57
+ FileUtils.mkdir_p(File.dirname(config_folder))
58
+ Dir.glob("#{@config}/*").each do |src|
59
+ FileUtils.cp_r(src, config_folder)
60
+ end
61
+ end
62
+
63
+ def build_blueprint
64
+ return unless @blueprint
65
+ build_type_folder("blueprints", @blueprint => @root)
66
+ end
67
+
68
+ def build_params
69
+ build_inputs(:params)
70
+ end
71
+
72
+ def build_vars
73
+ build_inputs(:vars)
74
+ end
75
+
76
+ # If a file has been supplied, then it gets copied over.
77
+ #
78
+ # # File
79
+ # lono.build_test_harness(
80
+ # params: "spec/fixtures/params/demo.txt",
81
+ # end
82
+ #
83
+ # # Results in:
84
+ # app/blueprints/#{@blueprint}/params/test.txt
85
+ #
86
+ # If a directory has been supplied, then the folder fully gets copied over.
87
+ #
88
+ # # Directory
89
+ # lono.build_test_harness(
90
+ # params: {demo: "spec/fixtures/params/demo"},
91
+ # end
92
+ #
93
+ # # Results in (whatever is in the folder):
94
+ # app/blueprints/#{@blueprint}/params/base.txt
95
+ # app/blueprints/#{@blueprint}/params/test.txt
96
+ #
97
+ def build_inputs(type)
98
+ instance_var = instance_variable_get("@#{type}") # IE: @params or @vars
99
+ inputs = [instance_var].compact.flatten
100
+ ext = type == :params ? 'txt' : 'rb'
101
+ inputs.each do |src|
102
+ folder = "#{build_dir}/config/blueprints/#{@blueprint}/#{type}"
103
+ FileUtils.rm_rf(folder) # wipe current params folder
104
+
105
+ if File.directory?(src)
106
+ FileUtils.mkdir_p(File.dirname(folder))
107
+ FileUtils.cp_r(src, folder)
108
+ elsif File.exist?(src) # if only a single file, then generate a test.txt since this runs under LONO_ENV=test
109
+ dest = "#{folder}/#{Lono.env}.#{ext}"
110
+ FileUtils.mkdir_p(File.dirname(dest))
111
+ FileUtils.cp(src, dest)
112
+ end
113
+ end
114
+ end
115
+
116
+ # Inputs:
117
+ #
118
+ # list: options[:blueprints] or options[:stacks]
119
+ # type_dir: blueprints or stacks
120
+ #
121
+ # The list argument can support a Hash or String value.
122
+ #
123
+ # If provided a Hahs, it should be structured like so:
124
+ #
125
+ # {vm: "app/blueprints/vm", network: "app/blueprints/network"}
126
+ #
127
+ # This allows for finer-control to specify what blueprints and stacks to build
128
+ #
129
+ # If provide a String, it should be a path to folder containing all blueprints or stacks.
130
+ # This provides less fine-grain control but is easier to use and shorter.
131
+ #
132
+ def build_type_folder(type_dir, list)
133
+ case list
134
+ when Hash
135
+ list.each do |name, src|
136
+ dest = "#{build_dir}/app/#{type_dir}/#{name}"
137
+ copy(src, dest)
138
+ remove_test_folder(dest) if @remove_test_folder
139
+ end
140
+ when String
141
+ dest = "#{build_dir}/app/#{type_dir}"
142
+ FileUtils.rm_rf(dest)
143
+ FileUtils.cp_r(list, dest)
144
+ else
145
+ raise "blueprints option must be a Hash or String"
146
+ end
147
+ end
148
+
149
+ def remove_test_folder(dest)
150
+ FileUtils.rm_rf("#{dest}/test")
151
+ end
152
+
153
+ def clean
154
+ FileUtils.rm_rf(build_dir)
155
+ end
156
+
157
+ def copy(src, dest)
158
+ FileUtils.mkdir_p(File.dirname(dest))
159
+ FileUtils.cp_r(src, dest)
160
+ end
161
+
162
+ def build_dir
163
+ "#{tmp_root}/#{@blueprint}"
164
+ end
165
+
166
+ def tmp_root
167
+ self.class.tmp_root
168
+ end
169
+
170
+ def self.tmp_root
171
+ "#{Lono.tmp_root}/test-harnesses"
172
+ end
173
+ end
174
+ end
@@ -0,0 +1,22 @@
1
+ module RSpec::Lono
2
+ class Harness
3
+ def initialize(options={})
4
+ @options = options
5
+ end
6
+
7
+ def build(options={})
8
+ setup
9
+ project = Project.new(@options.merge(options))
10
+ root = project.create
11
+ Lono.root = root # switch root to the generated test harness
12
+ end
13
+
14
+ def setup
15
+ # Require gems in Gemfile so lono_plugin_* gets loaded and registered
16
+ # This it test Gemfile. IE: app/stacks/demo/test/Gemfile
17
+ Kernel.require "bundler/setup"
18
+ Bundler.require # Same as Bundler.require(:default)
19
+ Lono.check_project = false
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,16 @@
1
+ module RSpec::Lono
2
+ module Helpers
3
+ extend Memoist
4
+
5
+ def harness
6
+ Harness.new
7
+ end
8
+ memoize :harness
9
+
10
+ def lono
11
+ # Normally @blueprint is nil and Runner will infer blueprint. User can override with @blueprint.
12
+ Runner.new(blueprint: @blueprint)
13
+ end
14
+ memoize :lono
15
+ end
16
+ end
@@ -0,0 +1,32 @@
1
+ class RSpec::Lono::Runner
2
+ module Concerns
3
+ extend Memoist
4
+ include Lono::AwsServices
5
+
6
+ # Example:
7
+ # {
8
+ # "SecurityGroupId"=>"sg-08ca356e0a6d607e4",
9
+ # "SecurityGroup"=>"demo-test-SecurityGroup-17X56VTN9PRXH"
10
+ # }
11
+ def outputs
12
+ stack.outputs.inject({}) do |acc,o|
13
+ acc.merge(o.output_key => o.output_value)
14
+ end
15
+ end
16
+
17
+ def resources
18
+ resp = describe_stack_resources(stack_name: @stack)
19
+ resp.stack_resources
20
+ end
21
+
22
+ def stack
23
+ find_stack(@stack)
24
+ end
25
+ memoize :stack
26
+
27
+ def describe_stack_resources(options={})
28
+ cfn.describe_stack_resources(options)
29
+ end
30
+ memoize :describe_stack_resources
31
+ end
32
+ end
@@ -0,0 +1,39 @@
1
+ require "json"
2
+
3
+ # Named Lo so dont have to fully qualify ::Lono within RSpec::Lono
4
+ module RSpec::Lono
5
+ class Runner
6
+ CLI = Lono::CLI
7
+ include RSpec::Lono::Concerns
8
+ include RSpec::Lono::Runner::Concerns
9
+ extend Memoist
10
+
11
+ def initialize(options={})
12
+ @options = options
13
+ @options[:blueprint] ||= detection.blueprint
14
+ @blueprint = Lono::Blueprint.new(@options)
15
+ @stack = Lono::Names.new(@options).stack
16
+ @name = @blueprint.name
17
+ end
18
+
19
+ def build(args='')
20
+ run("build #{@name} #{args}")
21
+ end
22
+
23
+ def up(args='')
24
+ run("up #{@name} #{args} -y")
25
+ end
26
+
27
+ def down(args='')
28
+ run("down #{@name} #{args} -y")
29
+ self.flush_cache
30
+ end
31
+
32
+ def run(command)
33
+ command = command.strip
34
+ puts "=> LONO_ENV=#{Lono.env} lono #{command}".color(:green)
35
+ args = command.split(' ')
36
+ CLI.start(args)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rspec
4
+ module Lono
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
data/lib/rspec/lono.rb ADDED
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lono/version"
4
+
5
+ require "active_support"
6
+ require "active_support/core_ext/class"
7
+ require "active_support/core_ext/hash"
8
+ require "active_support/core_ext/string"
9
+ require "memoist"
10
+ require "rainbow/ext/string"
11
+
12
+ require_relative "lono/autoloader"
13
+ RSpec::Lono::Autoloader.setup
14
+
15
+ module RSpec
16
+ module Lono
17
+ class Error < StandardError; end
18
+ extend Core
19
+ end
20
+ end
21
+
22
+ require "lono"
23
+
24
+ Lono::Plugin::Tester.register("rspec",
25
+ root: File.expand_path("../..", __dir__)
26
+ )
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format documentation
3
+ --require spec_helper
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "lono", path: "~/boltops-tools/lono" # '~> #{Lono::VERSION}'
4
+ gem "rspec-lono", path: "~/boltops-tools/rspec-lono"
@@ -0,0 +1,18 @@
1
+ describe "<%= name %>" do
2
+ before(:all) do
3
+ harness.build # built at: /tmp/lono/test-harnesses/<%= name %>
4
+ lono.up
5
+ end
6
+ after(:all) do
7
+ lono.down
8
+ end
9
+
10
+ it "successful deploy" do
11
+ # Replace with your own test
12
+ expect(true).to be true
13
+ # Example
14
+ # pp lono.outputs
15
+ # output_value = lono.outputs["LogicalId"]
16
+ # expect(output_value).to include("demo-test-")
17
+ end
18
+ end
@@ -0,0 +1,2 @@
1
+ # Declare your params here. IE:
2
+ # Key1=Value1
@@ -0,0 +1,2 @@
1
+ # Declare your vars here. IE:
2
+ # @var1 = "value1"
@@ -0,0 +1,14 @@
1
+ ENV["LONO_TEST"] = "1"
2
+ ENV["LONO_ENV"] = "test"
3
+
4
+ require "lono"
5
+ require "rspec/lono"
6
+
7
+ module Helper
8
+ # Your code goes here
9
+ end
10
+
11
+ RSpec.configure do |c|
12
+ c.include RSpec::Lono::Helpers
13
+ c.include Helper
14
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/rspec/lono/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "rspec-lono"
7
+ spec.version = Rspec::Lono::VERSION
8
+ spec.authors = ["Tung Nguyen"]
9
+ spec.email = ["tongueroo@gmail.com"]
10
+
11
+ spec.summary = "Lono RSpec support"
12
+ spec.homepage = "https://github.com/boltops-tools/rspec-lono"
13
+ spec.license = "Apache-2.0"
14
+ spec.required_ruby_version = ">= 2.6.0"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/boltops-tools/rspec-lono"
18
+ spec.metadata["changelog_uri"] = "https://github.com/boltops-tools/rspec-lono/blob/master/CHANGELOG.md"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject do |f|
24
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
25
+ end
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_dependency "activesupport"
32
+ spec.add_dependency "memoist"
33
+ spec.add_dependency "rainbow"
34
+ spec.add_dependency "zeitwerk"
35
+ spec.add_dependency "rspec"
36
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-lono
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tung Nguyen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-02-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: memoist
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rainbow
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: zeitwerk
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - tongueroo@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".rspec"
91
+ - CHANGELOG.md
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - lib/rspec/lono.rb
97
+ - lib/rspec/lono/autoloader.rb
98
+ - lib/rspec/lono/concerns.rb
99
+ - lib/rspec/lono/concerns/logging.rb
100
+ - lib/rspec/lono/core.rb
101
+ - lib/rspec/lono/detector.rb
102
+ - lib/rspec/lono/harness.rb
103
+ - lib/rspec/lono/harness/project.rb
104
+ - lib/rspec/lono/helpers.rb
105
+ - lib/rspec/lono/runner.rb
106
+ - lib/rspec/lono/runner/concerns.rb
107
+ - lib/rspec/lono/version.rb
108
+ - lib/templates/blueprint/test/.rspec
109
+ - lib/templates/blueprint/test/Gemfile.tt
110
+ - lib/templates/blueprint/test/spec/blueprint_spec.rb.tt
111
+ - lib/templates/blueprint/test/spec/fixtures/params/test.txt
112
+ - lib/templates/blueprint/test/spec/fixtures/vars/test.rb
113
+ - lib/templates/blueprint/test/spec/spec_helper.rb
114
+ - rspec-lono.gemspec
115
+ homepage: https://github.com/boltops-tools/rspec-lono
116
+ licenses:
117
+ - Apache-2.0
118
+ metadata:
119
+ homepage_uri: https://github.com/boltops-tools/rspec-lono
120
+ source_code_uri: https://github.com/boltops-tools/rspec-lono
121
+ changelog_uri: https://github.com/boltops-tools/rspec-lono/blob/master/CHANGELOG.md
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: 2.6.0
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubygems_version: 3.2.32
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Lono RSpec support
141
+ test_files: []