Skip to content
Draft
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
19 changes: 15 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,27 @@ let hasNativeReservationSupportCache = null
* @returns {boolean} True if native reservation supported
*/
function isNativeReservationSupported() {
if (process.env.DATAFORM_MOCK_NATIVE_RESERVATION === 'true') return true
if (process.env.DATAFORM_MOCK_NATIVE_RESERVATION === 'false') return false

if (hasNativeReservationSupportCache !== null) {
return hasNativeReservationSupportCache
}

if (process.env.DATAFORM_MOCK_NATIVE_RESERVATION === 'true') {
hasNativeReservationSupportCache = true
return true
}
if (process.env.DATAFORM_MOCK_NATIVE_RESERVATION === 'false') {
hasNativeReservationSupportCache = false
return false
}

hasNativeReservationSupportCache = false
return false
}

function resetNativeReservationSupportCache() {
hasNativeReservationSupportCache = null
}

/**
* Helper to check if a query/array of queries has an outer DECLARE statement
* @param {string|string[]|Function} sql - The SQL statement(s) to check
Expand Down Expand Up @@ -376,5 +386,6 @@ module.exports = {
prependStatement,
isArrayOrString,
findReservation,
isNativeReservationSupported
isNativeReservationSupported,
resetNativeReservationSupportCache
}
13 changes: 12 additions & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const {
createReservationSetter,
getActionName,
autoAssignActions,
isNativeReservationSupported
isNativeReservationSupported,
resetNativeReservationSupportCache
} = require('../index')

/**
Expand Down Expand Up @@ -63,6 +64,10 @@ describe('Dataform package', () => {
process.env.DATAFORM_MOCK_NATIVE_RESERVATION = 'false'
})

beforeEach(() => {
resetNativeReservationSupportCache()
})

afterAll(() => {
process.env.DATAFORM_MOCK_NATIVE_RESERVATION = originalEnv
})
Expand Down Expand Up @@ -223,6 +228,7 @@ describe('Dataform package', () => {
beforeEach(() => {
originalEnv = process.env.DATAFORM_MOCK_NATIVE_RESERVATION
originalDataform = global.dataform
resetNativeReservationSupportCache()
})

afterEach(() => {
Expand Down Expand Up @@ -269,6 +275,10 @@ describe('Dataform package', () => {
process.env.DATAFORM_MOCK_NATIVE_RESERVATION = 'false'
})

beforeEach(() => {
resetNativeReservationSupportCache()
})

afterAll(() => {
process.env.DATAFORM_MOCK_NATIVE_RESERVATION = originalEnv
})
Expand Down Expand Up @@ -427,6 +437,7 @@ describe('Dataform package', () => {
describe(`with native support = ${isNative}`, () => {
beforeEach(() => {
process.env.DATAFORM_MOCK_NATIVE_RESERVATION = String(isNative)
resetNativeReservationSupportCache()
})

test('should apply reservations to existing publish actions', () => {
Expand Down
Loading