class Fulmar::Domain::Service::ConfigTestService

Tests the configuration

Public Class Methods

new(config) click to toggle source
# File lib/fulmar/domain/service/config_test_service.rb, line 11
def initialize(config)
  @config = config
  @tests = {}
end

Public Instance Methods

global_test(name, &block) click to toggle source
# File lib/fulmar/domain/service/config_test_service.rb, line 32
def global_test(name, &block)
  @tests[name] = block
end
run() click to toggle source

Runs all methods beginning with test_ and returns the report

# File lib/fulmar/domain/service/config_test_service.rb, line 37
def run
  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
target_test(name) { |config| ... } click to toggle source
# File lib/fulmar/domain/service/config_test_service.rb, line 16
def target_test(name, &block)
  @tests[name] = proc do
    results = []
    @config.each do |env, target, _data|
      @config.set env, target
      result = yield(@config)
      if result
        result[:message] = "in [#{env}:#{target}]: #{result[:message]}"
        results << result
      end
    end
    results.reject(&:nil?)
  end

end

Protected Instance Methods

ssh_hostnames() click to toggle source
# File lib/fulmar/domain/service/config_test_service.rb, line 54
def ssh_hostnames
  @ssh_hostnames ||= `grep -E '^Host [^ *]+$' ~/.ssh/config | sort | uniq | cut -d ' ' -f 2`.split("\n")
end
test_files() click to toggle source
# File lib/fulmar/domain/service/config_test_service.rb, line 58
def test_files
  dir = "#{File.dirname(__FILE__)}/config_tests/"
  files = Dir.glob("#{dir}/*.rb")
  plugin_service = Fulmar::Domain::Service::PluginService.instance
  files + plugin_service.test_files
end