From c3ec9f31f24f742c552f87be43892e2acba33a63 Mon Sep 17 00:00:00 2001 From: amartynov Date: Mon, 14 Jul 2014 12:51:34 +0400 Subject: [PATCH] tests generator --- devops-service/tests/config.yml | 14 ++++ devops-service/tests/generate_tests.rb | 32 ++++++++++ .../templates/00_list/flavor.feature.erb | 64 +++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 devops-service/tests/config.yml create mode 100755 devops-service/tests/generate_tests.rb create mode 100644 devops-service/tests/templates/00_list/flavor.feature.erb diff --git a/devops-service/tests/config.yml b/devops-service/tests/config.yml new file mode 100644 index 0000000..f6f6cfb --- /dev/null +++ b/devops-service/tests/config.yml @@ -0,0 +1,14 @@ +--- +openstack: + flavor: "as_long_as_image" + image: "08093b30-8393-42c3-8fb3-c4df56deb967" + project: + name: "test_openstack" + env: "test" + +ec2: + flavor: "m1.small" + image: "ami-63071b0a" + project: + name: "test_ec2" + env: "test" diff --git a/devops-service/tests/generate_tests.rb b/devops-service/tests/generate_tests.rb new file mode 100755 index 0000000..8e1df84 --- /dev/null +++ b/devops-service/tests/generate_tests.rb @@ -0,0 +1,32 @@ +#!/usr/bin/env ruby +# +require "erb" +require "yaml" +require "ostruct" + +class Generator + + CONFIG = "config.yml" + + def initialize + @config = YAML.load_file(File.new(CONFIG)) + end + + def render(template) + ERB.new(template).result(binding) + end +end + +templates = { + "templates/00_list/flavor.feature.erb" => "flavor.feature" +} +generator = Generator.new + +templates.each do |input, output| + if File.exists?(input) + data = generator.render(File.read(input)) + File.open(output, "w") {|f| f.write(data)} + else + puts "WARN: file '#{input}' does not exist" + end +end diff --git a/devops-service/tests/templates/00_list/flavor.feature.erb b/devops-service/tests/templates/00_list/flavor.feature.erb new file mode 100644 index 0000000..92a5aba --- /dev/null +++ b/devops-service/tests/templates/00_list/flavor.feature.erb @@ -0,0 +1,64 @@ +@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'