add more tests

This commit is contained in:
Anton Chuchkalov 2015-07-08 17:48:19 +04:00
parent 9820ef415f
commit 356925de49
11 changed files with 250 additions and 4 deletions

View File

@ -12,7 +12,8 @@ class Generator < OpenStruct
TESTS_CONFIG = "features/support/config.yml" TESTS_CONFIG = "features/support/config.yml"
def initialize def initialize
@config = YAML.load_file(File.new(ENV["CONFIG"] || CONFIG)) config_file = ENV["DEVOPS_FEATURES_GENERATOR_CONFIG"] || ENV["CONFIG"] || CONFIG
@config = YAML.load_file(File.new(config_file))
load_fixtures() load_fixtures()
super(:config => @config) super(:config => @config)
end end
@ -63,7 +64,11 @@ class Generator < OpenStruct
def load_fixtures def load_fixtures
@fixtures = {} @fixtures = {}
@fixtures['deploy_env'] = YAML.load_file('templates/fixtures/deploy_env.yml') Dir["templates/fixtures/*.yml"].each do |fixture_path|
fixture_name = File.basename(fixture_path, '.yml')
@fixtures[fixture_name] = YAML.load_file(fixture_path)
end
@formatter = FixtureFormatter.new(@fixtures) @formatter = FixtureFormatter.new(@fixtures)
end end
end end
@ -77,7 +82,10 @@ templates = {
#create #create
"templates/api_v2/10_create/00_filter.feature.erb" => "features/api_v2/10_create/00_filter.feature", "templates/api_v2/10_create/00_filter.feature.erb" => "features/api_v2/10_create/00_filter.feature",
"templates/api_v2/10_create/00_stack_template.feature.erb" => "features/api_v2/10_create/00_stack_template.feature",
"templates/api_v2/10_create/00_key.feature.erb" => "features/api_v2/10_create/00_key.feature",
"templates/api_v2/10_create/10_image.feature.erb" => "features/api_v2/10_create/10_image.feature", "templates/api_v2/10_create/10_image.feature.erb" => "features/api_v2/10_create/10_image.feature",
"templates/api_v2/10_create/50_stack.feature.erb" => "features/api_v2/10_create/50_stack.feature",
"templates/api_v2/10_create/20_project.feature.erb" => "features/api_v2/10_create/20_project.feature", "templates/api_v2/10_create/20_project.feature.erb" => "features/api_v2/10_create/20_project.feature",
"templates/api_v2/10_create/30_script.feature.erb" => "features/api_v2/10_create/30_script.feature", "templates/api_v2/10_create/30_script.feature.erb" => "features/api_v2/10_create/30_script.feature",
"templates/api_v2/10_create/40_deploy_env.feature.erb" => "features/api_v2/10_create/40_deploy_env.feature", "templates/api_v2/10_create/40_deploy_env.feature.erb" => "features/api_v2/10_create/40_deploy_env.feature",
@ -88,12 +96,15 @@ templates = {
"templates/api_v2/20_update/00_user.feature.erb" => "features/api_v2/20_update/00_user.feature", "templates/api_v2/20_update/00_user.feature.erb" => "features/api_v2/20_update/00_user.feature",
#delete #delete
"templates/api_v2/90_delete/00_stack_template.feature.erb" => "features/api_v2/90_delete/00_stack_template.feature",
"templates/api_v2/90_delete/10_script.feature.erb" => "features/api_v2/90_delete/10_script.feature", "templates/api_v2/90_delete/10_script.feature.erb" => "features/api_v2/90_delete/10_script.feature",
"templates/api_v2/90_delete/10_stack.feature.erb" => "features/api_v2/90_delete/10_stack.feature",
"templates/api_v2/90_delete/20_deploy_env.feature.erb" => "features/api_v2/90_delete/20_deploy_env.feature", "templates/api_v2/90_delete/20_deploy_env.feature.erb" => "features/api_v2/90_delete/20_deploy_env.feature",
"templates/api_v2/90_delete/80_project.feature.erb" => "features/api_v2/90_delete/80_project.feature", "templates/api_v2/90_delete/80_project.feature.erb" => "features/api_v2/90_delete/80_project.feature",
"templates/api_v2/90_delete/90_image.feature.erb" => "features/api_v2/90_delete/90_image.feature", "templates/api_v2/90_delete/90_image.feature.erb" => "features/api_v2/90_delete/90_image.feature",
"templates/api_v2/90_delete/90_user.feature.erb" => "features/api_v2/90_delete/90_user.feature",
"templates/api_v2/90_delete/99_filter.feature.erb" => "features/api_v2/90_delete/99_filter.feature", "templates/api_v2/90_delete/99_filter.feature.erb" => "features/api_v2/90_delete/99_filter.feature",
"templates/api_v2/90_delete/90_user.feature.erb" => "features/api_v2/90_delete/90_user.feature" "templates/api_v2/90_delete/99_key.feature.erb" => "features/api_v2/90_delete/99_key.feature"
} }

View File

@ -0,0 +1,34 @@
@key
Feature: Add new script
Scenario: Add new key without file_name
When I send POST '/v2.0/key' query with JSON body
"""
<%= @formatter.json('key/invalid/blank_file_name', spaces: 6) %>
"""
Then response should be '400'
And response error should be "Parameter 'file_name' must be a not empty string"
Scenario: Add new key without key_name
When I send POST '/v2.0/key' query with JSON body
"""
<%= @formatter.json('key/invalid/blank_key_name', spaces: 6) %>
"""
Then response should be '400'
And response error should be "Parameter 'key_name' should be a not empty string"
Scenario: Add new key without content
When I send POST '/v2.0/key' query with JSON body
"""
<%= @formatter.json('key/invalid/blank_content', spaces: 6) %>
"""
Then response should be '400'
And response error should be "Parameter 'content' should be a not empty string"
Scenario: Add new key
When I send POST '/v2.0/key' query with JSON body
"""
<%= @formatter.json('key/valid', spaces: 6) %>
"""
Then response should be '201'

View File

@ -0,0 +1,25 @@
@stack_template @project @stack
Feature: Stack templates
Scenario: Add new stack_template with user without privileges
When I send POST '/v2.0/stack_template' query with JSON body with user without privileges
"""
<%= @formatter.json('stack_template/openstack/valid', spaces: 6) %>
"""
Then response should be '401'
<% openstack_template_id = @fixtures['stack_template']['openstack']['valid']['id'] %>
@openstack
Scenario: Add openstack stack_template
When I send POST '/v2.0/stack_template' query with JSON body
"""
<%= @formatter.json('stack_template/openstack/valid', spaces: 6) %>
"""
Then response should be '201'
And the Content-Type header should include 'application/json'
And response should be JSON object like:
"""
{
"id": "<%= openstack_template_id %>"
}
"""

View File

@ -0,0 +1,27 @@
@stack @project
Feature: Stacks
Scenario: Add new stack with user without privileges
When I send POST '/v2.0/stack' query with JSON body with user without privileges
"""
<%= @formatter.json('stack/openstack/valid', spaces: 6) %>
"""
Then response should be '401'
@openstack
Scenario: Add openstack stack
When I send POST '/v2.0/stack' query with JSON body
"""
<%= @formatter.json('stack/openstack/valid', spaces: 4) %>
"""
Then response should be '201'
And the Content-Type header should include 'application/json'
And response should be JSON object like:
"""
{
"id": "test_stack",
"deploy_env": "<%= @config["openstack"]["project"]["env"] %>",
"stack_template": "<%= @config["openstack"]["stack_template"] %>",
"cloud_stack_id": "arn:aws:cloudformation:us-east-1:123456789:stack/MyStack/aaf549a0-a413-11df-adb3-5081b3858e83"
}
"""

View File

@ -0,0 +1,19 @@
@stack_template @project @stack
Feature: Delete stack template
<% openstack_template_id = @fixtures['stack_template']['openstack']['valid']['id'] %>
Scenario: Delete stack template with user without privileges
When I send DELETE '/v2.0/stack_template/<%= openstack_template_id %>' query with user without privileges
Then response should be '401'
@openstack
Scenario: Delete openstack stack_template without header 'Accept'
When I send DELETE '/v2.0/stack_template/<%= openstack_template_id %>' query without header 'Accept'
Then response should be '406'
@openstack
Scenario: Delete openstack stack_template with id '<%= openstack_template_id %>'
When I send DELETE '/v2.0/stack_template/<%= openstack_template_id %>' query
Then response should be '200'
And the Content-Type header should include 'application/json'
And the JSON response should be an object

View File

@ -0,0 +1,19 @@
@stack @project
Feature: Delete stack
<% openstack_stack_id = @fixtures['stack']['openstack']['valid']['id'] %>
Scenario: Delete stack with user without privileges
When I send DELETE '/v2.0/stack/<%= openstack_stack_id %>' query with user without privileges
Then response should be '401'
@openstack
Scenario: Delete openstack stack without header 'Accept'
When I send DELETE '/v2.0/stack/<%= openstack_stack_id %>' query without header 'Accept'
Then response should be '406'
@openstack
Scenario: Delete stack with id '<%= openstack_stack_id %>'
When I send DELETE '/v2.0/stack/<%= openstack_stack_id %>' query
Then response should be '200'
And the Content-Type header should include 'application/json'
And the JSON response should be an object

View File

@ -0,0 +1,10 @@
@key
Feature: Delete key
<% key_name = @fixtures['key']['valid']['key_name'] %>
Scenario: Delete key
When I send DELETE '/v2.0/key/<%= key_name %>' query
Then response should be '200'
And the Content-Type header should include 'application/json'
And the JSON response should be an object

View File

@ -7,7 +7,11 @@ class FixtureFormatter
end end
def json(path, options={}) def json(path, options={})
result = JSON.pretty_generate(get_fixture(path)) begin
result = JSON.pretty_generate(get_fixture(path))
rescue
raise "Fixture '#{path}' is absent"
end
if options[:spaces] if options[:spaces]
result = shift_to_right(result, options[:spaces]) result = shift_to_right(result, options[:spaces])
end end

View File

@ -0,0 +1,20 @@
valid: &valid
file_name: test_file_name
key_name: test_key_name
content: test_content
invalid:
base: &invalid_base
<<: *valid
blank_file_name:
<<: *invalid_base
file_name:
blank_key_name:
<<: *invalid_base
key_name:
blank_content:
<<: *invalid_base
content:
scope:
<<: *invalid_base
scope: inalid_scope

View File

@ -0,0 +1,11 @@
openstack:
valid: &valid
id: openstack_stack
provider: openstack
project: test_openstack
deploy_env: test
stack_template: openstack_template
parameters:
admin_pass: Pass12
key_name: devops
image: CirrOS_0.3.1

View File

@ -0,0 +1,66 @@
openstack:
valid: &valid
id: openstack_template
provider: openstack
template_body: |
heat_template_version: 2013-05-23
description: >
Hello world HOT template that just defines a single server.
Contains just base features to verify base HOT support.
parameters:
key_name:
type: string
description: Name of an existing key pair to use for the server
constraints:
- custom_constraint: nova.keypair
flavor:
type: string
description: Flavor for the server to be created
default: m1.small
constraints:
- custom_constraint: nova.flavor
image:
type: string
description: Image ID or image name to use for the server
constraints:
- custom_constraint: glance.image
admin_pass:
type: string
description: Admin password
hidden: true
constraints:
- length: { min: 6, max: 8 }
description: Password length must be between 6 and 8 characters
- allowed_pattern: "[a-zA-Z0-9]+"
description: Password must consist of characters and numbers only
- allowed_pattern: "[A-Z]+[a-zA-Z0-9]*"
description: Password must start with an uppercase character
db_port:
type: number
description: Database port number
default: 50000
constraints:
- range: { min: 40000, max: 60000 }
description: Port number must be between 40000 and 60000
resources:
server:
type: OS::Nova::Server
properties:
key_name: { get_param: key_name }
image: { get_param: image }
flavor: { get_param: flavor }
admin_pass: { get_param: admin_pass }
user_data:
str_replace:
template: |
#!/bin/bash
echo db_port
params:
db_port: { get_param: db_port }
outputs:
server_networks:
description: The networks of the deployed server
value: { get_attr: [server, networks] }