Better formatting for downtime check messages

This removes excessive whitespace from the messages (e.g. leading
whitespace) and ensures the message is more clearly visible.
This commit is contained in:
Yorick Peterse 2016-08-17 12:15:20 +02:00
parent 88a0c984fc
commit fa0624fc64
No known key found for this signature in database
GPG Key ID: EDD30D2BEB691AC9
2 changed files with 36 additions and 3 deletions

View File

@ -1,7 +1,7 @@
module Gitlab
class DowntimeCheck
class Message
attr_reader :path, :offline, :reason
attr_reader :path, :offline
OFFLINE = "\e[31moffline\e[0m"
ONLINE = "\e[32monline\e[0m"
@ -19,10 +19,21 @@ module Gitlab
label = offline ? OFFLINE : ONLINE
message = "[#{label}]: #{path}"
message += ": #{reason}" if reason
if reason?
message += ":\n\n#{reason}\n\n"
end
message
end
def reason?
@reason.present?
end
def reason
@reason.strip.lines.map(&:strip).join("\n")
end
end
end
end

View File

@ -5,7 +5,7 @@ describe Gitlab::DowntimeCheck::Message do
it 'returns an ANSI formatted String for an offline migration' do
message = described_class.new('foo.rb', true, 'hello')
expect(message.to_s).to eq("[\e[31moffline\e[0m]: foo.rb: hello")
expect(message.to_s).to eq("[\e[31moffline\e[0m]: foo.rb:\n\nhello\n\n")
end
it 'returns an ANSI formatted String for an online migration' do
@ -14,4 +14,26 @@ describe Gitlab::DowntimeCheck::Message do
expect(message.to_s).to eq("[\e[32monline\e[0m]: foo.rb")
end
end
describe '#reason?' do
it 'returns false when no reason is specified' do
message = described_class.new('foo.rb')
expect(message.reason?).to eq(false)
end
it 'returns true when a reason is specified' do
message = described_class.new('foo.rb', true, 'hello')
expect(message.reason?).to eq(true)
end
end
describe '#reason' do
it 'strips excessive whitespace from the returned String' do
message = described_class.new('foo.rb', true, " hello\n world\n\n foo")
expect(message.reason).to eq("hello\nworld\n\nfoo")
end
end
end