summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/gitlab/ci/config/entry/include_spec.rb72
-rw-r--r--spec/lib/gitlab/ci/yaml_processor_spec.rb48
-rw-r--r--spec/lib/gitlab/git/blob_spec.rb24
-rw-r--r--spec/lib/gitlab/git/diff_stats_collection_spec.rb12
4 files changed, 137 insertions, 19 deletions
diff --git a/spec/lib/gitlab/ci/config/entry/include_spec.rb b/spec/lib/gitlab/ci/config/entry/include_spec.rb
new file mode 100644
index 00000000000..bab11f26fa1
--- /dev/null
+++ b/spec/lib/gitlab/ci/config/entry/include_spec.rb
@@ -0,0 +1,72 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe ::Gitlab::Ci::Config::Entry::Include do
+ subject(:include_entry) { described_class.new(config) }
+
+ describe 'validations' do
+ before do
+ include_entry.compose!
+ end
+
+ context 'when value is a string' do
+ let(:config) { 'test.yml' }
+
+ it { is_expected.to be_valid }
+ end
+
+ context 'when value is hash' do
+ context 'when using not allowed keys' do
+ let(:config) do
+ { not_allowed: 'key' }
+ end
+
+ it { is_expected.not_to be_valid }
+ end
+
+ context 'when using "local"' do
+ let(:config) { { local: 'test.yml' } }
+
+ it { is_expected.to be_valid }
+ end
+
+ context 'when using "file"' do
+ let(:config) { { file: 'test.yml' } }
+
+ it { is_expected.to be_valid }
+ end
+
+ context 'when using "template"' do
+ let(:config) { { template: 'test.yml' } }
+
+ it { is_expected.to be_valid }
+ end
+
+ context 'when using "artifact"' do
+ context 'and specifying "job"' do
+ let(:config) { { artifact: 'test.yml', job: 'generator' } }
+
+ it { is_expected.to be_valid }
+ end
+
+ context 'without "job"' do
+ let(:config) { { artifact: 'test.yml' } }
+
+ it { is_expected.not_to be_valid }
+
+ it 'has specific error' do
+ expect(include_entry.errors)
+ .to include('include config must specify the job where to fetch the artifact from')
+ end
+ end
+ end
+ end
+
+ context 'when value is something else' do
+ let(:config) { 123 }
+
+ it { is_expected.not_to be_valid }
+ end
+ end
+end
diff --git a/spec/lib/gitlab/ci/yaml_processor_spec.rb b/spec/lib/gitlab/ci/yaml_processor_spec.rb
index 62adba4319e..70c3c5ab339 100644
--- a/spec/lib/gitlab/ci/yaml_processor_spec.rb
+++ b/spec/lib/gitlab/ci/yaml_processor_spec.rb
@@ -2052,6 +2052,54 @@ module Gitlab
end
end
+ describe 'with parent-child pipeline' do
+ context 'when artifact and job are specified' do
+ let(:config) do
+ YAML.dump({
+ build1: { stage: 'build', script: 'test' },
+ test1: { stage: 'test', trigger: {
+ include: [{ artifact: 'generated.yml', job: 'build1' }]
+ } }
+ })
+ end
+
+ it { expect { subject }.not_to raise_error }
+ end
+
+ context 'when job is not specified specified while artifact is' do
+ let(:config) do
+ YAML.dump({
+ build1: { stage: 'build', script: 'test' },
+ test1: { stage: 'test', trigger: {
+ include: [{ artifact: 'generated.yml' }]
+ } }
+ })
+ end
+
+ it do
+ expect { subject }.to raise_error(
+ described_class::ValidationError,
+ /include config must specify the job where to fetch the artifact from/)
+ end
+ end
+
+ context 'when include is a string' do
+ let(:config) do
+ YAML.dump({
+ build1: { stage: 'build', script: 'test' },
+ test1: {
+ stage: 'test',
+ trigger: {
+ include: 'generated.yml'
+ }
+ }
+ })
+ end
+
+ it { expect { subject }.not_to raise_error }
+ end
+ end
+
describe "Error handling" do
it "fails to parse YAML" do
expect do
diff --git a/spec/lib/gitlab/git/blob_spec.rb b/spec/lib/gitlab/git/blob_spec.rb
index f25383ef416..06f9767d58b 100644
--- a/spec/lib/gitlab/git/blob_spec.rb
+++ b/spec/lib/gitlab/git/blob_spec.rb
@@ -301,26 +301,12 @@ describe Gitlab::Git::Blob, :seed_helper do
stub_const('Gitlab::Git::Blob::BATCH_SIZE', 2)
end
- context 'blobs_fetch_in_batches is enabled' do
- it 'fetches the blobs in batches' do
- expect(client).to receive(:get_blobs).with(first_batch, limit).ordered
- expect(client).to receive(:get_blobs).with(second_batch, limit).ordered
- expect(client).to receive(:get_blobs).with(third_batch, limit).ordered
+ it 'fetches the blobs in batches' do
+ expect(client).to receive(:get_blobs).with(first_batch, limit).ordered
+ expect(client).to receive(:get_blobs).with(second_batch, limit).ordered
+ expect(client).to receive(:get_blobs).with(third_batch, limit).ordered
- subject
- end
- end
-
- context 'blobs_fetch_in_batches is disabled' do
- before do
- stub_feature_flags(blobs_fetch_in_batches: false)
- end
-
- it 'fetches the blobs in a single batch' do
- expect(client).to receive(:get_blobs).with(blob_references, limit)
-
- subject
- end
+ subject
end
end
end
diff --git a/spec/lib/gitlab/git/diff_stats_collection_spec.rb b/spec/lib/gitlab/git/diff_stats_collection_spec.rb
index b07690ef39c..82d15a49062 100644
--- a/spec/lib/gitlab/git/diff_stats_collection_spec.rb
+++ b/spec/lib/gitlab/git/diff_stats_collection_spec.rb
@@ -29,4 +29,16 @@ describe Gitlab::Git::DiffStatsCollection do
expect(collection.paths).to eq %w[foo bar]
end
end
+
+ describe '#real_size' do
+ it 'returns the number of modified files' do
+ expect(collection.real_size).to eq('2')
+ end
+
+ it 'returns capped number when it is bigger than max_files' do
+ allow(::Commit).to receive(:max_diff_options).and_return(max_files: 1)
+
+ expect(collection.real_size).to eq('1+')
+ end
+ end
end