Sha256: b8eef6999a3161ff936b677375794e23765617ca716bca4d58752327e780b721

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

require 'TerraformDevKit'

module TFModTest
  TDK = TerraformDevKit

  class ModuleTest
    def initialize(module_name)
      @module_name = module_name
    end

    def run_task(task_name)
      puts("=== Running task #{task_name} for module #{@module_name} ===")
      run_task_in_directory(task_name, module_path)
    end

    def module_path
      File.join('test', @module_name)
    end

    private

    def run_task_in_directory(task_name, dir)
      Dir.chdir(dir) do
        load 'Rakefile'
        begin
          Rake::Task["#{@module_name}:#{task_name}"].invoke(DEFAULT_PREFIX)
        rescue RuntimeError => e
          puts e.message
          puts e.backtrace.join("\n")
          Rake::Task["#{@module_name}:clean"].invoke(DEFAULT_PREFIX)
          raise "Error testing module #{@module_name}"
        end
      end
    end
  end

  class ModuleTestRepository
    def self.each
      modules_path = Rake::FileList.new('test/*')
      modules_path.each do |path|
        module_name = File.basename(path)
        yield ModuleTest.new(module_name) unless excluded?(module_name)
      end
    end

    private_class_method
    def self.excluded?(module_name)
      excluded_modules.include?(module_name)
    end

    private_class_method
    def self.excluded_modules
      ENV.fetch('TM_EXCLUDE_MODULES', '').split(',')
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tfmodtest-0.1.0 lib/tfmodtest/module_test.rb