Skip to content

Commit

Permalink
started cucumber tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pghalliday committed Aug 31, 2015
1 parent c71bceb commit 7cfeb46
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 0 deletions.
49 changes: 49 additions & 0 deletions features/step_definitions/target_configurations_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
include Formatron::Features::Support

Given(/a basic formatron stack definition/) do
@fsd = FormatronStackDefinition.new
end

Given(/a prefix of (\w+)/) do |prefix|
@fsd.prefix = prefix
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

When(/I deploy the formatron stack with target (\w+)/) do |target|
@fsd.deploy target
end

Then(/the cloudformation stack should be called (\w+)/) do |name|
@fsd.outputs.cloudformation_stack.should == name
end

Then(/the cloudformation parameter should be (\w+)/) do |param|
@fsd.outputs.cloudformation_param.should == param
end

Then(/the S3 key for the cloudformation template should be (\w+)/) do |s3_key|
@fsd.outputs.cloudformation_s3_key.should == s3_key
end
28 changes: 28 additions & 0 deletions features/support/formatron_stack_definition.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module Formatron::Features
module Support
class FormatronStackDefinition
attr_accessor(
:prefix,
:name,
:test_target,
:test_param,
:prod_target,
:prod_param,
:s3_bucket
)

attr_reader :outputs

def deploy(target)
Dir.mktmpdir do |dir|
Credentials.new dir
Formatronfile.new dir, name, prefix, s3_bucket
Config.new dir, test_target, test_param
Config.new dir, prod_target, prod_param
Cloudformation.new dir
Formatron.new(dir, target).deploy
end
end
end
end
end
30 changes: 30 additions & 0 deletions features/support/formatron_stack_definition/cloudformation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class Formatron::Features::Support::FormatronStackDefinition::Cloudformation
CLOUDFORMATION_FILE = 'cloudformation/main.json'

def initialize(dir)
cloudformation_file = File.join(dir, CLOUDFORMATION_FILE)
FileUtils.mkdir_p File.dirname(cloudformation_file)
File.write cloudformation_file, <<-EOH.gsub(/^ {6}/, '')
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "test",
"Parameters": {
"param": {
"Type": "String"
}
},
"Resources": {
"user": {
"Type": "AWS::IAM::User",
"Properties": {
"LoginProfile": {
"Password": { "Ref": "param" }
}
}
}
},
"Outputs": {}
}
EOH
end
end
14 changes: 14 additions & 0 deletions features/support/formatron_stack_definition/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Formatron::Features::Support::FormatronStackDefinition::Config
CONFIG_DIR = 'config'
DEFAULT_FILE = '_default.json'

def initialize(dir, target, param)
config_dir = File.join(dir, CONFIG_DIR, target)
FileUtils.mkdir_p config_dir
File.write File.join(config_dir, DEFAULT_FILE), <<-EOH.gsub(/^ {6}/, '')
{
"param" = "#{param}"
}
EOH
end
end
12 changes: 12 additions & 0 deletions features/support/formatron_stack_definition/credentials.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Formatron::Features::Support::FormatronStackDefinition::Credentials
CREDENTIALS_FILE = 'credentials.json'

def initialize(dir)
File.write File.join(dir, CREDENTIALS_FILE), <<-EOH.gsub(/^ {6}/, '')
{
"accessKeyId" = "ajhfvbfjfhjadbhjvabdf",
"secretAccessKey" = "akjsdfjabkvjnadfvnkadfnvkjdfjvkdabkfjbvadkjfvbksdj"
}
EOH
end
end
15 changes: 15 additions & 0 deletions features/support/formatron_stack_definition/formatronfile.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Formatron::Features::Support::FormatronStackDefinition::Formatronfile
FORMATRONFILE_NAME = 'Formatronfile'

def initialize(dir, prefix, name, s3_bucket)
File.write File.join(dir, FORMATRONFILE_NAME), <<-EOH.gsub(/^ {6}/, '')
name '#{name}'
prefix '#{prefix}'
s3_bucket '#{s3_bucket}'
region 'eu-west-1'
cloudformation do
parameter 'param', config['#{name}']['param']
end
EOH
end
end
28 changes: 28 additions & 0 deletions features/target_configurations.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Feature: Target configurations
In order to test a formatron stack definition without affecting production resources
As a maintainer of formatron stacks
I want to be able to deploy separate target configurations from the same definition

Rules:
- CloudFormation stacks should be properly namespaced
- Configuration should be loaded from target specific sources
- Target specific S3 keys should be properly namespaced

Scenario Outline: deploy
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>
When I deploy the formatron stack with target <test target>
Then the cloudformation stack should be called <cloudformation stack>
And the cloudformation parameter should be <test parameter>
And the S3 key for the cloudformation template should be <cloudformation S3 key>

Examples:
| prefix | name | test target | test parameter | production target | production parameter | bucket | cloudformation stack | cloudformation S3 key|
| my_prefix_1 | my_stack_1 | test_1 | test_param_1 | production_1 | production_param_1 | my_bucket_1 | my_prefix_1-my_stack_1-test_1 | my_bucket_1/test_1/my_stack_1/cloudformation/main.json |
| my_prefix_2 | my_stack_2 | test_2 | test_param_2 | production_2 | production_param_2 | my_bucket_2 | my_prefix_2-my_stack_2-test_2 | my_bucket_2/test_2/my_stack_2/cloudformation/main.json |

0 comments on commit 7cfeb46

Please sign in to comment.