debian-mirror-gitlab/spec/models/ci/build_trace_chunks/fog_spec.rb

169 lines
4.2 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
2018-11-08 19:23:39 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Ci::BuildTraceChunks::Fog do
2018-11-08 19:23:39 +05:30
let(:data_store) { described_class.new }
2021-01-03 14:25:43 +05:30
let(:bucket) { 'artifacts' }
let(:connection_params) { Gitlab.config.artifacts.object_store.connection.symbolize_keys }
let(:connection) { ::Fog::Storage.new(connection_params) }
2018-11-08 19:23:39 +05:30
before do
2021-01-03 14:25:43 +05:30
stub_object_storage(connection_params: connection_params, remote_directory: bucket)
2018-11-08 19:23:39 +05:30
stub_artifacts_object_storage
end
describe '#available?' do
subject { data_store.available? }
context 'when object storage is enabled' do
it { is_expected.to be_truthy }
end
context 'when object storage is disabled' do
before do
stub_artifacts_object_storage(enabled: false)
end
it { is_expected.to be_falsy }
end
end
describe '#data' do
subject { data_store.data(model) }
context 'when data exists' do
let(:model) { create(:ci_build_trace_chunk, :fog_with_data, initial_data: 'sample data in fog') }
it 'returns the data' do
is_expected.to eq('sample data in fog')
end
end
context 'when data does not exist' do
let(:model) { create(:ci_build_trace_chunk, :fog_without_data) }
it 'returns nil' do
2020-10-24 23:57:45 +05:30
expect(data_store.data(model)).to be_nil
2018-11-08 19:23:39 +05:30
end
end
end
describe '#set_data' do
2020-11-24 15:15:51 +05:30
let(:new_data) { 'abc123' }
2018-11-08 19:23:39 +05:30
context 'when data exists' do
let(:model) { create(:ci_build_trace_chunk, :fog_with_data, initial_data: 'sample data in fog') }
it 'overwrites data' do
expect(data_store.data(model)).to eq('sample data in fog')
2020-11-24 15:15:51 +05:30
data_store.set_data(model, new_data)
2018-11-08 19:23:39 +05:30
2020-11-24 15:15:51 +05:30
expect(data_store.data(model)).to eq new_data
2018-11-08 19:23:39 +05:30
end
end
context 'when data does not exist' do
let(:model) { create(:ci_build_trace_chunk, :fog_without_data) }
it 'sets new data' do
2020-10-24 23:57:45 +05:30
expect(data_store.data(model)).to be_nil
2018-11-08 19:23:39 +05:30
2020-11-24 15:15:51 +05:30
data_store.set_data(model, new_data)
2018-11-08 19:23:39 +05:30
2020-11-24 15:15:51 +05:30
expect(data_store.data(model)).to eq new_data
2018-11-08 19:23:39 +05:30
end
end
end
describe '#delete_data' do
subject { data_store.delete_data(model) }
context 'when data exists' do
let(:model) { create(:ci_build_trace_chunk, :fog_with_data, initial_data: 'sample data in fog') }
it 'deletes data' do
expect(data_store.data(model)).to eq('sample data in fog')
subject
2020-10-24 23:57:45 +05:30
expect(data_store.data(model)).to be_nil
2018-11-08 19:23:39 +05:30
end
end
context 'when data does not exist' do
let(:model) { create(:ci_build_trace_chunk, :fog_without_data) }
it 'does nothing' do
2020-10-24 23:57:45 +05:30
expect(data_store.data(model)).to be_nil
2018-11-08 19:23:39 +05:30
subject
2020-10-24 23:57:45 +05:30
expect(data_store.data(model)).to be_nil
end
end
end
describe '#size' do
context 'when data exists' do
let(:model) { create(:ci_build_trace_chunk, :fog_with_data, initial_data: 'üabcd') }
it 'returns data bytesize correctly' do
expect(data_store.size(model)).to eq 6
end
end
context 'when data does not exist' do
let(:model) { create(:ci_build_trace_chunk, :fog_without_data) }
it 'returns zero' do
expect(data_store.size(model)).to be_zero
2018-11-08 19:23:39 +05:30
end
end
end
describe '#keys' do
subject { data_store.keys(relation) }
let(:build) { create(:ci_build) }
let(:relation) { build.trace_chunks }
before do
create(:ci_build_trace_chunk, :fog_with_data, chunk_index: 0, build: build)
create(:ci_build_trace_chunk, :fog_with_data, chunk_index: 1, build: build)
end
it 'returns keys' do
is_expected.to eq([[build.id, 0], [build.id, 1]])
end
end
describe '#delete_keys' do
subject { data_store.delete_keys(keys) }
let(:build) { create(:ci_build) }
let(:relation) { build.trace_chunks }
let(:keys) { data_store.keys(relation) }
before do
create(:ci_build_trace_chunk, :fog_with_data, chunk_index: 0, build: build)
create(:ci_build_trace_chunk, :fog_with_data, chunk_index: 1, build: build)
end
it 'deletes multiple data' do
2021-01-03 14:25:43 +05:30
files = connection.directories.new(key: bucket).files
expect(files.count).to eq(2)
expect(files[0].body).to be_present
expect(files[1].body).to be_present
2018-11-08 19:23:39 +05:30
subject
2021-01-03 14:25:43 +05:30
files.reload
expect(files.count).to eq(0)
2018-11-08 19:23:39 +05:30
end
end
end