---
"Help":
    - skip:
        version: " - 5.99.99"
        reason:  this uses a new API that has been added in 6.0
    - do:
        cat.templates:
          help: true

    - match:
        $body: |
                   /^  name             .+   \n
                       index_patterns   .+   \n
                       order            .+   \n
                       version          .+   \n
                   $/

---
"No templates":
    - skip:
        version: " - 5.0.99"
        reason:  templates were introduced in 5.1.0
    - do:
        cat.templates: {}

    - match:
        $body: |
               /^
               $/

---
"Normal templates":

    - skip:
        version: " - 5.99.99"
        reason:  this uses a new API that has been added in 6.0

    - do:
        indices.put_template:
          name: test
          body:
            order: 0
            version: 1
            index_patterns: test-*
            settings:
              number_of_shards: 1
              number_of_replicas: 0

    - do:
        indices.put_template:
          name: test_2
          body:
            order: 1
            version: 2
            index_patterns: test-2*
            settings:
              number_of_shards: 1
              number_of_replicas: 0

    - do:
        cat.templates: {}

    - match:
        $body: >
               /
                 (^|\n)test     \s+
                 \[test-\*\]    \s+
                 0              \s+
                 1
                 (\n|$)
               /

    - match:
        $body: >
               /
                (^|\n)test_2    \s+
                \[test-2\*\]    \s+
                1               \s+
                2
                (\n|$)
               /

---
"Filtered templates":

    - skip:
        version: " - 5.99.99"
        reason:  this uses a new API that has been added in 6.0

    - do:
        indices.put_template:
          name: test
          body:
            order: 0
            version: 1
            index_patterns: t*
            settings:
              number_of_shards: 1
              number_of_replicas: 0

    - do:
        indices.put_template:
          name: nomatch
          body:
            order: 2
            version: 1
            index_patterns: tea*
            settings:
              number_of_shards: 1
              number_of_replicas: 0

    - do:
        cat.templates:
            name: test*

    - match:
        $body: |
                /^
                    test    \s+
                    \[t\*\] \s+
                    0       \s+
                    1
                    \n
                $/

---
"Column headers":
    - skip:
        version: " - 5.99.99"
        reason:  this uses a new API that has been added in 6.0
    - do:
        indices.put_template:
          name: test
          body:
            order: 0
            version: 1
            index_patterns: t*
            settings:
              number_of_shards: 1
              number_of_replicas: 0

    - do:
        cat.templates:
            v: true
            name: test

    - match:
        $body: |
                 /^
                    name            \s+
                    index_patterns  \s+
                    order           \s+
                    version
                    \n
                    test            \s+
                    \[t\*\]         \s+
                    0               \s+
                    1
                    \n
                 $/

---
"Select columns":
    - skip:
        version: " - 5.99.99"
        reason:  this uses a new API that has been added in 6.0
    - do:
        indices.put_template:
          name: test
          body:
            order: 0
            version: 1
            index_patterns: t*
            settings:
              number_of_shards: 1
              number_of_replicas: 0

    - do:
        cat.templates:
            h:  [name, index_patterns]
            v:  true
            name: test*

    - match:
        $body: |
                /^
                    name        \s+
                    index_patterns
                    \n
                    test        \s+
                    \[t\*\]
                    \n
                $/

---
"Sort templates":
    - skip:
        version: " - 5.99.99"
        reason:  this uses a new API that has been added in 6.0
    - do:
        indices.put_template:
          name: test
          body:
            order: 0
            index_patterns: t*
            settings:
              number_of_shards: 1
              number_of_replicas: 0

    - do:
        indices.put_template:
          name: test_1
          body:
            order: 0
            version: 1
            index_patterns: te*
            settings:
              number_of_shards: 1
              number_of_replicas: 0

    - do:
        cat.templates:
            h: [name, index_patterns, version]
            s: [version]

    - match:
        $body: |
              /^
                  test   \s+ \[t\*\]  \s+   \n
                  test_1 \s+ \[te\*\] \s+ 1 \n
              $/

    - do:
        cat.templates:
            h: [name, index_patterns, version]
            s: ["version:desc"]

    - match:
        $body: |
              /^
                  test_1 \s+ \[te\*\]   \s+ 1\n
                  test   \s+ \[t\*\]    \s+  \n

              $/

---
"Multiple template":
    - skip:
        version: " - 5.99.99"
        reason:  this uses a new API that has been added in 6.0
    - do:
        indices.put_template:
          name: test_1
          body:
            order: 0
            version: 1
            index_patterns: [t*, te*]
            settings:
              number_of_shards: 1
              number_of_replicas: 0

    - do:
        cat.templates:
            h: [name, index_patterns]
            v: true


    - match:
       $body: |
              /^
                 name         \s+
                 index_patterns
                 \n
                 test_1       \s+
                 \[t\*,\ te\*\]
                 \n
              $/
