2020-04-22 19:07:51 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::CodeNavigationPath do
|
|
|
|
context 'when there is an artifact with code navigation data' do
|
2020-05-24 23:13:21 +05:30
|
|
|
let_it_be(:project) { create(:project, :repository) }
|
|
|
|
let_it_be(:sha) { project.repository.commits('master', limit: 5).last.id }
|
|
|
|
let_it_be(:pipeline) { create(:ci_pipeline, project: project, sha: sha) }
|
|
|
|
let_it_be(:job) { create(:ci_build, pipeline: pipeline) }
|
|
|
|
let_it_be(:artifact) { create(:ci_job_artifact, :lsif, job: job) }
|
|
|
|
|
|
|
|
let(:commit_sha) { sha }
|
2020-04-22 19:07:51 +05:30
|
|
|
let(:path) { 'lib/app.rb' }
|
2020-06-23 00:09:42 +05:30
|
|
|
let(:lsif_path) { "/#{project.full_path}/-/jobs/#{job.id}/artifacts/raw/lsif/#{path}.json?file_type=lsif" }
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
subject { described_class.new(project, commit_sha).full_json_path_for(path) }
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
before do
|
|
|
|
stub_feature_flags(code_navigation: project)
|
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
context 'when a pipeline exist for a sha' do
|
|
|
|
it 'returns path to a file in the artifact' do
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(subject).to eq(lsif_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when passed commit sha is nil' do
|
|
|
|
let(:commit_sha) { nil }
|
|
|
|
|
|
|
|
it 'returns path to a file in the artifact' do
|
|
|
|
expect(subject).to eq(lsif_path)
|
|
|
|
end
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a pipeline exist for the latest commits' do
|
|
|
|
let(:commit_sha) { project.commit.id }
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
it 'returns path to a file in the artifact' do
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(subject).to eq(lsif_path)
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when code_navigation feature is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(code_navigation: false)
|
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
it 'returns nil' do
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(subject).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|