cloudformation_rspec 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +9 -5
- data/Dockerfile.ci +10 -0
- data/cloudformation-rspec.gemspec +1 -1
- data/lib/cloudformation_rspec/matchers/validate.rb +26 -2
- data/spec/fixtures/invalid_lint_template.json +20 -0
- data/spec/fixtures/template_with_compile_parameters.rb +7 -0
- data/spec/fixtures/valid_sparkle_vpc_template.rb +1 -1
- data/spec/matchers/validate_spec.rb +11 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a073315a283411eaed933a0eb0e4eb51d3f87496e40e1f07673a94e6a2b6536c
|
4
|
+
data.tar.gz: 86dd0c5ca39eb1eb9f97c91e10194c71086cb231fb5b6127ce2241973af47b03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a61097b4245128ba048d275f3244c04deafff180f3503cdd38b43bf4b3e35db89eecabfc88989aa422b568e69a511f1df978acabf2ecf7ee0ecf018f61a19996
|
7
|
+
data.tar.gz: 60f7bade60799bb6d8ed94ebe312fdc5cb3f0195294e2200978b45d7e57d16424aeecb28e81b75ae57c22b47f13a0ff096bf151bb156612d97b29415145e9bce
|
data/.travis.yml
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
language: ruby
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
|
3
|
+
services:
|
4
|
+
- docker
|
5
|
+
|
6
|
+
before_install:
|
7
|
+
- docker build -t cloudformation_rspec -f Dockerfile.ci .
|
8
|
+
|
9
|
+
script:
|
10
|
+
- docker run cloudformation_rspec /bin/sh -c "bundle exec rake spec"
|
data/Dockerfile.ci
ADDED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'aws-sdk-cloudformation'
|
2
|
+
require 'open3'
|
2
3
|
|
3
4
|
module CloudFormationRSpec::Matchers::Validate
|
4
5
|
def validate_cf_template(template_body)
|
@@ -11,12 +12,35 @@ module CloudFormationRSpec::Matchers::Validate
|
|
11
12
|
end
|
12
13
|
true
|
13
14
|
end
|
15
|
+
|
16
|
+
def lint_cf_template(template_body)
|
17
|
+
# Issue a warning if cfn-lint is not installed, but pass the test
|
18
|
+
unless cfn_lint_available
|
19
|
+
warn "Failed to run cfn-lint, do you have it installed and available in $PATH?"
|
20
|
+
return true
|
21
|
+
end
|
22
|
+
|
23
|
+
Tempfile.open(['cfn-lint', '.json']) do |f|
|
24
|
+
f.write(template_body)
|
25
|
+
f.flush
|
26
|
+
stdout, _stderr, status = Open3.capture3('cfn-lint', '-i', 'W', '--', f.path)
|
27
|
+
if status.exitstatus != 0
|
28
|
+
@error = stdout
|
29
|
+
end
|
30
|
+
status.exitstatus == 0
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def cfn_lint_available
|
35
|
+
_, _, status = Open3.capture3('cfn-lint', '-l')
|
36
|
+
status.exitstatus == 0
|
37
|
+
end
|
14
38
|
end
|
15
39
|
|
16
40
|
RSpec::Matchers.define :be_valid do
|
17
41
|
include CloudFormationRSpec::Matchers::Validate
|
18
42
|
match do |cf_template|
|
19
|
-
validate_cf_template(cf_template)
|
43
|
+
validate_cf_template(cf_template) && lint_cf_template(cf_template)
|
20
44
|
end
|
21
45
|
|
22
46
|
failure_message do
|
@@ -39,7 +63,7 @@ RSpec::Matchers.define :be_valid_sparkleformation do
|
|
39
63
|
@error = error
|
40
64
|
return false
|
41
65
|
end
|
42
|
-
validate_cf_template(template_body)
|
66
|
+
validate_cf_template(template_body) && lint_cf_template(template_body)
|
43
67
|
end
|
44
68
|
|
45
69
|
failure_message do
|
@@ -0,0 +1,20 @@
|
|
1
|
+
{
|
2
|
+
"AWSTemplateFormatVersion" : "2010-09-09",
|
3
|
+
"Resources" : {
|
4
|
+
"myVPC" : {
|
5
|
+
"Type" : "AWS::EC2::VPC",
|
6
|
+
"Properties" : {
|
7
|
+
"CidrBlock" : 1,
|
8
|
+
"EnableDnsSupport" : [],
|
9
|
+
"EnableDnsHostnames" : [],
|
10
|
+
"InstanceTenancy" : {},
|
11
|
+
"Tags" : [ {"Key" : "foo", "Value" : "bar"} ]
|
12
|
+
}
|
13
|
+
}
|
14
|
+
},
|
15
|
+
"Outputs" : {
|
16
|
+
"VpcId": {
|
17
|
+
"Value": {"Ref": "myVPC"}
|
18
|
+
}
|
19
|
+
}
|
20
|
+
}
|
@@ -13,4 +13,11 @@ SparkleFormation.new(:vpc,
|
|
13
13
|
constraint_description 'CIDR block parameter must be in the form x.x.x.x/16-28'
|
14
14
|
default state!(:vpc_cidr)
|
15
15
|
end
|
16
|
+
|
17
|
+
resources.vpc do
|
18
|
+
type "AWS::EC2::VPC"
|
19
|
+
properties do
|
20
|
+
cidr_block ref!(:vpc_cidr)
|
21
|
+
end
|
22
|
+
end
|
16
23
|
end
|
@@ -26,6 +26,17 @@ describe 'be_valid' do
|
|
26
26
|
expect(template).not_to be_valid
|
27
27
|
end
|
28
28
|
end
|
29
|
+
|
30
|
+
context "the stack fails linting" do
|
31
|
+
let(:template) { File.join('spec', 'fixtures', 'invalid_lint_template.json') }
|
32
|
+
before do
|
33
|
+
allow(cf_stub).to receive(:validate_template)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'succeeds' do
|
37
|
+
expect(template).not_to be_valid
|
38
|
+
end
|
39
|
+
end
|
29
40
|
end
|
30
41
|
|
31
42
|
describe 'be_valid_sparkleformation' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudformation_rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Robinson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -75,6 +75,7 @@ extra_rdoc_files: []
|
|
75
75
|
files:
|
76
76
|
- ".travis.yml"
|
77
77
|
- CODE_OF_CONDUCT.md
|
78
|
+
- Dockerfile.ci
|
78
79
|
- Gemfile
|
79
80
|
- LICENSE.md
|
80
81
|
- README.md
|
@@ -89,6 +90,7 @@ files:
|
|
89
90
|
- lib/cloudformation_rspec/resource_change.rb
|
90
91
|
- lib/cloudformation_rspec/sparkle.rb
|
91
92
|
- spec/change_set_spec.rb
|
93
|
+
- spec/fixtures/invalid_lint_template.json
|
92
94
|
- spec/fixtures/invalid_sparkle_vpc_template.rb
|
93
95
|
- spec/fixtures/template_with_compile_parameters.rb
|
94
96
|
- spec/fixtures/valid_sparkle_vpc_template.rb
|
@@ -117,13 +119,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
119
|
- !ruby/object:Gem::Version
|
118
120
|
version: '0'
|
119
121
|
requirements: []
|
120
|
-
|
121
|
-
rubygems_version: 2.6.11
|
122
|
+
rubygems_version: 3.0.4
|
122
123
|
signing_key:
|
123
124
|
specification_version: 4
|
124
125
|
summary: Test your CloudFormation templates
|
125
126
|
test_files:
|
126
127
|
- spec/change_set_spec.rb
|
128
|
+
- spec/fixtures/invalid_lint_template.json
|
127
129
|
- spec/fixtures/invalid_sparkle_vpc_template.rb
|
128
130
|
- spec/fixtures/template_with_compile_parameters.rb
|
129
131
|
- spec/fixtures/valid_sparkle_vpc_template.rb
|