Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib/PostgresMetaRoles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export function changeRoleConfig2Object(config: string[]) {
return null
}
return config.reduce((acc: any, cur) => {
const [key, value] = cur.split('=')
acc[key] = value
const [key, ...rest] = cur.split('=')
acc[key] = rest.length > 0 ? rest.join('=') : undefined
return acc
}, {})
}
Expand Down
30 changes: 30 additions & 0 deletions test/role-config.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { expect, test, describe } from 'vitest'
import { changeRoleConfig2Object } from '../src/lib/PostgresMetaRoles.js'

describe('changeRoleConfig2Object', () => {
test('keeps everything after the first equals sign', () => {
expect(changeRoleConfig2Object(['application_name=api=worker'])).toStrictEqual({
application_name: 'api=worker',
})
})

test('parses ordinary values unchanged', () => {
expect(changeRoleConfig2Object(['search_path=public'])).toStrictEqual({
search_path: 'public',
})
})

test('handles both kinds of entry together', () => {
expect(
changeRoleConfig2Object(['application_name=api=worker', 'search_path=public'])
).toStrictEqual({ application_name: 'api=worker', search_path: 'public' })
})

test('an entry without an equals sign has no value', () => {
expect(changeRoleConfig2Object(['lone_key'])).toStrictEqual({ lone_key: undefined })
})

test('returns null when there is no config', () => {
expect(changeRoleConfig2Object(null as unknown as string[])).toBeNull()
})
})