add ability to clean features after generation

This commit is contained in:
Anton Chuchkalov 2014-11-21 15:22:46 +04:00
parent 803685df8e
commit ce8cdd230c
3 changed files with 37 additions and 80 deletions

View File

@ -80,7 +80,7 @@ GEM
moneta (0.6.0) moneta (0.6.0)
mongo (1.9.2) mongo (1.9.2)
bson (~> 1.9.2) bson (~> 1.9.2)
multi_json (1.8.4) multi_json (1.7.8)
multi_test (0.1.1) multi_test (0.1.1)
net-scp (1.1.2) net-scp (1.1.2)
net-ssh (>= 2.6.5) net-ssh (>= 2.6.5)
@ -168,9 +168,9 @@ DEPENDENCIES
mime-types (~> 1.25.1) mime-types (~> 1.25.1)
mixlib-shellout mixlib-shellout
mongo mongo
multi_json multi_json (= 1.7.8)
rufus-scheduler (= 2.0.24) rufus-scheduler (= 2.0.24)
sidekiq sidekiq (= 3.2.6)
sinatra (= 1.4.3) sinatra (= 1.4.3)
sinatra-contrib (= 1.4.1) sinatra-contrib (= 1.4.1)
sinatra-websocket (~> 0.3.0) sinatra-websocket (~> 0.3.0)

View File

@ -1,64 +0,0 @@
@flavor
Feature: Flavors
@openstack
Scenario: Get list of openstack flavors
When I send GET '/v2.0/flavors/openstack' query
Then response should be '200'
And the Content-Type header should include 'application/json'
And the JSON response should be an array
And response array should contains elements like:
"""
[
{
"id": "flavor_id",
"v_cpus": "v_cpus",
"ram": "ram",
"disk": "disk"
}
]
"""
@ec2
Scenario: Get list of ec2 flavors
When I send GET '/v2.0/flavors/ec2' query
Then response should be '200'
And the Content-Type header should include 'application/json'
And the JSON response should be an array
And response array should contains elements like:
"""
[
{
"id": "t1.micro",
"cores": 2,
"disk": 0,
"name": "Micro Instance",
"ram": 613
}
]
"""
@static
Scenario: Get list of static flavors
When I send GET '/v2.0/flavors/static' query
Then response should be '200'
And the Content-Type header should include 'application/json'
And the JSON response should be an array
And response array should be empty
@static
Scenario: Get flavors list of static provider without 'Accept' header
When I send GET '/v2.0/flavors/static' query without headers 'Accept'
Then response should be '406'
Scenario: Get flavors list of unknown provider
When I send GET '/v2.0/flavors/foo' query
Then response should be '404'
Scenario: Get flavors list of unknown provider without 'Accept' header
When I send GET '/v2.0/flavors/foo' query without headers 'Accept'
Then response should be '406'
Scenario: Get flavors list of unknown provider without privileges
When I send GET '/v2.0/flavors/foo' query with user without privileges
Then response should be '401'

View File

@ -15,18 +15,43 @@ class Generator < OpenStruct
super(:config => @config) super(:config => @config)
end end
def make_tests_config def configure!
c = {} c = {}
%w{host port username password path_prefix username_without_privileges password_without_privileges}.each do |key| %w{host port username password path_prefix username_without_privileges password_without_privileges}.each do |key|
c[key] = @config[key] c[key] = @config[key]
end end
File.open(TESTS_CONFIG, "w") {|f| f.write(c.to_yaml) } File.open(TESTS_CONFIG, "w") {|f| f.write(c.to_yaml) }
self
end end
def generate!(templates)
templates.each do |input, output|
if File.exists?(input)
data = render(File.read(input))
dir = File.dirname(output)
FileUtils.mkdir_p(dir) unless File.exists?(dir)
File.open(output, "w") {|f| f.write(data)}
else
puts "WARN: file '#{input}' does not exist"
end
end
end
def clean!(feature_files)
feature_files.each do |feature_file|
if File.exists?(feature_file)
FileUtils.rm(feature_file)
else
puts "WARN: file '#{feature_file}' does not exist"
end
end
end
private
def render(template) def render(template)
ERB.new(template).result(binding) ERB.new(template).result(binding)
end end
end end
templates = { templates = {
@ -54,16 +79,12 @@ templates = {
"templates/api_v2/90_delete/90_user.feature.erb" => "features/api_v2/90_delete/90_user.feature" "templates/api_v2/90_delete/90_user.feature.erb" => "features/api_v2/90_delete/90_user.feature"
} }
generator = Generator.new
generator.make_tests_config
templates.each do |input, output| generator = Generator.new.configure!
if File.exists?(input) if ARGV.first != 'clean'
data = generator.render(File.read(input)) generator.generate!(templates)
dir = File.dirname(output) else
FileUtils.mkdir_p(dir) unless File.exists?(dir) generator.clean!(templates.values)
File.open(output, "w") {|f| f.write(data)}
else
puts "WARN: file '#{input}' does not exist"
end
end end