2020-04-02 05:08:14 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Gitlab::CodeNavigationPath do
|
2020-04-02 05:08:14 -04:00
|
|
|
context 'when there is an artifact with code navigation data' do
|
2020-05-13 08:07:54 -04:00
|
|
|
let_it_be(:project) { create(:project, :repository) }
|
2020-07-07 11:08:49 -04:00
|
|
|
let_it_be(:sha) { project.repository.commits('master', limit: Gitlab::CodeNavigationPath::LATEST_COMMITS_LIMIT).last.id }
|
2020-05-13 08:07:54 -04:00
|
|
|
let_it_be(:pipeline) { create(:ci_pipeline, project: project, sha: sha) }
|
2020-05-15 17:08:21 -04:00
|
|
|
let_it_be(:job) { create(:ci_build, pipeline: pipeline) }
|
2020-05-13 08:07:54 -04:00
|
|
|
let_it_be(:artifact) { create(:ci_job_artifact, :lsif, job: job) }
|
|
|
|
|
|
|
|
let(:commit_sha) { sha }
|
2020-04-02 05:08:14 -04:00
|
|
|
let(:path) { 'lib/app.rb' }
|
2020-06-15 11:08:20 -04:00
|
|
|
let(:lsif_path) { "/#{project.full_path}/-/jobs/#{job.id}/artifacts/raw/lsif/#{path}.json?file_type=lsif" }
|
2020-04-02 05:08:14 -04:00
|
|
|
|
2020-05-13 08:07:54 -04:00
|
|
|
subject { described_class.new(project, commit_sha).full_json_path_for(path) }
|
|
|
|
|
|
|
|
context 'when a pipeline exist for a sha' do
|
|
|
|
it 'returns path to a file in the artifact' do
|
2020-06-15 11:08:20 -04:00
|
|
|
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-13 08:07:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a pipeline exist for the latest commits' do
|
|
|
|
let(:commit_sha) { project.commit.id }
|
2020-04-02 05:08:14 -04:00
|
|
|
|
2020-05-13 08:07:54 -04:00
|
|
|
it 'returns path to a file in the artifact' do
|
2020-06-15 11:08:20 -04:00
|
|
|
expect(subject).to eq(lsif_path)
|
2020-05-13 08:07:54 -04:00
|
|
|
end
|
2020-04-02 05:08:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|