setup:
  - do:
      cluster.put_settings:
        body: >
          {
            "persistent": {
              "logger.org.elasticsearch.xpack.transform.action": "DEBUG"
            }
          }


---
teardown:
  - do:
      transform.stop_transform:
        wait_for_checkpoint: false
        transform_id: "transform-unattended"
        timeout: "10m"
        wait_for_completion: true
  - do:
      transform.delete_transform:
        transform_id: "transform-unattended"
  - do:
      cluster.put_settings:
        body: >
          {
            "persistent": {
              "logger.org.elasticsearch.xpack.transform.action": "INFO"
            }
          }

---
"Test unattended put and start":
  - do:
      transform.put_transform:
        transform_id: "transform-unattended"
        defer_validation: true
        body: >
          {
            "source": { "index": "airline-data" },
            "dest": { "index": "dest-airline-data-by-airline-start-stop" },
            "pivot": {
              "group_by": { "airline": {"terms": {"field": "airline"}}},
              "aggs": {"avg_response": {"avg": {"field": "responsetime"}}}
            },
            "settings": {
              "unattended": true
            }
          }
  - match: { acknowledged: true }
  - do:
      transform.get_transform_stats:
        transform_id: "transform-unattended"
  - match: { count: 1 }
  - match: { transforms.0.id: "transform-unattended" }
  - match: { transforms.0.state: "/started|indexing|stopping|stopped/" }
  - match: { transforms.0.health.status: "green" }

  - do:
      transform.start_transform:
        transform_id: "transform-unattended"
  - match: { acknowledged: true }
  - do:
      transform.get_transform_stats:
        transform_id: "transform-unattended"
  - match: { count: 1 }
  - match: { transforms.0.id: "transform-unattended" }
  - match: { transforms.0.state: "/started|indexing|stopping|stopped/" }
  # Health status should be yellow due to missing source index, but it can be green as well (timing issue).
  - match: { transforms.0.health.status: "/green|yellow/" }

---
"Test unattended put and start wildcard":
  - do:
      transform.put_transform:
        transform_id: "transform-unattended"
        body: >
          {
            "source": { "index": "airline-data*" },
            "dest": { "index": "dest-airline-data-by-airline-start-stop" },
            "pivot": {
              "group_by": { "airline": {"terms": {"field": "airline"}}},
              "aggs": {"avg_response": {"avg": {"field": "responsetime"}}}
            },
            "settings": {
              "unattended": true
            }
          }
  - match: { acknowledged: true }
  - do:
      transform.start_transform:
        transform_id: "transform-unattended"
  - match: { acknowledged: true }
