60 lines
1.7 KiB
Ruby
Executable File
60 lines
1.7 KiB
Ruby
Executable File
#!/usr/bin/env ruby
|
|
#
|
|
require "erb"
|
|
require "yaml"
|
|
require "ostruct"
|
|
require "fileutils"
|
|
|
|
class Generator < OpenStruct
|
|
|
|
CONFIG = "params.yml"
|
|
TESTS_CONFIG = "features/support/config.yml"
|
|
|
|
def initialize
|
|
@config = YAML.load_file(File.new(ENV["CONFIG"] || CONFIG))
|
|
super(:config => @config)
|
|
end
|
|
|
|
def make_tests_config
|
|
c = {}
|
|
%w{host port username password path_prefix username_without_privileges password_without_privileges}.each do |key|
|
|
c[key] = @config[key]
|
|
end
|
|
File.open(TESTS_CONFIG, "w") {|f| f.write(c.to_yaml) }
|
|
end
|
|
|
|
def render(template)
|
|
ERB.new(template).result(binding)
|
|
end
|
|
|
|
end
|
|
|
|
templates = {
|
|
|
|
#list
|
|
"templates/api_v2/00_list/flavor.feature.erb" => "features/api_v2/00_list/flavor.feature",
|
|
|
|
#create
|
|
"templates/api_v2/10_create/00_filter.feature.erb" => "features/api_v2/10_create/00_filter.feature",
|
|
"templates/api_v2/10_create/10_image.feature.erb" => "features/api_v2/10_create/10_image.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/00_user.feature.erb" => "features/api_v2/10_create/00_user.feature",
|
|
|
|
#delete
|
|
"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|
|
|
if File.exists?(input)
|
|
data = generator.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
|