debian-mirror-gitlab/spec/lib/gitlab/gitaly_client/wiki_service_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

119 lines
4.1 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::GitalyClient::WikiService do
2018-03-17 18:26:18 +05:30
let(:project) { create(:project) }
let(:storage_name) { project.repository_storage }
let(:relative_path) { project.disk_path + '.git' }
let(:client) { described_class.new(project.repository) }
let(:commit) { create(:gitaly_commit) }
let(:page_version) { Gitaly::WikiPageVersion.new(format: 'markdown', commit: commit) }
let(:page_info) { { title: 'My Page', raw_data: 'a', version: page_version } }
describe '#find_page' do
let(:response) do
[
Gitaly::WikiFindPageResponse.new(page: Gitaly::WikiPage.new(page_info)),
Gitaly::WikiFindPageResponse.new(page: Gitaly::WikiPage.new(raw_data: 'b'))
]
end
2020-10-24 23:57:45 +05:30
2018-03-17 18:26:18 +05:30
let(:wiki_page) { subject.first }
let(:wiki_page_version) { subject.last }
subject { client.find_page(title: 'My Page', version: 'master', dir: '') }
it 'sends a wiki_find_page message' do
expect_any_instance_of(Gitaly::WikiService::Stub)
.to receive(:wiki_find_page)
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
.and_return([].each)
subject
end
it 'concatenates the raw data and returns a pair of WikiPage and WikiPageVersion' do
expect_any_instance_of(Gitaly::WikiService::Stub)
.to receive(:wiki_find_page)
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
.and_return(response.each)
expect(wiki_page.title).to eq('My Page')
expect(wiki_page.raw_data).to eq('ab')
expect(wiki_page_version.format).to eq('markdown')
2018-12-05 23:21:45 +05:30
expect(wiki_page.title).to be_utf8
expect(wiki_page.path).to be_utf8
expect(wiki_page.name).to be_utf8
2018-03-17 18:26:18 +05:30
end
end
2019-07-31 22:56:46 +05:30
describe '#load_all_pages' do
2018-03-17 18:26:18 +05:30
let(:page_2_info) { { title: 'My Page 2', raw_data: 'c', version: page_version } }
let(:response) do
[
Gitaly::WikiGetAllPagesResponse.new(page: Gitaly::WikiPage.new(page_info)),
Gitaly::WikiGetAllPagesResponse.new(page: Gitaly::WikiPage.new(raw_data: 'b')),
Gitaly::WikiGetAllPagesResponse.new(end_of_page: true),
Gitaly::WikiGetAllPagesResponse.new(page: Gitaly::WikiPage.new(page_2_info)),
Gitaly::WikiGetAllPagesResponse.new(page: Gitaly::WikiPage.new(raw_data: 'd')),
Gitaly::WikiGetAllPagesResponse.new(end_of_page: true)
]
end
2020-10-24 23:57:45 +05:30
2018-03-17 18:26:18 +05:30
let(:wiki_page_1) { subject[0].first }
let(:wiki_page_1_version) { subject[0].last }
let(:wiki_page_2) { subject[1].first }
let(:wiki_page_2_version) { subject[1].last }
2019-07-31 22:56:46 +05:30
subject { client.load_all_pages }
2018-03-17 18:26:18 +05:30
it 'sends a wiki_get_all_pages message' do
expect_any_instance_of(Gitaly::WikiService::Stub)
.to receive(:wiki_get_all_pages)
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
.and_return([].each)
subject
end
2018-11-18 11:00:15 +05:30
it 'sends a limit of 0 to wiki_get_all_pages' do
expect_any_instance_of(Gitaly::WikiService::Stub)
.to receive(:wiki_get_all_pages)
.with(gitaly_request_with_params(limit: 0), kind_of(Hash))
.and_return([].each)
subject
end
2018-03-17 18:26:18 +05:30
it 'concatenates the raw data and returns a pair of WikiPage and WikiPageVersion for each page' do
expect_any_instance_of(Gitaly::WikiService::Stub)
.to receive(:wiki_get_all_pages)
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
.and_return(response.each)
expect(subject.size).to be(2)
expect(wiki_page_1.title).to eq('My Page')
expect(wiki_page_1.raw_data).to eq('ab')
expect(wiki_page_1_version.format).to eq('markdown')
expect(wiki_page_2.title).to eq('My Page 2')
expect(wiki_page_2.raw_data).to eq('cd')
expect(wiki_page_2_version.format).to eq('markdown')
end
2018-11-18 11:00:15 +05:30
context 'with limits' do
2019-07-31 22:56:46 +05:30
subject { client.load_all_pages(limit: 1) }
2018-11-18 11:00:15 +05:30
it 'sends a request with the limit' do
expect_any_instance_of(Gitaly::WikiService::Stub)
.to receive(:wiki_get_all_pages)
.with(gitaly_request_with_params(limit: 1), kind_of(Hash))
.and_return([].each)
subject
end
end
2018-03-17 18:26:18 +05:30
end
end