lono 3.5.0 → 4.0.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.
Files changed (186) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +15 -4
  3. data/.rspec +1 -0
  4. data/CHANGELOG.md +15 -1
  5. data/Gemfile +3 -3
  6. data/Guardfile +17 -8
  7. data/{LICENSE → LICENSE.txt} +1 -1
  8. data/README.md +20 -12
  9. data/Rakefile +1 -2
  10. data/{bin → exe}/lono +1 -0
  11. data/lib/lono.rb +12 -9
  12. data/lib/lono/cfn.rb +7 -9
  13. data/lib/lono/cfn/{aws_services.rb → aws_service.rb} +1 -1
  14. data/lib/lono/cfn/base.rb +41 -38
  15. data/lib/lono/cfn/create.rb +6 -2
  16. data/lib/lono/cfn/delete.rb +2 -2
  17. data/lib/lono/cfn/diff.rb +1 -1
  18. data/lib/lono/cfn/preview.rb +26 -15
  19. data/lib/lono/cfn/update.rb +11 -9
  20. data/lib/lono/cfn/util.rb +3 -3
  21. data/lib/lono/clean.rb +1 -1
  22. data/lib/lono/cli.rb +71 -39
  23. data/lib/lono/command.rb +42 -18
  24. data/lib/lono/completer.rb +162 -0
  25. data/lib/lono/completer/script.rb +6 -0
  26. data/lib/lono/completer/script.sh +10 -0
  27. data/lib/lono/completion.rb +15 -0
  28. data/lib/lono/core.rb +23 -9
  29. data/lib/lono/core/config.rb +20 -0
  30. data/lib/lono/default/settings.yml +33 -13
  31. data/lib/lono/help.rb +6 -79
  32. data/lib/lono/help/cfn.md +6 -0
  33. data/lib/lono/help/cfn/create.md +22 -0
  34. data/lib/lono/help/cfn/delete.md +5 -0
  35. data/lib/lono/help/cfn/diff.md +5 -0
  36. data/lib/lono/help/cfn/download.md +5 -0
  37. data/lib/lono/help/cfn/preview.md +11 -0
  38. data/lib/lono/help/cfn/update.md +21 -0
  39. data/lib/lono/help/completion.md +22 -0
  40. data/lib/lono/help/completion_script.md +3 -0
  41. data/lib/lono/help/generate.md +7 -0
  42. data/lib/lono/help/hello.md +5 -0
  43. data/lib/lono/help/import.md +7 -0
  44. data/lib/lono/help/inspect.md +4 -0
  45. data/lib/lono/help/inspect/depends.md +3 -0
  46. data/lib/lono/help/inspect/summary.md +3 -0
  47. data/lib/lono/help/new.md +8 -0
  48. data/lib/lono/help/param.md +3 -0
  49. data/lib/lono/{param/help.rb → help/param/generate.md} +1 -9
  50. data/lib/lono/help/script/build.md +5 -0
  51. data/lib/lono/help/script/upload.md +8 -0
  52. data/lib/lono/help/template.md +4 -0
  53. data/lib/lono/help/template/bashify.md +4 -0
  54. data/lib/lono/help/template/generate.md +7 -0
  55. data/lib/lono/help/user_data.md +3 -0
  56. data/lib/lono/importer.rb +43 -20
  57. data/lib/lono/inspector.rb +2 -19
  58. data/lib/lono/inspector/base.rb +2 -2
  59. data/lib/lono/inspector/{depends.rb → graph.rb} +3 -3
  60. data/lib/lono/inspector/summary.rb +1 -1
  61. data/lib/lono/new.rb +79 -26
  62. data/lib/lono/new/helper.rb +16 -0
  63. data/lib/lono/new/message.rb +35 -0
  64. data/lib/lono/param.rb +1 -2
  65. data/lib/lono/param/generator.rb +34 -86
  66. data/lib/lono/project_checker.rb +35 -40
  67. data/lib/lono/script.rb +19 -0
  68. data/lib/lono/script/base.rb +9 -0
  69. data/lib/lono/script/build.rb +73 -0
  70. data/lib/lono/script/upload.rb +81 -0
  71. data/lib/lono/sequence.rb +33 -0
  72. data/lib/lono/setting.rb +83 -0
  73. data/lib/lono/template.rb +8 -9
  74. data/lib/lono/template/{aws_services.rb → aws_service.rb} +1 -1
  75. data/lib/lono/template/context.rb +73 -0
  76. data/lib/lono/template/dsl.rb +63 -64
  77. data/lib/lono/template/helper.rb +201 -0
  78. data/lib/lono/template/template.rb +29 -221
  79. data/lib/lono/template/upload.rb +41 -33
  80. data/lib/lono/upgrade4.rb +175 -0
  81. data/lib/lono/user_data.rb +31 -0
  82. data/lib/lono/version.rb +1 -1
  83. data/lib/starter_projects/autoscaling/.gitignore +1 -0
  84. data/lib/starter_projects/{json_project → autoscaling}/Gemfile +0 -0
  85. data/lib/starter_projects/{yaml_project → autoscaling}/Guardfile +0 -0
  86. data/lib/starter_projects/autoscaling/README.md +118 -0
  87. data/lib/starter_projects/autoscaling/app/definitions/base.rb +2 -0
  88. data/lib/starter_projects/autoscaling/app/templates/autoscaling.yml +682 -0
  89. data/lib/starter_projects/autoscaling/config/params/base/autoscaling.txt +6 -0
  90. data/lib/starter_projects/autoscaling/config/settings.yml +33 -0
  91. data/lib/starter_projects/ec2/.gitignore +1 -0
  92. data/lib/starter_projects/{yaml_project → ec2}/Gemfile +0 -0
  93. data/lib/starter_projects/{json_project → ec2}/Guardfile +1 -1
  94. data/lib/starter_projects/ec2/README.md +86 -0
  95. data/lib/starter_projects/ec2/app/definitions/base.rb +2 -0
  96. data/lib/starter_projects/ec2/app/definitions/development.rb +1 -0
  97. data/lib/starter_projects/ec2/app/definitions/production.rb +1 -0
  98. data/lib/starter_projects/{yaml_project → ec2/app}/helpers/my_custom_helper.rb +0 -0
  99. data/lib/starter_projects/{json_project/templates/user_data/app.sh → ec2/app/partials/user_data/bootstrap.sh} +1 -2
  100. data/lib/starter_projects/{yaml_project → ec2/app}/templates/example.yml +0 -0
  101. data/lib/starter_projects/{json_project/params/base/api-web.txt → ec2/config/params/base/example.txt} +0 -0
  102. data/lib/starter_projects/ec2/config/params/development/example.txt +3 -0
  103. data/lib/starter_projects/ec2/config/params/production/example.txt +2 -0
  104. data/lib/starter_projects/ec2/config/settings.yml +33 -0
  105. data/lib/starter_projects/ec2/config/variables/base.rb +3 -0
  106. data/lib/starter_projects/ec2/config/variables/development.rb +2 -0
  107. data/lib/starter_projects/ec2/config/variables/production.rb +2 -0
  108. data/lib/starter_projects/ec2/welcome.txt +8 -0
  109. data/lib/starter_projects/skeleton/.gitignore +1 -0
  110. data/lib/starter_projects/skeleton/Gemfile +3 -0
  111. data/lib/starter_projects/skeleton/Guardfile +12 -0
  112. data/lib/starter_projects/skeleton/README.md +53 -0
  113. data/{spec/fixtures/my_project/templates/.gitkeep → lib/starter_projects/skeleton/app/definitions/base.rb} +0 -0
  114. data/lib/starter_projects/skeleton/config/settings.yml +33 -0
  115. data/lib/starter_projects/skeleton/welcome.txt +7 -0
  116. data/lono.gemspec +12 -10
  117. data/spec/fixtures/lono_project/.gitignore +1 -0
  118. data/spec/fixtures/lono_project/Gemfile +3 -0
  119. data/spec/fixtures/lono_project/Guardfile +12 -0
  120. data/spec/fixtures/lono_project/app/definitions/base.rb +10 -0
  121. data/spec/fixtures/lono_project/app/definitions/base/more.rb +7 -0
  122. data/spec/fixtures/lono_project/app/definitions/development.rb +1 -0
  123. data/spec/fixtures/lono_project/app/definitions/production.rb +1 -0
  124. data/spec/fixtures/lono_project/app/helpers/custom_helper.rb +5 -0
  125. data/spec/fixtures/lono_project/app/partials/security_group.yml +10 -0
  126. data/{lib/starter_projects/yaml_project/templates/partial → spec/fixtures/lono_project/app/partials}/user_data/bootstrap.sh +8 -2
  127. data/spec/fixtures/lono_project/app/templates/example.yml +50 -0
  128. data/{lib/starter_projects/yaml_project/params/base/api-web-prod.txt → spec/fixtures/lono_project/config/params/base/example.txt} +1 -0
  129. data/spec/fixtures/lono_project/config/params/development/example.txt +1 -0
  130. data/spec/fixtures/lono_project/config/params/production/example.txt +1 -0
  131. data/spec/fixtures/lono_project/config/settings.yml +31 -0
  132. data/spec/fixtures/lono_project/config/variables/base.rb +3 -0
  133. data/spec/fixtures/lono_project/config/variables/development.rb +1 -0
  134. data/spec/fixtures/lono_project/config/variables/production.rb +1 -0
  135. data/spec/fixtures/params/envonly/params/{prod → development}/network.txt +0 -0
  136. data/spec/fixtures/params/overlay/params/{prod → development}/network.txt +0 -0
  137. data/spec/fixtures/raw_templates/aws-waf-security-automations.template +2 -2
  138. data/spec/lib/lono/cfn_spec.rb +6 -9
  139. data/spec/lib/lono/cli_spec.rb +44 -0
  140. data/spec/lib/lono/completion_spec.rb +17 -0
  141. data/spec/lib/lono/inspect_spec.rb +6 -15
  142. data/spec/lib/lono/param/generator_spec.rb +45 -26
  143. data/spec/lib/lono/param_spec.rb +1 -3
  144. data/spec/lib/lono/setting_spec.rb +47 -0
  145. data/spec/lib/lono/template/dsl_spec.rb +33 -157
  146. data/spec/lib/lono/template_spec.rb +4 -16
  147. data/spec/spec_helper.rb +45 -14
  148. metadata +168 -82
  149. data/.coveralls.yml +0 -1
  150. data/lib/lono/cfn/help.rb +0 -103
  151. data/lib/lono/current_region.rb +0 -42
  152. data/lib/lono/inspector/help.rb +0 -21
  153. data/lib/lono/settings.rb +0 -45
  154. data/lib/lono/template/help.rb +0 -25
  155. data/lib/lono/template/helpers.rb +0 -136
  156. data/lib/starter_projects/json_project/.gitignore +0 -1
  157. data/lib/starter_projects/json_project/config/templates/base/blog.rb +0 -20
  158. data/lib/starter_projects/json_project/config/templates/base/stacks.rb +0 -58
  159. data/lib/starter_projects/json_project/templates/db.json +0 -212
  160. data/lib/starter_projects/json_project/templates/partial/host_record.json +0 -28
  161. data/lib/starter_projects/json_project/templates/partial/server.json +0 -45
  162. data/lib/starter_projects/json_project/templates/user_data/db.sh +0 -39
  163. data/lib/starter_projects/json_project/templates/user_data/db2.sh +0 -2
  164. data/lib/starter_projects/json_project/templates/user_data/ruby_script.rb +0 -5
  165. data/lib/starter_projects/json_project/templates/web.json +0 -386
  166. data/lib/starter_projects/yaml_project/.gitignore +0 -1
  167. data/lib/starter_projects/yaml_project/config/templates/base/blog.rb +0 -20
  168. data/lib/starter_projects/yaml_project/config/templates/base/stacks.rb +0 -56
  169. data/lib/starter_projects/yaml_project/config/templates/prod/stacks.rb +0 -1
  170. data/lib/starter_projects/yaml_project/config/templates/stag/stacks.rb +0 -1
  171. data/lib/starter_projects/yaml_project/config/variables/base/variables.rb +0 -4
  172. data/lib/starter_projects/yaml_project/config/variables/prod/variables.rb +0 -1
  173. data/lib/starter_projects/yaml_project/config/variables/stag/variables.rb +0 -1
  174. data/lib/starter_projects/yaml_project/params/base/example.txt +0 -2
  175. data/lib/starter_projects/yaml_project/params/prod/example.txt +0 -1
  176. data/lib/starter_projects/yaml_project/params/stag/example.txt +0 -1
  177. data/lib/starter_projects/yaml_project/templates/db.yml +0 -148
  178. data/lib/starter_projects/yaml_project/templates/partial/host_record.yml +0 -14
  179. data/lib/starter_projects/yaml_project/templates/partial/server.yml +0 -59
  180. data/lib/starter_projects/yaml_project/templates/web.yml +0 -206
  181. data/spec/fixtures/my_project/config/templates/base/stacks.rb +0 -3
  182. data/spec/fixtures/my_project/params/my-stack.txt +0 -3
  183. data/spec/fixtures/my_project/templates/my-stack.yml +0 -0
  184. data/spec/lib/lono/new_spec.rb +0 -59
  185. data/spec/lib/lono/template/template_spec.rb +0 -104
  186. data/spec/lib/lono_spec.rb +0 -27
@@ -0,0 +1 @@
1
+ # resources that only exist in the development environment
@@ -0,0 +1 @@
1
+ # resources that only exist in the production environment
@@ -0,0 +1,5 @@
1
+ module CustomHelper
2
+ def custom_helper
3
+ "custom_helper value"
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ InstanceSecurityGroup:
2
+ Type: AWS::EC2::SecurityGroup
3
+ Properties:
4
+ GroupDescription: <%= @desc %>
5
+ SecurityGroupIngress:
6
+ - IpProtocol: tcp
7
+ FromPort: <%= @port %>
8
+ ToPort: <%= @port %>
9
+ CidrIp:
10
+ Ref: SSHLocation
@@ -1,5 +1,11 @@
1
1
  #!/bin/bash -lexv
2
- <% stack_name = "#{@app}-#{@role}-#{@env}" -%>
2
+
3
3
  exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
4
- echo <%= stack_name %> > /tmp/stack_name
4
+
5
+ # Lono.env=<%= Lono.env %>
6
+ # override_test=<%= @override_test %>
7
+ # self=<%= self.inspect %>
8
+
5
9
  cat /proc/uptime | cut -f1 -d'.' > /tmp/time-to-boot
10
+
11
+
@@ -0,0 +1,50 @@
1
+ ---
2
+ AWSTemplateFormatVersion: '2010-09-09'
3
+ Description: 'AWS CloudFormation Sample Template. A fixture for testing only. @_name: <%= @_name %>'
4
+ Parameters:
5
+ KeyName:
6
+ Description: Name of an existing EC2 KeyPair for SSH. <%= custom_helper %>
7
+ Type: AWS::EC2::KeyPair::KeyName
8
+ ConstraintDescription: must be the name of an existing EC2 KeyPair.
9
+ <% if @route53 %>
10
+ HostedZoneName:
11
+ Description: The route53 HostedZoneName. For example, "mydomain.com." Don't forget the period at the end.
12
+ Type: String
13
+ Subdomain:
14
+ Description: The subdomain of the dns entry. For example, hello -> hello.mydomain.com, hello is the subdomain.
15
+ Type: String
16
+ <% end %>
17
+ Resources:
18
+ EC2Instance:
19
+ Type: AWS::EC2::Instance
20
+ Properties:
21
+ InstanceType:
22
+ Ref: InstanceType
23
+ SecurityGroups:
24
+ - Ref: InstanceSecurityGroup
25
+ KeyName:
26
+ Ref: KeyName
27
+ UserData:
28
+ Fn::Base64: !Sub |
29
+ <%= partial("user_data/bootstrap.sh", {}, indent: 10) %>
30
+ ImageId:
31
+ Fn::FindInMap:
32
+ - AWSRegionArch2AMI
33
+ - Ref: AWS::Region
34
+ - Fn::FindInMap:
35
+ - AWSInstanceType2Arch
36
+ - Ref: InstanceType
37
+ - Arch
38
+ <%= partial("security_group", desc: "Enable SSH access via port 22", port: "22") %>
39
+ <% if @route53 %>
40
+ DnsRecord:
41
+ Type: AWS::Route53::RecordSet
42
+ Properties:
43
+ HostedZoneName: !Ref 'HostedZoneName'
44
+ Comment: DNS name for my instance.
45
+ Name: !Join ['', [!Ref 'Subdomain', ., !Ref 'HostedZoneName']]
46
+ Type: CNAME
47
+ TTL: '900'
48
+ ResourceRecords:
49
+ - !GetAtt EC2Instance.PublicIp
50
+ <% end %>
@@ -0,0 +1 @@
1
+ InstanceType=t2.small
@@ -0,0 +1 @@
1
+ InstanceType=t2.large
@@ -0,0 +1,31 @@
1
+ # More info: http://lono.cloud/docs/settings/
2
+ # The base config is specially treated. It gets included the other environments automatically.
3
+ # Yaml also directly supports merging with & and <<* syntax but doing it automatically
4
+ # for a cleaner syntax.
5
+ base:
6
+ # If s3_folder is set then the generated templates and app/scripts will automatically
7
+ # be uploaded to s3.
8
+ # There are 2 formats for s3_folder:
9
+ # Format 1:
10
+ # s3_folder: mybucket/path/to/folder # simple string
11
+ # Format 2:
12
+ # s3_folder: # Hash options in order to support different AWS_PROFILEs
13
+ # default: mybucket/folder
14
+ # aws_profile1: mybucket/folder
15
+ # aws_profile2: another-bucket/storage/folder
16
+ # randomize_stack_name: true # tack on a 3 char random string at the end of the stack name
17
+ # for lono cfn create
18
+
19
+ development:
20
+ # cluster: dev
21
+ # When you have AWS_PROFILE set to one of these values, ufo will switch to the desired
22
+ # environment. This prevents you from switching AWS_PROFILE, forgetting to
23
+ # also switch UFO_ENV, and accidentally deploying to production vs development.
24
+ # aws_profiles:
25
+ # - dev_profile1
26
+ # - dev_profile2
27
+
28
+ production:
29
+ # cluster: prod
30
+ # aws_profiles:
31
+ # - prod_profile
@@ -0,0 +1,3 @@
1
+ @ami = "ami-base-main"
2
+ @base_only = "base-only-test"
3
+ @override_test = "overridden-by-env-specific-variable"
@@ -0,0 +1 @@
1
+ @override_test = "overridden-by-development"
@@ -0,0 +1 @@
1
+ @override_test = "overridden-by-production"
@@ -10,12 +10,12 @@
10
10
  "Parameters": ["SqlInjectionProtectionParam", "CrossSiteScriptingProtectionParam", "ActivateHttpFloodProtectionParam", "ActivateScansProbesProtectionParam", "ActivateReputationListsProtectionParam", "ActivateBadBotProtectionParam"]
11
11
  }, {
12
12
  "Label": {
13
- "default": "Settings"
13
+ "default": "Setting"
14
14
  },
15
15
  "Parameters": ["CloudFrontAccessLogBucket"]
16
16
  }, {
17
17
  "Label": {
18
- "default": "Advanced Settings"
18
+ "default": "Advanced Setting"
19
19
  },
20
20
  "Parameters": ["RequestThreshold", "ErrorThreshold", "WAFBlockPeriod"]
21
21
  }, {
@@ -1,39 +1,36 @@
1
- require "spec_helper"
2
-
3
1
  describe Lono::Cfn do
4
2
  before(:all) do
5
- @env = "LONO_ROOT=#{ENV['LONO_ROOT']}"
6
3
  @args = "--noop"
7
4
  end
8
5
 
9
6
  describe "lono cfn" do
10
7
  it "create stack" do
11
- out = execute("#{@env} bin/lono cfn create my-stack #{@args}")
8
+ out = execute("#{@env} exe/lono cfn create example #{@args}")
12
9
  expect(out).to include("Creating")
13
10
  end
14
11
 
15
12
  it "update stack" do
16
- out = execute("#{@env} bin/lono cfn update my-stack #{@args}")
13
+ out = execute("#{@env} exe/lono cfn update example #{@args}")
17
14
  expect(out).to include("Updating")
18
15
  end
19
16
 
20
17
  it "delete stack" do
21
- out = execute("#{@env} bin/lono cfn delete my-stack #{@args}")
18
+ out = execute("#{@env} exe/lono cfn delete example #{@args}")
22
19
  expect(out).to include("Deleted")
23
20
  end
24
21
 
25
22
  it "preview stack" do
26
- out = execute("#{@env} bin/lono cfn preview my-stack #{@args}")
23
+ out = execute("#{@env} exe/lono cfn preview example #{@args}")
27
24
  expect(out).to include("CloudFormation preview")
28
25
  end
29
26
 
30
27
  it "diff stack" do
31
- out = execute("#{@env} bin/lono cfn diff my-stack #{@args}")
28
+ out = execute("#{@env} exe/lono cfn diff example #{@args}")
32
29
  expect(out).to include("diff")
33
30
  end
34
31
 
35
32
  it "download stack" do
36
- out = execute("#{@env} bin/lono cfn download my-stack #{@args}")
33
+ out = execute("#{@env} exe/lono cfn download example #{@args}")
37
34
  expect(out).to include("Download")
38
35
  end
39
36
  end
@@ -0,0 +1,44 @@
1
+ describe Lono::CLI do
2
+ context "general" do
3
+ it "new generate new project" do
4
+ # using another name for the lono project because we call
5
+ # exe/lono new lono_project for all specs via the RSpec.config already
6
+ # NOTE: LONO_ROOT modified in the spec_helper.rb
7
+ execute("exe/lono new test_project --no-bundle")
8
+ exist = File.exist?("tmp/test_project/config/settings.yml")
9
+ expect(exist).to be true
10
+ FileUtils.rm_rf("tmp/test_project")
11
+ end
12
+
13
+ it "import should download template" do
14
+ out = execute("exe/lono import spec/fixtures/raw_templates/aws-waf-security-automations.template --name waf")
15
+ expect(out).to match(/=> Imported CloudFormation template/)
16
+ end
17
+ end
18
+
19
+ # Ensure the example starter project is always able to produce output/templates.
20
+ context "project generated from lono new command" do
21
+ before(:all) do
22
+ # hack to so we don't have to change LONO_ROOT
23
+ @project = ENV['LONO_ROOT']
24
+ FileUtils.mv(@project, "#{@project}.temp") if File.exist?(@project)
25
+ end
26
+ after(:all) do
27
+ FileUtils.rm_rf(@project)
28
+ # move temp back for the rest of the tests
29
+ FileUtils.mv("#{@project}.temp", @project) if File.exist?("#{@project}.temp")
30
+ end
31
+
32
+ it "generate should build templates" do
33
+ # NOTE: LONO_ROOT modified in the spec_helper.rb
34
+ execute("exe/lono new lono_project --no-bundle")
35
+ execute("exe/lono generate")
36
+ success = $?.exitstatus == 0
37
+ expect(success).to be true
38
+
39
+ exist = File.exist?("#{Lono.root}/config/settings.yml")
40
+ expect(exist).to be true
41
+ end
42
+ end
43
+ end
44
+
@@ -0,0 +1,17 @@
1
+ describe Lono::CLI do
2
+ describe "lono completion" do
3
+ commands = {
4
+ # "new" => "name", # options is the completion because it's a Thor::Group
5
+ "generate" => "--clean",
6
+ "cfn" => "create",
7
+ "cfn create" => "name",
8
+ "param" => "generate",
9
+ }
10
+ commands.each do |command, expected_word|
11
+ it "#{command}" do
12
+ out = execute("exe/lono completion #{command}")
13
+ expect(out).to include(expected_word) # only checking for one word for simplicity
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,20 +1,11 @@
1
- require_relative "../../spec_helper"
2
-
3
1
  describe Lono::Inspector do
4
- before(:all) do
5
- @args = "--noop"
2
+ it "lono xgraph" do
3
+ out = execute("exe/lono xgraph example --noop")
4
+ expect(out).to include("Generating dependencies tree")
6
5
  end
7
6
 
8
- describe "lono inspect" do
9
- it "depends" do
10
- out = execute("bin/lono inspect depends my-stack #{@args}")
11
- expect(out).to include("Generating dependencies tree")
12
- end
13
-
14
- it "summary" do
15
- out = execute("bin/lono inspect summary my-stack #{@args}")
16
- expect(out).to include("Summary")
17
- end
7
+ it "lono summary" do
8
+ out = execute("exe/lono summary example")
9
+ expect(out).to include("Summary")
18
10
  end
19
11
  end
20
-
@@ -1,37 +1,56 @@
1
- require_relative "../../../spec_helper"
2
-
3
1
  describe Lono::Param::Generator do
4
- def generate(project_root)
5
- @saved_root = ENV['LONO_ROOT']
6
- ENV['LONO_ROOT'] = project_root
7
- param = Lono::Param::Generator.new("network",
8
- mute: true
9
- )
10
- json = param.generate
11
- ENV['LONO_ROOT'] = @saved_root
2
+ context "layering" do
3
+ def generate(context)
4
+ path = "spec/fixtures/params/#{context}/params/development/network.txt"
5
+ param = Lono::Param::Generator.new("network",
6
+ path: path,
7
+ mute: true,
8
+ )
9
+ json = param.generate
10
+ data = JSON.load(json)
11
+ param_value = data.first["ParameterValue"]
12
+ end
12
13
 
13
- data = JSON.load(json)
14
- param_value = data.first["ParameterValue"]
15
- end
14
+ context "overlay params" do
15
+ it "should combine params" do
16
+ param_value = generate("overlay")
17
+ expect(param_value).to eq "2"
18
+ end
19
+ end
16
20
 
17
- context "overlay params" do
18
- it "should combine params" do
19
- param_value = generate("spec/fixtures/params/overlay")
20
- expect(param_value).to eq "2"
21
+ context "only base param" do
22
+ it "should generate prod param from base param" do
23
+ param_value = generate("baseonly")
24
+ expect(param_value).to eq "foo"
25
+ end
21
26
  end
22
- end
23
27
 
24
- context "only base param" do
25
- it "should generate prod param from base param" do
26
- param_value = generate("spec/fixtures/params/baseonly")
27
- expect(param_value).to eq "foo"
28
+ context "only env param" do
29
+ it "should generate prod param from env param" do
30
+ param_value = generate("envonly")
31
+ expect(param_value).to eq "bar"
32
+ end
28
33
  end
29
34
  end
30
35
 
31
- context "only env param" do
32
- it "should generate prod param from env param" do
33
- param_value = generate("spec/fixtures/params/envonly")
34
- expect(param_value).to eq "bar"
36
+ # Load the variables defined in config/variables/* to make available the params/*.txt files
37
+ #
38
+ # Example:
39
+ #
40
+ # config/variables/base/variables.rb:
41
+ # @ami = "ami-base-main"
42
+ #
43
+ # params/base/example.txt:
44
+ # Ami=<%= @ami %>
45
+ #
46
+ context "shared variables access" do
47
+ it "should have access to shared variables" do
48
+ # quickest to write test by shelling out
49
+ out = execute("exe/lono generate")
50
+ text = IO.read("#{Lono.root}/output/params/example.json")
51
+ data = JSON.load(text)
52
+ param = data.select { |i| i["ParameterKey"] == "Ami" }.first
53
+ expect(param["ParameterValue"]).to eq "ami-base-main"
35
54
  end
36
55
  end
37
56
  end
@@ -1,5 +1,3 @@
1
- require_relative "../../spec_helper"
2
-
3
1
  describe Lono::Param do
4
2
  before(:all) do
5
3
  @args = ""
@@ -7,7 +5,7 @@ describe Lono::Param do
7
5
 
8
6
  describe "lono param" do
9
7
  it "generate" do
10
- out = execute("bin/lono param generate #{@args}")
8
+ out = execute("exe/lono param generate #{@args}")
11
9
  expect(out).to include("Generating")
12
10
  end
13
11
  end
@@ -0,0 +1,47 @@
1
+ describe Lono::Param::Generator do
2
+ let(:setting) do
3
+ setting = Lono::Setting.new(check_lono_project=false)
4
+ allow(setting).to receive(:data).and_return(data)
5
+ setting
6
+ end
7
+ context "simple string" do
8
+ let(:data) do
9
+ {
10
+ "s3_folder" => "s3-bucket/simple/string/example"
11
+ }
12
+ end
13
+ it "should return simple string value" do
14
+ value = setting.s3_folder
15
+ expect(value).to eq "s3-bucket/simple/string/example"
16
+ end
17
+ end
18
+
19
+ context "options hash" do
20
+ let(:data) do
21
+ {
22
+ "s3_folder" => {
23
+ "default" => "s3-bucket/default/path",
24
+ "aws_profile1" => "s3-bucket/aws_profile1/path",
25
+ }
26
+ }
27
+ end
28
+ it "should return default value when AWS_PROFILE not set" do
29
+ saved = ENV['AWS_PROFILE']
30
+
31
+ value = setting.s3_folder
32
+ expect(value).to eq "s3-bucket/default/path"
33
+
34
+ ENV['AWS_PROFILE'] = saved
35
+ end
36
+
37
+ it "should return AWS_PROFILE value when AWS_PROFILE set" do
38
+ saved = ENV['AWS_PROFILE']
39
+ ENV['AWS_PROFILE'] = "aws_profile1"
40
+
41
+ value = setting.s3_folder
42
+ expect(value).to eq "s3-bucket/aws_profile1/path"
43
+
44
+ ENV['AWS_PROFILE'] = saved
45
+ end
46
+ end
47
+ end