|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +## |
| 4 | +# Assertions about when books are rebuilt based on changes in source |
| 5 | +# repositories or the book's configuration. |
| 6 | +RSpec.describe 'building all books' do |
| 7 | + KIBANA_LINKS_FILE = 'src/ui/public/documentation_links/documentation_links.js' |
| 8 | + shared_context 'there is a broken link in the docs' do |check_links| |
| 9 | + convert_before do |src, dest| |
| 10 | + repo = src.repo_with_index 'repo', 'https://www.elastic.co/guide/foo' |
| 11 | + book = src.book 'Test' |
| 12 | + book.source repo, 'index.asciidoc' |
| 13 | + convert = dest.prepare_convert_all src.conf |
| 14 | + convert.skip_link_check unless check_links |
| 15 | + convert.convert(expect_failure: check_links) |
| 16 | + end |
| 17 | + end |
| 18 | + shared_context 'there is a broken link in kibana' do |check_links| |
| 19 | + convert_before do |src, dest| |
| 20 | + # Kibana is special and we check links in it with a little magic |
| 21 | + kibana_repo = src.repo 'kibana' |
| 22 | + kibana_repo.write KIBANA_LINKS_FILE, <<~JS |
| 23 | + export const documentationLinks = { |
| 24 | + foo: `${ELASTIC_WEBSITE_URL}guide/foo`, |
| 25 | + }; |
| 26 | + JS |
| 27 | + kibana_repo.commit 'init' |
| 28 | + |
| 29 | + # The preview of the book is important here because it is how we detect |
| 30 | + # the versions of kibana to check. |
| 31 | + # NOCOMMIT maybe we shouldn't?! |
| 32 | + repo = src.repo_with_index 'repo', "Doesn't matter" |
| 33 | + book = src.book 'Test', prefix: 'en/kibana' |
| 34 | + book.source repo, 'index.asciidoc' |
| 35 | + convert = dest.prepare_convert_all src.conf |
| 36 | + convert.skip_link_check unless check_links |
| 37 | + convert.convert(expect_failure: check_links) |
| 38 | + end |
| 39 | + end |
| 40 | + |
| 41 | + describe 'when broken link detection is disabled' do |
| 42 | + describe 'when there is a broken link in the docs' do |
| 43 | + include_context 'there is a broken link in the docs', false |
| 44 | + it 'logs that it skipped link checking' do |
| 45 | + expect(outputs[0]).to include('Skipped Checking links') |
| 46 | + end |
| 47 | + end |
| 48 | + describe 'when there is a broken link in kibana' do |
| 49 | + include_context 'there is a broken link in kibana', false |
| 50 | + it 'logs that it skipped link checking' do |
| 51 | + expect(outputs[0]).to include('Skipped Checking links') |
| 52 | + end |
| 53 | + end |
| 54 | + end |
| 55 | + describe 'when broken link detection is enabled' do |
| 56 | + shared_examples 'all links are ok' do |
| 57 | + it 'logs that all the links are ok' do |
| 58 | + expect(outputs[-1]).to include('All cross-document links OK') |
| 59 | + end |
| 60 | + end |
| 61 | + shared_examples 'there are broken links in kibana' do |
| 62 | + it 'logs there are bad cross document links' do |
| 63 | + expect(outputs[-1]).to include('Bad cross-document links:') |
| 64 | + end |
| 65 | + it 'logs the bad link' do |
| 66 | + expect(outputs[-1]).to include(indent(<<~LOG.strip, ' ')) |
| 67 | + Kibana [master]: src/ui/public/documentation_links/documentation_links.js: |
| 68 | + - foo |
| 69 | + LOG |
| 70 | + end |
| 71 | + end |
| 72 | + describe 'when all of the links are intact' do |
| 73 | + convert_before do |src, dest| |
| 74 | + repo = src.repo_with_index( |
| 75 | + 'repo', |
| 76 | + 'https://www.elastic.co/guide/test/current/chapter.html' |
| 77 | + ) |
| 78 | + book = src.book 'Test' |
| 79 | + book.source repo, 'index.asciidoc' |
| 80 | + dest.prepare_convert_all(src.conf).convert |
| 81 | + end |
| 82 | + include_examples 'all links are ok' |
| 83 | + end |
| 84 | + describe 'when there is a broken link in the docs' do |
| 85 | + include_context 'there is a broken link in the docs', true |
| 86 | + it 'logs there are bad cross document links' do |
| 87 | + expect(outputs[0]).to include('Bad cross-document links:') |
| 88 | + end |
| 89 | + it 'logs the bad link' do |
| 90 | + expect(outputs[0]).to include(indent(<<~LOG.strip, ' ')) |
| 91 | + /tmp/docsbuild/target_repo/html/test/current/chapter.html: |
| 92 | + - foo |
| 93 | + LOG |
| 94 | + end |
| 95 | + end |
| 96 | + describe 'when there is a broken link in kibana' do |
| 97 | + include_context 'there is a broken link in kibana', true |
| 98 | + include_examples 'there are broken links in kibana' |
| 99 | + end |
| 100 | + describe 'when using --keep_hash and --sub_dir together like a PR test' do |
| 101 | + describe 'when there is a broken link in one of the books being built' do |
| 102 | + convert_before do |src, dest| |
| 103 | + repo1 = src.repo_with_index 'repo1', "Doesn't matter" |
| 104 | + book1 = src.book 'Test1' |
| 105 | + book1.source repo1, 'index.asciidoc' |
| 106 | + repo2 = src.repo_with_index 'repo2', "Also doesn't matter" |
| 107 | + book2 = src.book 'Test2' |
| 108 | + book2.source repo2, 'index.asciidoc' |
| 109 | + dest.prepare_convert_all(src.conf).convert |
| 110 | + |
| 111 | + repo2.write 'index.asciidoc', <<~ASCIIDOC |
| 112 | + = Title |
| 113 | +
|
| 114 | + [[chapter]] |
| 115 | + == Chapter |
| 116 | + https://www.elastic.co/guide/foo |
| 117 | + ASCIIDOC |
| 118 | + dest.prepare_convert_all(src.conf) |
| 119 | + .keep_hash |
| 120 | + .sub_dir(repo2, 'master') |
| 121 | + .convert(expect_failure: true) |
| 122 | + end |
| 123 | + it 'logs there are bad cross document links' do |
| 124 | + expect(outputs[1]).to include('Bad cross-document links:') |
| 125 | + end |
| 126 | + it 'logs the bad link' do |
| 127 | + expect(outputs[1]).to include(indent(<<~LOG.strip, ' ')) |
| 128 | + /tmp/docsbuild/target_repo/html/test2/current/chapter.html: |
| 129 | + - foo |
| 130 | + LOG |
| 131 | + end |
| 132 | + end |
| 133 | + describe "when there is a broken link in a book that isn't being built" do |
| 134 | + convert_before do |src, dest| |
| 135 | + repo1 = src.repo_with_index 'repo1', "Doesn't matter" |
| 136 | + book1 = src.book 'Test1' |
| 137 | + book1.source repo1, 'index.asciidoc' |
| 138 | + repo2 = src.repo_with_index 'repo2', "Also doesn't matter" |
| 139 | + book2 = src.book 'Test2' |
| 140 | + book2.source repo2, 'index.asciidoc' |
| 141 | + dest.prepare_convert_all(src.conf).convert |
| 142 | + |
| 143 | + repo1.write 'index.asciidoc', <<~ASCIIDOC |
| 144 | + = Title |
| 145 | +
|
| 146 | + [[chapter]] |
| 147 | + == Chapter |
| 148 | + https://www.elastic.co/guide/foo |
| 149 | + ASCIIDOC |
| 150 | + dest.prepare_convert_all(src.conf) |
| 151 | + .keep_hash |
| 152 | + .sub_dir(repo2, 'master') |
| 153 | + .convert |
| 154 | + end |
| 155 | + include_examples 'all links are ok' |
| 156 | + end |
| 157 | + describe 'when there is a broken link in kibana' do |
| 158 | + def self.setup(src, dest) |
| 159 | + kibana_repo = src.repo_with_index 'kibana', "Doesn't matter" |
| 160 | + kibana_repo.write KIBANA_LINKS_FILE, 'no links here' |
| 161 | + kibana_repo.commit 'add empty links file' |
| 162 | + kibana_book = src.book 'Kibana', prefix: 'en/kibana' |
| 163 | + kibana_book.source kibana_repo, 'index.asciidoc' |
| 164 | + repo2 = src.repo_with_index 'repo2', "Also doesn't matter" |
| 165 | + book2 = src.book 'Test2' |
| 166 | + book2.source repo2, 'index.asciidoc' |
| 167 | + dest.prepare_convert_all(src.conf).convert |
| 168 | + |
| 169 | + kibana_repo.write KIBANA_LINKS_FILE, <<~JS |
| 170 | + export const documentationLinks = { |
| 171 | + foo: `${ELASTIC_WEBSITE_URL}guide/foo`, |
| 172 | + }; |
| 173 | + JS |
| 174 | + end |
| 175 | + describe 'when the broken link is in an unbuilt branch' do |
| 176 | + convert_before do |src, dest| |
| 177 | + setup src, dest |
| 178 | + src.repo('kibana').commit 'add bad link' |
| 179 | + dest.prepare_convert_all(src.conf) |
| 180 | + .keep_hash |
| 181 | + .sub_dir(src.repo('repo2'), 'master') |
| 182 | + .convert |
| 183 | + end |
| 184 | + include_examples 'all links are ok' |
| 185 | + end |
| 186 | + describe 'when the broken link is in an *new* unbuilt branch' do |
| 187 | + convert_before do |src, dest| |
| 188 | + setup src, dest |
| 189 | + kibana = src.repo('kibana') |
| 190 | + kibana.switch_to_new_branch 'new_branch' |
| 191 | + kibana.commit 'add bad link' |
| 192 | + dest.prepare_convert_all(src.conf) |
| 193 | + .keep_hash |
| 194 | + .sub_dir(src.repo('repo2'), 'master') |
| 195 | + .convert |
| 196 | + end |
| 197 | + include_examples 'all links are ok' |
| 198 | + end |
| 199 | + describe 'when the broken link is in the --sub_dir' do |
| 200 | + convert_before do |src, dest| |
| 201 | + setup src, dest |
| 202 | + dest.prepare_convert_all(src.conf) |
| 203 | + .keep_hash |
| 204 | + .sub_dir(src.repo('kibana'), 'master') |
| 205 | + .convert(expect_failure: true) |
| 206 | + end |
| 207 | + include_examples 'there are broken links in kibana' |
| 208 | + end |
| 209 | + end |
| 210 | + end |
| 211 | + end |
| 212 | +end |
0 commit comments