Sha256: acea39e6627902ef358ebf9a02c1160a10eb7b8c781c25f38368b2e9bac244ca

Contents?: true

Size: 1.54 KB

Versions: 2

Compression:

Stored size: 1.54 KB

Contents

require 'erb'

module Fulmar
  module Domain
    module Service
      # Tests the configuration
      class ConfigTestService
        include Fulmar::Domain::Model

        def initialize(config)
          @config = config
          @tests = {}
        end

        def target_test(name, &block)
          @tests[name] = Proc.new do
            results = []
            @config.each do |env, target, _data|
              @config.set env, target
              result = block.call(@config)
              if result
                result[:message] = "in [#{env}:#{target}]: #{result[:message]}"
                results << result
              end
            end
            results.reject(&:nil?)
          end

        end

        def global_test(name, &block)
          @tests[name] = block
        end

        # Runs all methods beginning with test_ and returns the report
        def run
          test_dirs = ["#{File.dirname(__FILE__)}/config_tests/"]
          test_files = test_dirs.collect{ |dir| Dir.glob("#{dir}/*.rb") }.flatten
          test_files.each do |file|
            eval File.read(file)
          end

          results = []
          @tests.each_pair do |name, test|
            results << test.call(@config)
          end
          results.reject!(&:nil?)
          results.reject!(&:empty?)
          results.flatten!
          results
        end

        protected

        def ssh_hostnames
          @ssh_hostnames ||= `grep -E '^Host [^ *]+$' ~/.ssh/config | sort | uniq | cut -d ' ' -f 2`.split("\n")
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fulmar-2.0.1 lib/fulmar/domain/service/config_test_service.rb
fulmar-2.0.0 lib/fulmar/domain/service/config_test_service.rb