Skip to content

Commit

Permalink
refactoring to better reflect the UI surfaces and simplify support libs
Browse files Browse the repository at this point in the history
  • Loading branch information
pghalliday committed Sep 1, 2015
1 parent 1bd92b1 commit 5c1ece1
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 181 deletions.
74 changes: 20 additions & 54 deletions features/step_definitions/target_configurations_steps.rb
Original file line number Diff line number Diff line change
@@ -1,51 +1,14 @@
include Formatron::Features::Support
include Formatron::Cucumber::Support

Given(/a basic formatron stack definition/) do
@fsd = FormatronStackDefinition.new
Given(/^a Formatron project$/) do
@fp = FormatronProject.new
end

Given(/a prefix of (\w+)/) do |prefix|
@fsd.prefix = prefix
Given(/^a ([^\s]+) file with content$/) do |relative_path, content|
@fp.add_file relative_path, content
end

Given(/a name of (\w+)/) do |name|
@fsd.name = name
end

Given(/a test target name of (\w+)/) do |name|
@fsd.test_target = name
end

Given(/a test configuration parameter of (\w+)/) do |param|
@fsd.test_param = param
end

Given(/a production target name of (\w+)/) do |name|
@fsd.prod_target = name
end

Given(/a production configuration parameter of (\w+)/) do |param|
@fsd.prod_param = param
end

Given(/an S3 bucket of (\w+)/) do |bucket|
@fsd.s3_bucket = bucket
end

Given(/a region of (\w+)/) do |region|
@fsd.region = region
end

Given(/a test kms key of (\w+)/) do |kms_key|
@fsd.test_kms_key = kms_key
end

Given(/a production kms key of (\w+)/) do |kms_key|
@fsd.prod_kms_key = kms_key
end

When(/I deploy the formatron stack with target (\w+)/) do |target|
@target = target
When(/^I deploy the formatron stack with target (\w+)$/) do |target|
@credentials = double
@s3_client = double
allow(@s3_client).to receive(:put_object)
Expand All @@ -55,26 +18,29 @@
allow(Aws::Credentials).to receive(:new) {@credentials}
allow(Aws::S3::Client).to receive(:new) {@s3_client}
allow(Aws::CloudFormation::Client).to receive(:new) {@cloudformation}
@fsd.deploy target
@fp.deploy target
end

Then(/^the region (\w+), AWS access key ID (\w+) and AWS secret access key (\w+) should be used when communicating with AWS$/) do |region, access_key_id, secret_access_key|
expect(Aws::Credentials).to have_received(:new).once.with(
FormatronStackDefinition::Credentials::ACCESS_KEY_ID,
FormatronStackDefinition::Credentials::SECRET_ACCESS_KEY
access_key_id,
secret_access_key
)
expect(Aws::S3::Client).to have_received(:new).once.with(
region: @fsd.region,
region: region,
signature_version: 'v4',
credentials: @credentials
)
expect(Aws::CloudFormation::Client).to have_received(:new).once.with(
region: @fsd.region,
region: region,
credentials: @credentials
)
expect(@s3_client).to have_received(:put_object).twice
expect(@cloudformation).to have_received(:validate_template).once
expect(@cloudformation).to have_received(:create_stack).once
end

Then(/the config should be uploaded to S3 bucket (\w+) with key ([^\s,]+), KMS key (\w+) and content/) do |bucket, key, kms_key, content|
Then(/^the config should be uploaded to S3 bucket (\w+) with key ([^\s,]+), KMS key (\w+) and content$/) do |bucket, key, kms_key, content|
expect(@s3_client).to have_received(:put_object).once.with(
bucket: bucket,
key: key,
Expand All @@ -84,21 +50,21 @@
)
end

Then(/the cloudformation template should be validated/) do
Then(/^the cloudformation template should be validated with content matching ([^\s]+)$/) do |relative_path|
expect(@cloudformation).to have_received(:validate_template).once.with(
template_body: FormatronStackDefinition::Cloudformation::TEMPLATE_JSON
template_body: @fp.files[relative_path]
)
end

Then(/the cloudformation template should be uploaded to S3 bucket (\w+) with key ([^\s]+)/) do |bucket, key|
Then(/^the cloudformation template should be uploaded to S3 bucket (\w+) with key ([^\s]+) and content matching ([^\s]+)$/) do |bucket, key, relative_path|
expect(@s3_client).to have_received(:put_object).once.with(
bucket: bucket,
key: key,
body: FormatronStackDefinition::Cloudformation::TEMPLATE_JSON
body: @fp.files[relative_path]
)
end

Then(/the cloudformation stack should be created with name ([^\s,]+), template url ([^\s]+) and parameter (\w+)/) do |name, url, param|
Then(/^the cloudformation stack should be created with name ([^\s,]+), template url ([^\s]+) and parameter (\w+)/) do |name, url, param|
expect(@cloudformation).to have_received(:create_stack).once.with(
stack_name: name,
template_url: url,
Expand Down
26 changes: 26 additions & 0 deletions features/support/formatron_project.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module Formatron::Cucumber
module Support
class FormatronProject
attr_reader :files

def initialize
@files = {}
end

def add_file(relative_path, content)
@files[relative_path] = content
end

def deploy(target)
Dir.mktmpdir do |dir|
@files.each do |relative_path, content|
path = File.join dir, relative_path
FileUtils.mkdir_p File.dirname(path)
File.write path, content
end
Formatron.new(dir, target).deploy
end
end
end
end
end
29 changes: 0 additions & 29 deletions features/support/formatron_stack_definition.rb

This file was deleted.

31 changes: 0 additions & 31 deletions features/support/formatron_stack_definition/cloudformation.rb

This file was deleted.

18 changes: 0 additions & 18 deletions features/support/formatron_stack_definition/config.rb

This file was deleted.

14 changes: 0 additions & 14 deletions features/support/formatron_stack_definition/credentials.rb

This file was deleted.

17 changes: 0 additions & 17 deletions features/support/formatron_stack_definition/formatronfile.rb

This file was deleted.

81 changes: 63 additions & 18 deletions features/target_configurations.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,64 @@ Feature: Target configurations
- Target specific S3 keys should be properly namespaced

Scenario Outline: deploy a simple stack with only a CloudFormation template
Given a basic formatron stack definition
And a prefix of <prefix>
And a name of <name>
And a test target name of <test target>
And a test configuration parameter of <test parameter>
And a production target name of <production target>
And a production configuration parameter of <production parameter>
And an S3 bucket of <bucket>
And a region of <region>
And a test kms key of <test kms key>
And a production kms key of <production kms key>
Given a Formatron project
And a credentials.json file with content
"""
{
"accessKeyId": "<AWS access key ID>",
"secretAccessKey": "<AWS secret access key>"
}
"""
And a Formatronfile file with content
"""
name '<name>'
prefix '<prefix>'
s3_bucket '<bucket>'
region '<region>'
kms_key '<test target>', '<test KMS key>'
kms_key '<production target>', '<production KMS key>'
cloudformation do
parameter 'param', config['<name>']['param']
end
"""
And a config/<test target>/_default.json file with content
"""
{
"param": "<test parameter>"
}
"""
And a config/<production target>/_default.json file with content
"""
{
"param": "<production parameter>"
}
"""
And a cloudformation/main.json file with content
"""
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "test",
"Parameters": {
"param": {
"Type": "String"
}
},
"Resources": {
"user": {
"Type": "AWS::IAM::User",
"Properties": {
"LoginProfile": {
"Password": { "Ref": "param" }
}
}
}
},
"Outputs": {}
}
"""
When I deploy the formatron stack with target <test target>
Then the config should be uploaded to S3 bucket <bucket> with key <test target>/<name>/config.json, KMS key <test kms key> and content
Then the region <region>, AWS access key ID <AWS access key ID> and AWS secret access key <AWS secret access key> should be used when communicating with AWS
And the config should be uploaded to S3 bucket <bucket> with key <test target>/<name>/config.json, KMS key <test KMS key> and content
"""
{
"formatronTarget": "<test target>",
Expand All @@ -38,14 +83,14 @@ Feature: Target configurations
"formatronPrefix": "<prefix>",
"formatronS3Bucket": "<bucket>",
"formatronRegion": "<region>",
"formatronKmsKey": "<test kms key>"
"formatronKmsKey": "<test KMS key>"
}
"""
And the cloudformation template should be validated
And the cloudformation template should be uploaded to S3 bucket <bucket> with key <test target>/<name>/cloudformation/main.json
And the cloudformation template should be validated with content matching cloudformation/main.json
And the cloudformation template should be uploaded to S3 bucket <bucket> with key <test target>/<name>/cloudformation/main.json and content matching cloudformation/main.json
And the cloudformation stack should be created with name <prefix>-<name>-<test target>, template url https://s3.amazonaws.com/<bucket>/<test target>/<name>/cloudformation/main.json and parameter <test parameter>

Examples:
| prefix | name | test target | test parameter | production target | production parameter | bucket | region | test kms key | production kms key |
| my_prefix_1 | my_stack_1 | test_1 | test_param_1 | production_1 | production_param_1 | my_bucket_1 | my_region_1 | my_test_kms_key_1 | my_prod_kms_key_1 |
| my_prefix_2 | my_stack_2 | test_2 | test_param_2 | production_2 | production_param_2 | my_bucket_2 | my_region_2 | my_test_kms_key_2 | my_prod_kms_key_2 |
| prefix | name | test target | test parameter | production target | production parameter | bucket | region | test KMS key | production KMS key | AWS access key ID | AWS secret access key |
| my_prefix_1 | my_stack_1 | test_1 | test_param_1 | production_1 | production_param_1 | my_bucket_1 | my_region_1 | my_test_kms_key_1 | my_prod_kms_key_1 | access_key_id_1 | secret_access_key_1 |
| my_prefix_2 | my_stack_2 | test_2 | test_param_2 | production_2 | production_param_2 | my_bucket_2 | my_region_2 | my_test_kms_key_2 | my_prod_kms_key_2 | access_key_id_2 | secret_access_key_2 |

0 comments on commit 5c1ece1

Please sign in to comment.