---
"Explain backing index lifecycle":
  - requires:
      cluster_features: [ "gte_v8.11.0" ]
      reason: "Data stream lifecycle was released as tech preview in 8.11"
      test_runner_features: allowed_warnings
  - do:
      allowed_warnings:
        - "index template [template-with-lifecycle] has index patterns [managed-data-stream] matching patterns from existing older templates [global] with patterns (global => [*]); this template [template-with-lifecycle] will take precedence during new index creation"
      indices.put_index_template:
        name: template-with-lifecycle
        body:
          index_patterns: [ managed-data-stream ]
          template:
            settings:
              index.number_of_replicas: 0
            lifecycle:
              data_retention: "30d"
          data_stream: { }
  - do:
      indices.create_data_stream:
        name: managed-data-stream
  - is_true: acknowledged

  - do:
      indices.get_data_stream:
        name: "managed-data-stream"
  - match: { data_streams.0.name: managed-data-stream }
  - match: { data_streams.0.generation: 1 }
  - length: { data_streams.0.indices: 1 }
  - match: { data_streams.0.indices.0.index_name: '/\.ds-managed-data-stream-(\d{4}\.\d{2}\.\d{2}-)?000001/' }
  - set:
      data_streams.0.indices.0.index_name: backing_index

  - do:
      indices.explain_data_lifecycle:
        index: $backing_index
  - match: { indices.$backing_index.managed_by_lifecycle: true }
  - match: { indices.$backing_index.lifecycle.data_retention: '30d' }
  - match: { indices.$backing_index.lifecycle.enabled: true }
  - is_false: indices.$backing_index.lifecycle.rollover


  - do:
      indices.explain_data_lifecycle:
        index: $backing_index
        include_defaults: true
  - match: { indices.$backing_index.managed_by_lifecycle: true }
  - match: { indices.$backing_index.lifecycle.data_retention: '30d' }
  - is_true: indices.$backing_index.lifecycle.rollover




