Skip to content

Commit

Permalink
fix: correctly support multiValueHeaders in go functions during dev…
Browse files Browse the repository at this point in the history
…elopment (#4618)

* fix: correctly support `multiValueHeaders` in go functions during development

`multiValueHeaders` was simply not forwarded from the response of the go function

* chore: update contributors field

* chore: update contributors field

* Update tests/unit/lib/functions/runtimes/go/index.test.js

Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com>

* chore: update contributors field

* chore: update contributors field

Co-authored-by: danez <danez@users.noreply.github.com>
Co-authored-by: token-generator-app[bot] <token-generator-app[bot]@users.noreply.github.com>
Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
5 people authored May 25, 2022
1 parent 441d7ff commit f8e692f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/lib/functions/runtimes/go/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
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)

1 comment on commit f8e692f

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

Package size: 287 MB

Please sign in to comment.