Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly support multiValueHeaders in go functions during development #4618

Merged
merged 9 commits into from
May 25, 2022
3 changes: 2 additions & 1 deletion src/lib/functions/runtimes/go/index.js
Original file line number Diff line number Diff line change
@@ -55,11 +55,12 @@ const invokeFunction = async ({ context, event, func, timeout }) => {
})

try {
const { body, headers, statusCode } = JSON.parse(stdout)
const { body, headers, multiValueHeaders, statusCode } = JSON.parse(stdout)

return {
body,
headers,
multiValueHeaders,
statusCode,
}
} catch {
29 changes: 29 additions & 0 deletions tests/unit/lib/functions/runtimes/go/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const test = require('ava')
const sinon = require('sinon')

const { rewiremock } = require('../../../../../integration/utils/rewiremock')

const runFunctionsProxySpy = sinon.stub()
// eslint-disable-next-line n/global-require
const { invokeFunction } = rewiremock.proxy(() => require('../../../../../../src/lib/functions/runtimes/go/index'), {
'../../../../../../src/lib/functions/local-proxy': {
runFunctionsProxy: runFunctionsProxySpy,
},
})

const invokeFunctionMacro = test.macro({
async exec(t, prop, expected) {
runFunctionsProxySpy.resolves({ stdout: JSON.stringify({ [prop]: expected }) })

const match = await invokeFunction({ func: { mainFile: '', buildData: {} } })
t.deepEqual(match[prop], expected)
},
title(providedTitle, prop) {
return `should return ${prop}`
},
})

test(invokeFunctionMacro, 'body', 'thebody')
test(invokeFunctionMacro, 'headers', { 'X-Single': 'A' })
test(invokeFunctionMacro, 'multiValueHeaders', { 'X-Multi': ['B', 'C'] })
test(invokeFunctionMacro, 'statusCode', 200)