---
"Test script processor with inline script and params":
  - do:
      ingest.put_pipeline:
        id: "my_pipeline"
        body:  >
          {
            "description": "_description",
            "processors": [
              {
                "script" : {
                  "source": "ctx.bytes_total = (ctx.bytes_in + ctx.bytes_out) * params.factor",
                  "params": {
                     "factor": 10
                  }
                }
              }
            ]
          }
  - match: { acknowledged: true }

  - do:
      index:
        index: test
        type: test
        id: 1
        pipeline: "my_pipeline"
        body: { bytes_in: 1234, bytes_out: 4321 }

  - do:
      get:
        index: test
        type: test
        id: 1
  - match: { _source.bytes_in: 1234 }
  - match: { _source.bytes_out: 4321 }
  - match: { _source.bytes_total: 55550 }

---
"Test script processor with stored script":
  - skip:
      features: warnings

  - do:
      put_script:
        id: "sum_bytes"
        body: >
          {
            "script": {
              "lang": "painless",
              "source" : "ctx.bytes_total = ctx.bytes_in + ctx.bytes_out"
            }
          }
  - match: { acknowledged: true }

  - do:
      ingest.put_pipeline:
        id: "my_pipeline"
        body:  >
          {
            "description": "_description",
            "processors": [
              {
                "script" : {
                  "id" : "sum_bytes"
                }
              }
            ]
          }
  - match: { acknowledged: true }

  - do:
      index:
        index: test
        type: test
        id: 1
        pipeline: "my_pipeline"
        body: { bytes_in: 1234, bytes_out: 4321 }

  - do:
      get:
        index: test
        type: test
        id: 1
  - match: { _source.bytes_in: 1234 }
  - match: { _source.bytes_out: 4321 }
  - match: { _source.bytes_total: 5555 }

---
"Test script processor with syntax error in inline script":
  - do:
      catch: request
      ingest.put_pipeline:
        id: "my_pipeline"
        body:  >
          {
            "description": "_description",
            "processors": [
              {
                "script" : {
                  "source": "invalid painless, hear me roar!"
                }
              }
            ]
          }
  - match: { error.header.processor_type: "script" }
  - match: { error.type: "script_exception" }
  - match: { error.reason: "compile error" }

