README.asciidoc 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. The Elasticsearch docs are in AsciiDoc format and can be built using the
  2. Elasticsearch documentation build process.
  3. See: https://github.com/elastic/docs
  4. === Backporting doc fixes
  5. * Doc changes should generally be made against master and backported through to the current version
  6. (as applicable).
  7. * Changes can also be backported to the maintenance version of the previous major version.
  8. This is typically reserved for technical corrections, as it can require resolving more complex
  9. merge conflicts, fixing test failures, and figuring out where to apply the change.
  10. * Avoid backporting to out-of-maintenance versions.
  11. Docs follow the same policy as code and fixes are not ordinarily merged to
  12. versions that are out of maintenance.
  13. * Do not backport doc changes to https://www.elastic.co/support/eol[EOL versions].
  14. === Snippet testing
  15. Snippets marked with `[source,console]` are automatically annotated with
  16. "VIEW IN CONSOLE" and "COPY AS CURL" in the documentation and are automatically
  17. tested by the command `./gradlew -pdocs check`. To test just the docs from a
  18. single page, use e.g. `./gradlew -ddocs integTestRunner --tests "*rollover*"`.
  19. By default each `[source,console]` snippet runs as its own isolated test. You
  20. can manipulate the test execution in the following ways:
  21. * `// TEST`: Explicitly marks a snippet as a test. Snippets marked this way
  22. are tests even if they don't have `[source,console]` but usually `// TEST` is
  23. used for its modifiers:
  24. * `// TEST[s/foo/bar/]`: Replace `foo` with `bar` in the generated test. This
  25. should be used sparingly because it makes the snippet "lie". Sometimes,
  26. though, you can use it to make the snippet more clear. Keep in mind that
  27. if there are multiple substitutions then they are applied in the order that
  28. they are defined.
  29. * `// TEST[catch:foo]`: Used to expect errors in the requests. Replace `foo`
  30. with `request` to expect a 400 error, for example. If the snippet contains
  31. multiple requests then only the last request will expect the error.
  32. * `// TEST[continued]`: Continue the test started in the last snippet. Between
  33. tests the nodes are cleaned: indexes are removed, etc. This prevents that
  34. from happening between snippets because the two snippets are a single test.
  35. This is most useful when you have text and snippets that work together to
  36. tell the story of some use case because it merges the snippets (and thus the
  37. use case) into one big test.
  38. * You can't use `// TEST[continued]` immediately after `// TESTSETUP` or
  39. `// TEARDOWN`.
  40. * `// TEST[skip:reason]`: Skip this test. Replace `reason` with the actual
  41. reason to skip the test. Snippets without `// TEST` or `// CONSOLE` aren't
  42. considered tests anyway but this is useful for explicitly documenting the
  43. reason why the test shouldn't be run.
  44. * `// TEST[setup:name]`: Run some setup code before running the snippet. This
  45. is useful for creating and populating indexes used in the snippet. The setup
  46. code is defined in `docs/build.gradle`. See `// TESTSETUP` below for a
  47. similar feature.
  48. * `// TEST[warning:some warning]`: Expect the response to include a `Warning`
  49. header. If the response doesn't include a `Warning` header with the exact
  50. text then the test fails. If the response includes `Warning` headers that
  51. aren't expected then the test fails.
  52. * `[source,console-result]`: Matches this snippet against the body of the
  53. response of the last test. If the response is JSON then order is ignored. If
  54. you add `// TEST[continued]` to the snippet after `[source,console-result]`
  55. it will continue in the same test, allowing you to interleave requests with
  56. responses to check.
  57. * `// TESTRESPONSE`: Explicitly marks a snippet as a test response even without
  58. `[source,console-result]`. Similarly to `// TEST` this is mostly used for
  59. its modifiers.
  60. * You can't use `[source,console-result]` immediately after `// TESTSETUP`.
  61. Instead, consider using `// TEST[continued]` or rearrange your snippets.
  62. NOTE: Previously we only used `// TESTRESPONSE` instead of
  63. `[source,console-result]` so you'll see that a lot in older branches but we
  64. prefer `[source,console-result]` now.
  65. * `// TESTRESPONSE[s/foo/bar/]`: Substitutions. See `// TEST[s/foo/bar]` for
  66. how it works. These are much more common than `// TEST[s/foo/bar]` because
  67. they are useful for eliding portions of the response that are not pertinent
  68. to the documentation.
  69. * One interesting difference here is that you often want to match against
  70. the response from Elasticsearch. To do that you can reference the "body" of
  71. the response like this: `// TESTRESPONSE[s/"took": 25/"took": $body.took/]`.
  72. Note the `$body` string. This says "I don't expect that 25 number in the
  73. response, just match against what is in the response." Instead of writing
  74. the path into the response after `$body` you can write `$_path` which
  75. "figures out" the path. This is especially useful for making sweeping
  76. assertions like "I made up all the numbers in this example, don't compare
  77. them" which looks like `// TESTRESPONSE[s/\d+/$body.$_path/]`.
  78. * `// TESTRESPONSE[non_json]`: Add substitutions for testing responses in a
  79. format other than JSON. Use this after all other substitutions so it doesn't
  80. make other substitutions difficult.
  81. * `// TESTRESPONSE[skip:reason]`: Skip the assertions specified by this
  82. response.
  83. * `// TESTSETUP`: Marks this snippet as the "setup" for all other snippets in
  84. this file. This is a somewhat natural way of structuring documentation. You
  85. say "this is the data we use to explain this feature" then you add the
  86. snippet that you mark `// TESTSETUP` and then every snippet will turn into
  87. a test that runs the setup snippet first. See the "painless" docs for a file
  88. that puts this to good use. This is fairly similar to `// TEST[setup:name]`
  89. but rather than the setup defined in `docs/build.gradle` the setup is defined
  90. right in the documentation file. In general, we should prefer `// TESTSETUP`
  91. over `// TEST[setup:name]` because it makes it more clear what steps have to
  92. be taken before the examples will work. Tip: `// TESTSETUP` can only be used
  93. on the first snippet of a document.
  94. * `// TEARDOWN`: Ends and cleans up a test series started with `// TESTSETUP` or
  95. `// TEST[setup:name]`. You can use `// TEARDOWN` to set up multiple tests in
  96. the same file.
  97. * `// NOTCONSOLE`: Marks this snippet as neither `// CONSOLE` nor
  98. `// TESTRESPONSE`, excluding it from the list of unconverted snippets. We
  99. should only use this for snippets that *are* JSON but are *not* responses or
  100. requests.
  101. In addition to the standard CONSOLE syntax these snippets can contain blocks
  102. of yaml surrounded by markers like this:
  103. ```
  104. startyaml
  105. - compare_analyzers: {index: thai_example, first: thai, second: rebuilt_thai}
  106. endyaml
  107. ```
  108. This allows slightly more expressive testing of the snippets. Since that syntax
  109. is not supported by `[source,console]` the usual way to incorporate it is with a
  110. `// TEST[s//]` marker like this:
  111. ```
  112. // TEST[s/\n$/\nstartyaml\n - compare_analyzers: {index: thai_example, first: thai, second: rebuilt_thai}\nendyaml\n/]
  113. ```
  114. Any place you can use json you can use elements like `$body.path.to.thing`
  115. which is replaced on the fly with the contents of the thing at `path.to.thing`
  116. in the last response.