---
"no segments test":
  - do:
      indices.segments:
        allow_no_indices: true

  - match:   { _shards.total: 0}
  - match:   { indices: {}}

  - do:
      catch: missing
      indices.segments:
        allow_no_indices: false

---
"basic segments test":

  - do:
      indices.create:
        index: index1
        body:
          settings:
            number_of_shards: "1"
            number_of_replicas: "0"
  - do:
      index:
        index: index1
        type: type
        body: { foo: bar }
        refresh: true

  - do:
       cluster.health:
         wait_for_status: green

  - do:
      indices.segments:
          index: index1

  - match:   { _shards.total: 1}
  - match:   { indices.index1.shards.0.0.routing.primary: true}
  - match:   { indices.index1.shards.0.0.segments._0.num_docs: 1}

---
"closed segments test":

  - do:
      indices.create:
        index: index1
        body:
          settings:
            number_of_shards: "1"
            number_of_replicas: "0"
  - do:
      index:
        index: index1
        type: type
        body: { foo: bar }
        refresh: true

  - do:
      indices.close:
        index: index1

  - do:
      catch: forbidden
      indices.segments:
          index: index1

  - do:
      indices.segments:
          index: index1
          ignore_unavailable: true

  - match:   { _shards.total: 0}