lono 4.2.1 → 4.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +3 -0
  3. data/lib/lono/version.rb +1 -1
  4. data/lono.gemspec +5 -3
  5. metadata +3 -79
  6. data/spec/fixtures/cfn.json +0 -369
  7. data/spec/fixtures/cfn/stack-events-complete.json +0 -1080
  8. data/spec/fixtures/cfn/stack-events-in-progress.json +0 -1080
  9. data/spec/fixtures/cfn/stack-events-update-rollback-complete.json +0 -1086
  10. data/spec/fixtures/lono_project/.gitignore +0 -1
  11. data/spec/fixtures/lono_project/Gemfile +0 -3
  12. data/spec/fixtures/lono_project/Guardfile +0 -12
  13. data/spec/fixtures/lono_project/app/definitions/base.rb +0 -10
  14. data/spec/fixtures/lono_project/app/definitions/base/more.rb +0 -7
  15. data/spec/fixtures/lono_project/app/definitions/development.rb +0 -1
  16. data/spec/fixtures/lono_project/app/definitions/production.rb +0 -1
  17. data/spec/fixtures/lono_project/app/helpers/custom_helper.rb +0 -5
  18. data/spec/fixtures/lono_project/app/partials/security_group.yml +0 -10
  19. data/spec/fixtures/lono_project/app/partials/user_data/bootstrap.sh +0 -11
  20. data/spec/fixtures/lono_project/app/templates/example.yml +0 -50
  21. data/spec/fixtures/lono_project/config/params/base/example.txt +0 -3
  22. data/spec/fixtures/lono_project/config/params/development/example.txt +0 -1
  23. data/spec/fixtures/lono_project/config/params/production/example.txt +0 -1
  24. data/spec/fixtures/lono_project/config/settings.yml +0 -31
  25. data/spec/fixtures/lono_project/config/variables/base.rb +0 -3
  26. data/spec/fixtures/lono_project/config/variables/development.rb +0 -1
  27. data/spec/fixtures/lono_project/config/variables/production.rb +0 -1
  28. data/spec/fixtures/params/baseonly/params/base/network.txt +0 -1
  29. data/spec/fixtures/params/envonly/params/development/network.txt +0 -1
  30. data/spec/fixtures/params/overlay/params/base/network.txt +0 -1
  31. data/spec/fixtures/params/overlay/params/development/network.txt +0 -1
  32. data/spec/fixtures/raw_templates/aws-waf-security-automations.template +0 -1575
  33. data/spec/lib/lono/cfn/status_spec.rb +0 -77
  34. data/spec/lib/lono/cfn_spec.rb +0 -38
  35. data/spec/lib/lono/cli_spec.rb +0 -44
  36. data/spec/lib/lono/completion_spec.rb +0 -17
  37. data/spec/lib/lono/inspect_spec.rb +0 -11
  38. data/spec/lib/lono/param/generator_spec.rb +0 -56
  39. data/spec/lib/lono/param_spec.rb +0 -13
  40. data/spec/lib/lono/setting_spec.rb +0 -47
  41. data/spec/lib/lono/template/dsl_spec.rb +0 -59
  42. data/spec/lib/lono/template_spec.rb +0 -21
  43. data/spec/spec_helper.rb +0 -62
@@ -1,77 +0,0 @@
1
- describe Lono::Cfn::Status do
2
- let(:status) do
3
- status = Lono::Cfn::Status.new("test-stack")
4
- allow(status).to receive(:cfn).and_return(cfn)
5
- status
6
- end
7
- let(:cfn) do
8
- service = double("service").as_null_object
9
- allow(service).to receive(:describe_stacks).and_return(stack_status)
10
- allow(service).to receive(:describe_stack_events).and_return(stack_events)
11
- service
12
- end
13
-
14
- context "in progress" do
15
- let(:stack_status) { "UPDATE_IN_PROGRESS" }
16
- let(:stack_events) { JSON.load(IO.read("spec/fixtures/cfn/stack-events-in-progress.json")) }
17
- it "lists events since user initiated event" do
18
- status.refresh_events
19
- i = status.find_index(:start)
20
- expect(i).to eq 15
21
- # uncomment to view and debug
22
- # status.show_events
23
- # puts "****"
24
- # status.show_events # show not show anything
25
- end
26
-
27
- it "lists events since last shown event" do
28
- # first display
29
- status.refresh_events
30
- i = status.find_index(:start)
31
- expect(i).to eq 15
32
-
33
- # move the last event back in time 4 events, so should print 3 events
34
- status.instance_variable_set(:@last_shown_event_id, "TargetGroup-ec634c43-b887-4bde-a525-7c69782865a6")
35
-
36
- captured_events = []
37
- allow(status).to receive(:print_event) do |e|
38
- captured_events << "#{e["resource_type"]} #{e["resource_status"]}"
39
- end
40
- status.show_events
41
- expect(captured_events).to eq([
42
- "AWS::ElasticLoadBalancingV2::LoadBalancer DELETE_IN_PROGRESS",
43
- "AWS::ElasticLoadBalancingV2::LoadBalancer DELETE_COMPLETE",
44
- "AWS::EC2::SecurityGroup DELETE_IN_PROGRESS",
45
- ])
46
- end
47
- end
48
-
49
- context "complete" do
50
- let(:stack_status) { "UPDATE_COMPLETE" }
51
- let(:stack_events) { JSON.load(IO.read("spec/fixtures/cfn/stack-events-complete.json")) }
52
- it "lists events all the way to completion" do
53
- status.refresh_events
54
- i = status.find_index(:start)
55
- expect(i).to eq 17
56
- # uncomment to view and debug
57
- # status.show_events
58
- end
59
- end
60
-
61
- context "update_rollback" do
62
- let(:stack_status) { "UPDATE_ROLLBACK_COMPLETE" }
63
- let(:stack_events) { JSON.load(IO.read("spec/fixtures/cfn/stack-events-update-rollback-complete.json")) }
64
- it "lists events all the way to update rollback complete" do
65
- status.refresh_events
66
- expect(status.success?).to be false
67
- expect(status.update_rollback?).to be true
68
- expect(status.rollback_error_message).to include("STATIC_NAME")
69
-
70
- # i = status.find_index(:start)
71
- # expect(i).to eq 17
72
- # uncomment to view and debug
73
- # status.show_events
74
- end
75
- end
76
- end
77
-
@@ -1,38 +0,0 @@
1
- describe Lono::Cfn do
2
- before(:all) do
3
- @args = "--noop"
4
- end
5
-
6
- describe "lono cfn" do
7
- it "create stack" do
8
- out = execute("#{@env} exe/lono cfn create example #{@args}")
9
- expect(out).to include("Creating")
10
- end
11
-
12
- it "update stack" do
13
- out = execute("#{@env} exe/lono cfn update example #{@args}")
14
- expect(out).to include("Updating")
15
- end
16
-
17
- it "delete stack" do
18
- out = execute("#{@env} exe/lono cfn delete example #{@args}")
19
- expect(out).to include("Deleted")
20
- end
21
-
22
- it "preview stack" do
23
- out = execute("#{@env} exe/lono cfn preview example #{@args}")
24
- expect(out).to include("CloudFormation preview")
25
- end
26
-
27
- it "diff stack" do
28
- out = execute("#{@env} exe/lono cfn diff example #{@args}")
29
- expect(out).to include("diff")
30
- end
31
-
32
- it "download stack" do
33
- out = execute("#{@env} exe/lono cfn download example #{@args}")
34
- expect(out).to include("Download")
35
- end
36
- end
37
- end
38
-
@@ -1,44 +0,0 @@
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
-
@@ -1,17 +0,0 @@
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,11 +0,0 @@
1
- describe Lono::Inspector do
2
- it "lono xgraph" do
3
- out = execute("exe/lono xgraph example --noop")
4
- expect(out).to include("Generating dependencies tree")
5
- end
6
-
7
- it "lono summary" do
8
- out = execute("exe/lono summary example")
9
- expect(out).to include("Summary")
10
- end
11
- end
@@ -1,56 +0,0 @@
1
- describe Lono::Param::Generator do
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
13
-
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
20
-
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
26
- end
27
-
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
33
- end
34
- end
35
-
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"
54
- end
55
- end
56
- end
@@ -1,13 +0,0 @@
1
- describe Lono::Param do
2
- before(:all) do
3
- @args = ""
4
- end
5
-
6
- describe "lono param" do
7
- it "generate" do
8
- out = execute("exe/lono param generate #{@args}")
9
- expect(out).to include("Generating")
10
- end
11
- end
12
- end
13
-
@@ -1,47 +0,0 @@
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
@@ -1,59 +0,0 @@
1
- describe Lono::Template::DSL do
2
- context "tmp/lono_project" do
3
- it "#evaluate_templates" do
4
- dsl = Lono::Template::DSL.new(
5
- quiet: true
6
- )
7
- dsl.evaluate_templates
8
- templates = dsl.instance_variable_get(:@templates)
9
- template_names = templates.map { |h| h[:name] }
10
- expect(template_names).to include("example")
11
- end
12
- end
13
-
14
- context "lono generate" do
15
- before(:each) do
16
- dsl = Lono::Template::DSL.new(quiet: true)
17
- dsl.run
18
- end
19
-
20
- it "should generate cloudformation template" do
21
- template = YAML.load_file("#{Lono.root}/output/templates/example.yml")
22
- expect(template['Description']).to include "AWS CloudFormation Sample Template"
23
- end
24
-
25
- # <%= partial("security_group", desc: "whatever", port: 22)
26
- it "partial local variables become instance variables in partial view" do
27
- template = YAML.load_file("#{Lono.root}/output/templates/example.yml")
28
- desc = template['Resources']['InstanceSecurityGroup']['Properties']['GroupDescription']
29
- expect(desc).to eq 'Enable SSH access via port 22'
30
- end
31
-
32
- it "partials should have access to variables" do
33
- text = IO.read("#{Lono.root}/output/templates/example.yml")
34
- expect(text).to include("override_test=overridden-by-development")
35
- end
36
-
37
- it "should have access to custom helpers" do
38
- text = IO.read("#{Lono.root}/output/templates/example.yml")
39
- expect(text).to include("custom_helper value")
40
- end
41
- end
42
-
43
- context "yaml parse error" do
44
- let(:dsl) do
45
- Lono::Template::DSL.new(quiet: true)
46
- end
47
-
48
- it "show exact line of error code when yaml is invalid" do
49
- IO.write("tmp/bad.yml", <<EOL)
50
- test: 1
51
- foo
52
- test
53
- EOL
54
- out = dsl.validate("tmp/bad.yml")
55
- expect(out).to include("2 foo")
56
- end
57
-
58
- end
59
- end
@@ -1,21 +0,0 @@
1
- describe Lono do
2
- describe "bashify" do
3
- it "should convert cfn user_data to bash script" do
4
- path = "spec/fixtures/cfn.json"
5
- out = execute("exe/lono template bashify #{path}")
6
- expect(out).to match /bash -lexv/
7
- end
8
- end
9
-
10
- describe "cli specs" do
11
- it "should generate templates" do
12
- out = execute("exe/lono template generate --clean")
13
- expect(out).to match /Generating CloudFormation templates/
14
- end
15
-
16
- it "should upload templates" do
17
- out = execute("exe/lono template upload --noop")
18
- expect(out).to match /Templates uploaded to s3/
19
- end
20
- end
21
- end
@@ -1,62 +0,0 @@
1
- ENV['TEST'] = '1'
2
- # Ensures aws api never called. Fixture home folder does not contain ~/.aws/credentails
3
- ENV['HOME'] = "spec/fixtures/home"
4
- # We'll always re-generate a new lono project in tmp. It can be:
5
- #
6
- # 1. copied from spec/fixtures/lono_project
7
- # 2. generated from `lono new`
8
- #
9
- # This is done because changing LONO_ROOT for specs was a mess.
10
- ENV['LONO_ROOT'] = "tmp/lono_project" # this gets kept
11
-
12
- require "pp"
13
- require "byebug"
14
-
15
- # require "bundler"
16
- # Bundler.require(:development)
17
-
18
- root = File.expand_path("../", File.dirname(__FILE__))
19
- require "#{root}/lib/lono"
20
-
21
- module Helper
22
- def execute(cmd)
23
- puts "Running: #{cmd}" if show_command?
24
- out = `#{cmd}`
25
- puts out if show_command?
26
- out
27
- end
28
-
29
- # Added SHOW_COMMAND because DEBUG is also used by other libraries like
30
- # bundler and it shows its internal debugging logging also.
31
- def show_command?
32
- ENV['DEBUG'] || ENV['SHOW_COMMAND']
33
- end
34
-
35
- def ensure_tmp_exists
36
- FileUtils.mkdir_p("tmp")
37
- end
38
-
39
- # Copies spec/fixtures/lono_project to tmp/lono_project,
40
- # Main fixture we'll use because it's faster
41
- def copy_lono_project
42
- destroy_lono_project # just in case KEEP_TMP_PROJECT is used
43
- FileUtils.cp_r("spec/fixtures/lono_project", "tmp/lono_project")
44
- end
45
-
46
- def destroy_lono_project
47
- # Only use KEEP_TMP_PROJECT if you are testing exactly 1 spec for debugging
48
- # or it'll affect other tests.
49
- FileUtils.rm_rf(Lono.root)
50
- end
51
- end
52
-
53
- RSpec.configure do |c|
54
- c.include Helper
55
- c.before(:all) do
56
- ensure_tmp_exists
57
- copy_lono_project
58
- end
59
- c.after(:all) do
60
- destroy_lono_project unless ENV['KEEP_TMP_PROJECT']
61
- end
62
- end