require 'spec_helper' require 'job_helper' describe Diagnostic::Reporter do # used to stub request object class DummyRequest attr_accessor :params, :port end def params diagnostic='base', scope=nil {op: diagnostic, scope: scope} end def git begin message = `cd #{Rails.root.to_s}; git describe --tags --always;`.strip rescue message = error("Failed accessing git") end end def aggregate_data opts={} { 'Diagnostic::Dummy' => { 'NodeA' => { 'ImportantTest' => { 'description' => 'A', 'status' => opts[:status].nil? ? true : opts[:status], 'consistent' => opts[:consistent].nil? ? true : opts[:consistent], } } } } end def aggregate_consistency_data diagnostic='Base' original_a = Diagnostic::Base.create_info('A') original_b = Diagnostic::Base.create_info('B') data = { 'CONSTANTA' => original_a, 'CONSTANTB' => original_b, 'CONSTANTB2' => original_b, } different_b = Diagnostic::Base.create_info('C') key = "Diagnostic::" + diagnostic test = { key => { 'NodeA' => data, 'NodeB' => data + { 'CONSTANTB' => different_b, 'CONSTANTB2' => different_b }, } } inconsistent_b = Diagnostic::Base.create_info('B', true, false) inconsistent_c = Diagnostic::Base.create_info('C', true, false) if diagnostic == 'Env' expected = { key => { 'NodeA' => { 'CONSTANTB' => inconsistent_b, 'CONSTANTB2' => inconsistent_b, }, 'NodeB' => { 'CONSTANTB' => inconsistent_c, 'CONSTANTB2' => inconsistent_c, }, } } else expected = { key => { 'NodeA' => { 'CONSTANTA' => original_a + {'consistent' => true}, 'CONSTANTB' => inconsistent_b, 'CONSTANTB2' => inconsistent_b, }, 'NodeB' => { 'CONSTANTA' => original_a + {'consistent' => true}, 'CONSTANTB' => inconsistent_c, 'CONSTANTB2' => inconsistent_c, }, } } end [test, expected] end def info v, status, consistent Diagnostic::Base.create_info(v, status, consistent) end def version_data consistent = true Diagnostic::Base.pack(include_ip=false){ { "Marty" => info(Marty::VERSION, true, consistent), "Delorean" => info(Delorean::VERSION, true, true), "Mcfly" => info(Mcfly::VERSION, true, true), "Git" => info(git, true, true), } } end def minimize(str) str.gsub(/\s+/, "") end describe 'display mechanism for version diagnostic' do before(:all) do Diagnostic::Reporter.diagnostics = [Diagnostic::Version] end before(:each) do Diagnostic::Reporter.request = DummyRequest.new end it 'masks consistent nodes for display (version)' do Diagnostic::Reporter.request.params = params(scope='local') data = { 'Diagnostic::Version' => { 'NodeA' => version_data, 'NodeB' => version_data, } } expected = <<-ERB
consistent | |
---|---|
Marty | #{Marty::VERSION} |
Delorean | #{Delorean::VERSION} |
Mcfly | #{Mcfly::VERSION} |
Git | #{git} |
NodeA | NodeB | |
---|---|---|
Marty | #{Marty::VERSION} |
#{bad_ver} |
Delorean | #{Delorean::VERSION} |
#{Delorean::VERSION} |
Mcfly | #{Mcfly::VERSION} |
#{Mcfly::VERSION} |
Git | #{git} |
#{git} |
NodeA | NodeB | NodeC | |
---|---|---|---|
RuntimeError |
B |
N/A |
N/A |
OtherError |
N/A |
C |
N/A |
OtherOtherError |
N/A |
N/A |
D |