diff --git a/lib/panda_motd/components/service_status.rb b/lib/panda_motd/components/service_status.rb index 24c5538..c0f7908 100644 --- a/lib/panda_motd/components/service_status.rb +++ b/lib/panda_motd/components/service_status.rb @@ -30,8 +30,8 @@ def to_s def parse_service(service) cmd_result = `systemctl is-active #{service[0]}`.strip - unless valid_responses.include? cmd_result - @errors << ComponentError.new(self, 'Unable to parse systemctl output') + if cmd_result.empty? + @errors << ComponentError.new(self, 'systemctl output was blank.') end cmd_result end @@ -41,13 +41,11 @@ def parse_services(services) end def service_colors - { - active: :green, - inactive: :red - } - end + colors = Hash.new(:red) + colors[:active] = :green + colors[:inactive] = :yellow + colors[:failed] = :red - def valid_responses - ['active', 'inactive'] + colors end end diff --git a/spec/components/service_status_spec.rb b/spec/components/service_status_spec.rb index 5dd3da5..5d11e6f 100644 --- a/spec/components/service_status_spec.rb +++ b/spec/components/service_status_spec.rb @@ -23,19 +23,23 @@ context 'when printing different statuses' do it 'prints active in green' do - stub_system_call(component, returns: 'active') - component.process - component.instance_variable_set(:@results, servicename: :active) expect(component.to_s).to include 'active'.green end - it 'prints inactive in red' do - stub_system_call(component, returns: 'active') - component.process - + it 'prints inactive in yellow' do component.instance_variable_set(:@results, servicename: :inactive) - expect(component.to_s).to include 'inactive'.red + expect(component.to_s).to include 'inactive'.yellow + end + + it 'prints failed in red' do + component.instance_variable_set(:@results, servicename: :failed) + expect(component.to_s).to include 'failed'.red + end + + it 'prints unknown status in red' do + component.instance_variable_set(:@results, servicename: :asdf123) + expect(component.to_s).to include 'asdf123'.red end end @@ -46,7 +50,7 @@ errors = component.errors expect(errors.count).to eq 2 - expect(errors.first.message).to eq 'Unable to parse systemctl output' + expect(errors.first.message).to eq 'systemctl output was blank.' end end end