Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for the Kibana link checking changes in #2085 #2086

Merged
merged 2 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions integtest/spec/all_books_broken_link_detection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Assertions about when books are rebuilt based on changes in source
# repositories or the book's configuration.
RSpec.describe 'building all books' do
KIBANA_LINKS_FILE = 'src/ui/public/documentation_links/documentation_links.js'
KIBANA_LINKS_FILE = 'src/core/public/doc_links/doc_links_service.ts'
shared_context 'there is a broken link in the docs' do |text, check_links|
convert_before do |src, dest|
repo = src.repo_with_index 'repo', text
Expand All @@ -25,13 +25,13 @@
include_context 'there is a broken link in the docs',
'link:/guide/foo[]', check_links
end
shared_context 'there is a broken link in kibana' do |check_links|
shared_context 'there is a kibana link' do |check_links, url, expect_failure|
convert_before do |src, dest|
# Kibana is special and we check links in it with a little magic
kibana_repo = src.repo 'kibana'
kibana_repo.write KIBANA_LINKS_FILE, <<~JS
export const documentationLinks = {
foo: `${ELASTIC_WEBSITE_URL}guide/foo`,
foo: `#{url}`,
};
JS
kibana_repo.commit 'init'
Expand All @@ -44,10 +44,17 @@
book.source repo, 'index.asciidoc'
convert = dest.prepare_convert_all src.conf
convert.skip_link_check unless check_links
convert.convert(expect_failure: check_links)
convert.convert(expect_failure: expect_failure)
end
end

shared_context 'there is a broken link in kibana' do |check_links|
# If we check links, we expect failure, and if we don't check links, we
# don't expect failure.
include_context 'there is a kibana link', check_links,
'${ELASTIC_WEBSITE_URL}guide/foo', check_links
end

describe 'when broken link detection is disabled' do
describe 'when there is a broken absolute link in the docs' do
include_context 'there is a broken absolute link in the docs', false
Expand Down Expand Up @@ -85,14 +92,14 @@
LOG
end
end
shared_examples 'there are broken links in kibana' do
shared_examples 'there are broken links in kibana' do |url|
it 'logs there are bad cross document links' do
expect(outputs[-1]).to include('Bad cross-document links:')
end
it 'logs the bad link' do
expect(outputs[-1]).to include(indent(<<~LOG.strip, ' '))
Kibana [master]: src/ui/public/documentation_links/documentation_links.js contains broken links to:
- foo
Kibana [master]: src/core/public/doc_links/doc_links_service.ts contains broken links to:
- #{url}
LOG
end
end
Expand All @@ -118,7 +125,18 @@
end
describe 'when there is a broken link in kibana' do
include_context 'there is a broken link in kibana', true
include_examples 'there are broken links in kibana'
include_examples 'there are broken links in kibana', 'foo'
end
describe 'when a link in kibana goes to the website outside the guide' do
include_context 'there is a kibana link', true,
'${ELASTIC_WEBSITE_URL}not-part-of-the-guide', false
include_examples 'all links are ok'
end
describe 'when there is a broken Elasticsearch reference link in Kibana' do
include_context 'there is a kibana link', true,
'${ELASTICSEARCH_DOCS}missing-page', true
include_examples 'there are broken links in kibana',
'en/elasticsearch/reference/master/missing-page'
end
describe 'when using --keep_hash and --sub_dir together like a PR test' do
describe 'when there is a broken link in one of the books being built' do
Expand Down Expand Up @@ -191,7 +209,7 @@ def self.setup(src, dest)

kibana_repo.write KIBANA_LINKS_FILE, <<~JS
export const documentationLinks = {
foo: `${ELASTIC_WEBSITE_URL}guide/foo`,
foo: `${ELASTIC_WEBSITE_URL}guide/bar`,
};
JS
end
Expand Down Expand Up @@ -227,7 +245,7 @@ def self.setup(src, dest)
.sub_dir(src.repo('kibana'), 'master')
.convert(expect_failure: true)
end
include_examples 'there are broken links in kibana'
include_examples 'there are broken links in kibana', 'bar'
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion integtest/spec/all_books_change_detection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def chapter(index)
# 3. A book at `en/kibana`
kibana_repo = src.repo_with_index 'kibana', 'words'
kibana_repo.write(
'src/ui/public/documentation_links/documentation_links.ts',
'src/core/public/doc_links/doc_links_service.ts',
'text but no links actually'
)
kibana_repo.commit 'add links file'
Expand Down