Class: Kurgan::Test

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/kurgan/test.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



12
13
14
# File 'lib/kurgan/test.rb', line 12

def self.source_root
  File.dirname(__FILE__)
end

Instance Method Details

#create_testObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/kurgan/test.rb', line 24

def create_test
  case options[:type]
  when 'config'
    template('templates/test.yaml.tt', "#{options[:directory]}/#{test_name}.test.yaml")
  when 'spec'
    if test_name == '*'
      test_yamls = Dir["tests/*.test.yaml"]
      tests = test_yamls.map {|test_yaml| test_yaml[/tests\/(.*).test.yaml/, 1]}
    else
      tests = [test_name]
    end

    tests.each do |name|
      output_file = "#{Dir.pwd}/out/tests/#{name}/#{@component_name}.compiled.yaml"
      if !File.file?(output_file)
        warn "compile cloudformation test output file #{output_file} not found.\nRun `cfhighlander cftest -t #{options[:directory]}/#{name}.test.yaml`"
      end
      compiled_test = YAML.load_file("#{Dir.pwd}/out/tests/#{name}/#{@component_name}.compiled.yaml")
      template('templates/test.spec.tt', "spec/#{name}_spec.rb", compiled_test)
    end
  else
    error "#{options[:type]} is not a supported test type yet", :red
  end
end

#get_cfhighlander_templateObject



16
17
18
19
20
21
22
# File 'lib/kurgan/test.rb', line 16

def get_cfhighlander_template
  @cfhighlander_template = Dir['*.cfhighlander.rb'][0]
  if @cfhighlander_template.nil?
    raise "No cfhighlander.rb file found in #{Dir.pwd}"
  end
  @component_name = @cfhighlander_template.split('.').first
end