summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorMatija Čupić <matteeyah@gmail.com>2018-09-08 12:09:14 +0200
committerMatija Čupić <matteeyah@gmail.com>2018-09-08 12:09:14 +0200
commit797046e358bcf0fcd8cab413fcccad1614180aa9 (patch)
tree174dfc2e3851e8e4d2d74f6bfac7774295d488ee /spec
parent6a8133b943a8e06571f5497bea0f36c236b2bf90 (diff)
downloadgitlab-ce-797046e358bcf0fcd8cab413fcccad1614180aa9.tar.gz
Reconcile differences in lib/gitlab/ci/external/file
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/gitlab/ci/external/file/local_spec.rb59
-rw-r--r--spec/lib/gitlab/ci/external/file/remote_spec.rb52
2 files changed, 89 insertions, 22 deletions
diff --git a/spec/lib/gitlab/ci/external/file/local_spec.rb b/spec/lib/gitlab/ci/external/file/local_spec.rb
index 8d3545d5009..a4099703ac9 100644
--- a/spec/lib/gitlab/ci/external/file/local_spec.rb
+++ b/spec/lib/gitlab/ci/external/file/local_spec.rb
@@ -1,15 +1,15 @@
-require 'fast_spec_helper'
+require 'spec_helper'
describe Gitlab::Ci::External::File::Local do
let(:project) { create(:project, :repository) }
let(:local_file) { described_class.new(location, { project: project, sha: '12345' }) }
- describe "#valid?" do
+ describe '#valid?' do
context 'when is a valid local path' do
let(:location) { '/vendor/gitlab-ci-yml/existent-file.yml' }
before do
- allow_any_instance_of(described_class).to receive(:local_file_content).and_return("image: 'ruby2:2'")
+ allow_any_instance_of(described_class).to receive(:fetch_local_content).and_return("image: 'ruby2:2'")
end
it 'should return true' do
@@ -25,29 +25,52 @@ describe Gitlab::Ci::External::File::Local do
end
end
- describe "#content" do
+ context 'when is not a yaml file' do
+ let(:location) { '/config/application.rb' }
+
+ it 'should return false' do
+ expect(local_file.valid?).to be_falsy
+ end
+ end
+ end
+
+ describe '#content' do
+ context 'with a a valid file' do
let(:local_file_content) do
<<~HEREDOC
- before_script:
- - apt-get update -qq && apt-get install -y -qq sqlite3 libsqlite3-dev nodejs
- - ruby -v
- - which ruby
- - gem install bundler --no-ri --no-rdoc
- - bundle install --jobs $(nproc) "${FLAGS[@]}"
+ before_script:
+ - apt-get update -qq && apt-get install -y -qq sqlite3 libsqlite3-dev nodejs
+ - ruby -v
+ - which ruby
+ - gem install bundler --no-ri --no-rdoc
+ - bundle install --jobs $(nproc) "${FLAGS[@]}"
HEREDOC
end
+ let(:location) { '/vendor/gitlab-ci-yml/existent-file.yml' }
+
+ before do
+ allow_any_instance_of(described_class).to receive(:fetch_local_content).and_return(local_file_content)
+ end
- context 'with a local file' do
- let(:location) { '/vendor/gitlab-ci-yml/non-existent-file.yml' }
+ it 'should return the content of the file' do
+ expect(local_file.content).to eq(local_file_content)
+ end
+ end
- before do
- allow_any_instance_of(described_class).to receive(:local_file_content).and_return(local_file_content)
- end
+ context 'with an invalid file' do
+ let(:location) { '/vendor/gitlab-ci-yml/non-existent-file.yml' }
- it 'should return the content of the file' do
- expect(local_file.content).to eq(local_file_content)
- end
+ it 'should be nil' do
+ expect(local_file.content).to be_nil
end
end
end
+
+ describe '#error_message' do
+ let(:location) { '/vendor/gitlab-ci-yml/non-existent-file.yml' }
+
+ it 'should return an error message' do
+ expect(local_file.error_message).to eq("Local file '#{location}' is not valid.")
+ end
+ end
end
diff --git a/spec/lib/gitlab/ci/external/file/remote_spec.rb b/spec/lib/gitlab/ci/external/file/remote_spec.rb
index 620c8e1001e..314dcfec511 100644
--- a/spec/lib/gitlab/ci/external/file/remote_spec.rb
+++ b/spec/lib/gitlab/ci/external/file/remote_spec.rb
@@ -1,4 +1,4 @@
-require 'fast_spec_helper'
+require 'spec_helper'
describe Gitlab::Ci::External::File::Remote do
let(:remote_file) { described_class.new(location) }
@@ -25,7 +25,7 @@ describe Gitlab::Ci::External::File::Remote do
end
end
- context 'when is not a valid remote url' do
+ context 'with an irregular url' do
let(:location) { 'not-valid://gitlab.com/gitlab-org/gitlab-ce/blob/1234/.gitlab-ci-1.yml' }
it 'should return false' do
@@ -35,13 +35,29 @@ describe Gitlab::Ci::External::File::Remote do
context 'with a timeout' do
before do
- allow(HTTParty).to receive(:get).and_raise(Timeout::Error)
+ allow(Gitlab::HTTP).to receive(:get).and_raise(Timeout::Error)
end
it 'should be falsy' do
expect(remote_file.valid?).to be_falsy
end
end
+
+ context 'when is not a yaml file' do
+ let(:location) { 'https://asdasdasdaj48ggerexample.com' }
+
+ it 'should be falsy' do
+ expect(remote_file.valid?).to be_falsy
+ end
+ end
+
+ context 'with an internal url' do
+ let(:location) { 'http://localhost:8080' }
+
+ it 'should be falsy' do
+ expect(remote_file.valid?).to be_falsy
+ end
+ end
end
describe "#content" do
@@ -57,12 +73,40 @@ describe Gitlab::Ci::External::File::Remote do
context 'with a timeout' do
before do
- allow(HTTParty).to receive(:get).and_raise(Timeout::Error)
+ allow(Gitlab::HTTP).to receive(:get).and_raise(Timeout::Error)
end
it 'should be falsy' do
expect(remote_file.content).to be_falsy
end
end
+
+ context 'with an invalid remote url' do
+ let(:location) { 'https://asdasdasdaj48ggerexample.com' }
+
+ before do
+ WebMock.stub_request(:get, location).to_raise(SocketError.new('Some HTTP error'))
+ end
+
+ it 'should be nil' do
+ expect(remote_file.content).to be_nil
+ end
+ end
+
+ context 'with an internal url' do
+ let(:location) { 'http://localhost:8080' }
+
+ it 'should be nil' do
+ expect(remote_file.content).to be_nil
+ end
+ end
+ end
+
+ describe "#error_message" do
+ let(:location) { 'not-valid://gitlab.com/gitlab-org/gitlab-ce/blob/1234/.gitlab-ci-1.yml' }
+
+ it 'should return an error message' do
+ expect(remote_file.error_message).to eq("Remote file '#{location}' is not valid.")
+ end
end
end