setup:
  - skip:
      features: headers
  - do:
      headers:
        Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
      ml.put_job:
        job_id: get-datafeed-1
        body:  >
          {
            "job_id":"get-datafeed-1",
            "analysis_config" : {
                "bucket_span": "1h",
                "detectors" :[{"function":"count"}]
            },
            "data_description" : {
                "format":"xcontent",
                "time_field":"time",
                "time_format":"epoch"
            }
          }

  - do:
      headers:
        Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
      ml.put_job:
        job_id: get-datafeed-2
        body:  >
          {
            "job_id":"get-datafeed-2",
            "analysis_config" : {
                "bucket_span": "1h",
                "detectors" :[{"function":"count"}]
            },
            "data_description" : {
                "time_field":"time"
            }
          }

  - do:
      headers:
        Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
      ml.put_datafeed:
        datafeed_id: datafeed-1
        body: >
          {
            "job_id":"get-datafeed-1",
            "indexes":["index-1"]
          }

  - do:
      headers:
        Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
      ml.put_datafeed:
        datafeed_id: datafeed-2
        body: >
          {
            "job_id":"get-datafeed-2",
            "indexes":["index-2"]
          }

---
"Test get datafeed given missing datafeed_id":

  - do:
      catch: missing
      ml.get_datafeeds:
        datafeed_id: missing-datafeed

---
"Test get single datafeed":

  - do:
      ml.get_datafeeds:
        datafeed_id: datafeed-1
  - match: { datafeeds.0.datafeed_id: "datafeed-1"}
  - match: { datafeeds.0.job_id: "get-datafeed-1"}

  - do:
      ml.get_datafeeds:
        datafeed_id: datafeed-2
  - match: { datafeeds.0.datafeed_id: "datafeed-2"}
  - match: { datafeeds.0.job_id: "get-datafeed-2"}

---
"Test explicit get all datafeeds":

  - do:
      ml.get_datafeeds:
        datafeed_id: _all
  - match: { count: 2 }
  - match: { datafeeds.0.datafeed_id: "datafeed-1"}
  - match: { datafeeds.0.job_id: "get-datafeed-1"}
  - match: { datafeeds.1.datafeed_id: "datafeed-2"}
  - match: { datafeeds.1.job_id: "get-datafeed-2"}

---
"Test implicit get all datafeeds":

  - do:
      ml.get_datafeeds: {}
  - match: { count: 2 }
  - match: { datafeeds.0.datafeed_id: "datafeed-1"}
  - match: { datafeeds.0.job_id: "get-datafeed-1"}
  - match: { datafeeds.1.datafeed_id: "datafeed-2"}
  - match: { datafeeds.1.job_id: "get-datafeed-2"}
