require 'spec_helper' require 'job_helper' describe Marty::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 message = `cd #{Rails.root}; git describe --tags --always;`.strip rescue StandardError message = error('Failed accessing git') end def aggregate_data opts = {} { '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 = Marty::Diagnostic::Base.create_info('A') original_b = Marty::Diagnostic::Base.create_info('B') data = { 'CONSTANTA' => original_a, 'CONSTANTB' => original_b, 'CONSTANTB2' => original_b, } different_b = Marty::Diagnostic::Base.create_info('C') test = { diagnostic => { 'NodeA' => data, 'NodeB' => data + { 'CONSTANTB' => different_b, 'CONSTANTB2' => different_b }, } } inconsistent_b = Marty::Diagnostic::Base.create_info('B', true, false) inconsistent_c = Marty::Diagnostic::Base.create_info('C', true, false) if diagnostic == 'EnvironmentVariables' expected = { diagnostic => { 'NodeA' => { 'CONSTANTB' => inconsistent_b, 'CONSTANTB2' => inconsistent_b, }, 'NodeB' => { 'CONSTANTB' => inconsistent_c, 'CONSTANTB2' => inconsistent_c, }, } } else expected = { diagnostic => { '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 Marty::Diagnostic::Base.create_info(v, status, consistent) end def version_data consistent = true Marty::Diagnostic::Base.pack(include_ip = false) do { 'Marty' => info(Marty::VERSION, true, consistent), 'Delorean' => info(Delorean::VERSION, true, true), 'Mcfly' => info(Mcfly::VERSION, true, true), 'Git' => info(git, true, true), } end end def minimize(str) str.gsub(/\s+/, '') end describe 'display mechanism for version diagnostic' do before(:all) do described_class.diagnostics = [Marty::Diagnostic::Version] end before(:each) do described_class.request = DummyRequest.new end it 'masks consistent nodes for display (version)' do described_class.request.params = params(scope = 'local') data = { '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 |