---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    ml.put_job:
      job_id: "delete-expired-data-a"
      body: "{\n  \"description\":\"Analysis of response time by airline\",\n  \"\
        analysis_config\" : {\n      \"bucket_span\" : \"1h\",\n      \"detectors\"\
        \ :[{\"function\":\"metric\",\"field_name\":\"responsetime\",\"by_field_name\"\
        :\"airline\"}]\n  },\n  \"data_description\" : {\n      \"time_field\":\"\
        time\",\n      \"time_format\":\"yyyy-MM-dd HH:mm:ssX\"\n  },\n  \"results_retention_days\"\
        \ : 1,\n  \"model_snapshot_retention_days\" : 1\n}\n"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    ml.put_job:
      job_id: "delete-expired-data-b"
      body: "{\n  \"description\":\"Analysis of response time by airline\",\n  \"\
        analysis_config\" : {\n      \"bucket_span\" : \"1h\",\n      \"detectors\"\
        \ :[{\"function\":\"metric\",\"field_name\":\"responsetime\",\"by_field_name\"\
        :\"airline\"}]\n  },\n  \"data_description\" : {\n      \"time_field\":\"\
        time\",\n      \"time_format\":\"yyyy-MM-dd HH:mm:ssX\"\n  },\n  \"results_retention_days\"\
        \ : 1,\n  \"model_snapshot_retention_days\" : 1\n}\n"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
Test delete expired data with no body:
- do:
    ml.delete_expired_data: {}
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    deleted: true
---
Test delete expired data with body parameters:
- do:
    ml.delete_expired_data:
      body: "{ \"timeout\": \"10h\", \"requests_per_second\": 100000.0 }\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    deleted: true
---
Test delete expired data with path parameters:
- do:
    ml.delete_expired_data:
      timeout: "10h"
      requests_per_second: 100000.0
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    deleted: true
---
Test delete expired data with unknown job id:
- do:
    catch: "missing"
    ml.delete_expired_data:
      job_id: "not-a-job"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
