- test: Test Py3 method 
  cleanup:
    -   bn remove returnPy3Method
  steps:
    -   in: export BASE_ARGS="-H X-Binaris-Api-Key:${BINARIS_API_KEY}"
    -   in: export TEST_FUNCTION="https://${BINARIS_INVOKE_ENDPOINT}/v2/run/${BINARIS_ACCOUNT_ID}/returnPy3Method"
    -   in: bn create python3 returnPy3Method
    -   in: |-
          cat > function.py << EOL
          def handler(body, ctx):
            return ctx.request.method
          EOL
    -   in: bn deploy returnPy3Method
    -   in: curl -s -X GET ${BASE_ARGS} "${TEST_FUNCTION}"
        out: '"GET"'
    -   in: curl -s -X POST ${BASE_ARGS} "${TEST_FUNCTION}"
        out: '"POST"'
    -   in: curl -s -X PUT ${BASE_ARGS} "${TEST_FUNCTION}"
        out: '"PUT"'
    -   in: curl -s -X DELETE ${BASE_ARGS} "${TEST_FUNCTION}"
        out: '"DELETE"'
    -   in: curl -s -X OPTIONS ${BASE_ARGS} "${TEST_FUNCTION}"
        out: '"OPTIONS"'
    -   in: curl -s -X PATCH ${BASE_ARGS} "${TEST_FUNCTION}"
        out: '"PATCH"'

- test: Test Py3 data input
  cleanup:
    -   bn remove returnPy3ReqBody
  steps:
    -   in: export BASE_ARGS="-H X-Binaris-Api-Key:${BINARIS_API_KEY}"
    -   in: export TEST_FUNCTION="https://${BINARIS_INVOKE_ENDPOINT}/v2/run/${BINARIS_ACCOUNT_ID}/returnPy3ReqBody"
    -   in: bn create python3 returnPy3ReqBody
    -   in: |-
          cat > function.py << EOL
          def handler(input, ctx):
            return ctx.request.body.decode('utf-8')
          EOL
    -   in: bn deploy returnPy3ReqBody
    -   in: curl -s ${BASE_ARGS} "${TEST_FUNCTION}"
        out: ''
    -   in: curl -s --data '{' ${BASE_ARGS} "${TEST_FUNCTION}"
        out: '"{"'
    -   in: curl -s --data '{}' ${BASE_ARGS} "${TEST_FUNCTION}"
        out: '"{}"'
    -   in: curl -s --data ' ' ${BASE_ARGS} "${TEST_FUNCTION}"
        out: '" "'
    -   in: curl -s --data-urlencode ' ' ${BASE_ARGS} "${TEST_FUNCTION}"
        out: '"%20"'
    -   in: echo | curl -s --data-binary @- ${BASE_ARGS} "${TEST_FUNCTION}"
        out: '"\n"'

- test: Test Py3 headers input
  cleanup:
    -   bn remove returnPy3ReqTestHeader
  steps:
    -   in: export BASE_ARGS="-H X-Binaris-Api-Key:${BINARIS_API_KEY}"
    -   in: export TEST_FUNCTION="https://${BINARIS_INVOKE_ENDPOINT}/v2/run/${BINARIS_ACCOUNT_ID}/returnPy3ReqTestHeader"
    -   in: bn create python3 returnPy3ReqTestHeader
    -   in: |-
          cat > function.py << EOL
          def handler(input, ctx):
            return ctx.request.headers["Test"]
          EOL
    -   in: bn deploy returnPy3ReqTestHeader
    -   in: curl -s ${BASE_ARGS} "${TEST_FUNCTION}"
        out: ''
    -   in: 'curl -s -H "Test;" ${BASE_ARGS} "${TEST_FUNCTION}"'
        out: '""'
    -   in: 'curl -s -H "Test: foo" ${BASE_ARGS} "${TEST_FUNCTION}"'
        out: '"foo"'
    -   in: 'curl -s -H "Test: 123" ${BASE_ARGS} "${TEST_FUNCTION}"'
        out: '"123"'
    -   in: 'curl -s -H "Test: foo" -H "Test: bar" ${BASE_ARGS} "${TEST_FUNCTION}"'
        out: '"foo,bar"'

- test: Test Py3 path input
  cleanup:
    -   bn remove returnPy3ReqPath
  steps:
    -   in: export BASE_ARGS="-H X-Binaris-Api-Key:${BINARIS_API_KEY}"
    -   in: export TEST_FUNCTION="https://${BINARIS_INVOKE_ENDPOINT}/v2/run/${BINARIS_ACCOUNT_ID}/returnPy3ReqPath"
    -   in: bn create python3 returnPy3ReqPath
    -   in: |-
          cat > function.py << EOL
          def handler(input, ctx):
            return ctx.request.path
          EOL
    -   in: bn deploy returnPy3ReqPath
    -   in: curl -s ${BASE_ARGS} "${TEST_FUNCTION}"
        out: 'null'
    -   in: curl -s ${BASE_ARGS} "${TEST_FUNCTION}/////"
        out: '"/"'
    -   in: curl -s ${BASE_ARGS} "${TEST_FUNCTION}/foo"
        out: '"/foo"'
    -   in: curl -s ${BASE_ARGS} "${TEST_FUNCTION}/foo?qs"
        out: '"/foo"'
    -   in: curl -s ${BASE_ARGS} "${TEST_FUNCTION}/foo/"
        out: '"/foo/"'
    -   in: curl -s ${BASE_ARGS} "${TEST_FUNCTION}/foo/?qs=1"
        out: '"/foo/"'
    -   in: curl -s ${BASE_ARGS} "${TEST_FUNCTION}/foo///"
        out: '"/foo/"'
    -   in: curl -s ${BASE_ARGS} "${TEST_FUNCTION}/foo/bar"
        out: '"/foo/bar"'
    -   in: curl -s ${BASE_ARGS} "${TEST_FUNCTION}/foo/bar/"
        out: '"/foo/bar/"'
