debian-mirror-gitlab/spec/lib/gitlab/ci/ansi2json/state_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

69 lines
1.8 KiB
Ruby
Raw Permalink Normal View History

2023-06-20 00:43:36 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Ci::Ansi2json::State, feature_category: :continuous_integration do
2023-07-09 08:55:56 +05:30
def build_state
described_class.new('', 1000).tap do |state|
2023-06-20 00:43:36 +05:30
state.offset = 1
state.new_line!(style: { fg: 'some-fg', bg: 'some-bg', mask: 1234 })
state.set_last_line_offset
state.open_section('hello', 111, {})
end
end
2023-07-09 08:55:56 +05:30
let(:state) { build_state }
2023-06-20 00:43:36 +05:30
describe '#initialize' do
it 'restores valid prior state', :aggregate_failures do
new_state = described_class.new(state.encode, 1000)
expect(new_state.offset).to eq(1)
expect(new_state.inherited_style).to eq({
bg: 'some-bg',
fg: 'some-fg',
mask: 1234
})
expect(new_state.open_sections).to eq({ 'hello' => 111 })
end
2023-07-09 08:55:56 +05:30
it 'ignores unsigned prior state', :aggregate_failures do
unsigned, _ = build_state.encode.split('--')
2023-06-20 00:43:36 +05:30
expect(::Gitlab::AppLogger).to(
receive(:warn).with(
2023-07-09 08:55:56 +05:30
message: a_string_matching(/signature missing or invalid/),
invalid_state: unsigned
2023-06-20 00:43:36 +05:30
)
)
2023-07-09 08:55:56 +05:30
new_state = described_class.new(unsigned, 0)
2023-06-20 00:43:36 +05:30
expect(new_state.offset).to eq(0)
expect(new_state.inherited_style).to eq({})
expect(new_state.open_sections).to eq({})
end
2023-07-09 08:55:56 +05:30
it 'ignores bad input', :aggregate_failures do
2023-06-20 00:43:36 +05:30
expect(::Gitlab::AppLogger).to(
receive(:warn).with(
2023-07-09 08:55:56 +05:30
message: a_string_matching(/signature missing or invalid/),
invalid_state: 'abcd'
2023-06-20 00:43:36 +05:30
)
)
2023-07-09 08:55:56 +05:30
new_state = described_class.new('abcd', 0)
2023-06-20 00:43:36 +05:30
expect(new_state.offset).to eq(0)
expect(new_state.inherited_style).to eq({})
expect(new_state.open_sections).to eq({})
end
2023-07-09 08:55:56 +05:30
end
2023-06-20 00:43:36 +05:30
2023-07-09 08:55:56 +05:30
describe '#encode' do
it 'deterministically signs the state' do
expect(state.encode).to eq state.encode
2023-06-20 00:43:36 +05:30
end
end
end