-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue 366 - Replace better-eval with vm and add option to configure p…
…arser (#536) * Replace better-eval with vm * issue366 - Add test case for variant column type * issue 366 - Remove 'vm' from package.json as it's already part of node * issue 366 - Rename test * issue 366 - Make array const * issue 366 - Wrapped lines in else clause * issue 366 - Put variant test in its own describe and placed create/drop table in the before/after functions * issue 366 - Put variant test in its own describe and placed create/drop table in the before/after functions * issue 366 - Put variant test in its own describe and placed create/drop table in the before/after functions * issue 366 - Put variant test in its own describe and placed create/drop table in the before/after functions * issue 366 - Put variant test in its own describe and placed create/drop table in the before/after functions * issue 366 - Put variant test in its own describe and placed create/drop table in the before/after functions * issue 366 - Temp revert wrapping test in describe * issue 366 - Temp revert else clause * issue 366 - Temp revert const array * issue 366 - Temp revert name change * issue 366 - Temp revert remove vm * issue 366 - Remove vm * issue 366 - Rename test * issue 366 - Make array const * issue 366 - Wrap in else clause * issue 366 - Wrap variant test in its own describe * Require async used by the variant test * Parse JSON one row at a time * issue 366 - Add option to configure json/xml parser * issue 366 - Fix typo from logLevel * issue 366 - Add test case for xml data type * issue 366 - Add tests for snowflake.configure options * issue 366 - Fix ocsp variable * Return to default configuration after test * Return to default configuration after test * issue 366 - nit newline * Run lint on new test file * Move required up * issue 366 - Keep old behaviour of xml parser * issue 366 - Log and throw error in the default xml parser * issue 366 - Add expected signature for setting a custom parser * issue 366 - Make new variables const * Wrap variant test cases in their own describe * issue 366 - Wrap the configure test cases in their own describe * issue 366 - Refactor calling the test cases * issue 366 - Fixed the custom xml parser in the test case * issue 366 - Create test with custom parser * issue 366 - Move require up * issue 366 - Add logging and throw for both JSON/XML parser errors
1 parent
01b2eb4
commit 0926a0f
Showing
10 changed files
with
555 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
/* | ||
* Copyright (c) 2023 Snowflake Computing Inc. All rights reserved. | ||
*/ | ||
|
||
const assert = require('assert'); | ||
const snowflake = require('./../../lib/snowflake'); | ||
const ErrorCodes = require('./../../lib/errors').codes; | ||
const Logger = require('./../../lib/logger'); | ||
const GlobalConfig = require('./../../lib/global_config'); | ||
|
||
const LOG_LEVEL_TAGS = require('./../../lib/logger/core').LOG_LEVEL_TAGS; | ||
|
||
describe('Snowflake Configure Tests', function () { | ||
let originalConfig; | ||
|
||
before(function () { | ||
originalConfig = { | ||
logLevel: Logger.getInstance().getLevelTag(), | ||
insecureConnect: GlobalConfig.isInsecureConnect(), | ||
ocspFailOpen: GlobalConfig.getOcspFailOpen(), | ||
jsonColumnVariantParser: GlobalConfig.jsonColumnVariantParser, | ||
xmlColumnVariantParser: GlobalConfig.xmlColumnVariantParser | ||
}; | ||
}); | ||
|
||
after(function () { | ||
snowflake.configure(originalConfig); | ||
}); | ||
|
||
describe('Test invalid arguments', function () { | ||
const negativeTestCases = | ||
[ | ||
{ | ||
name: 'invalid logLevel', | ||
options: { logLevel: 'unsupported' }, | ||
errorCode: ErrorCodes.ERR_GLOBAL_CONFIGURE_INVALID_LOG_LEVEL | ||
}, | ||
{ | ||
name: 'invalid insecureConnect', | ||
options: { insecureConnect: 'unsupported' }, | ||
errorCode: ErrorCodes.ERR_GLOBAL_CONFIGURE_INVALID_INSECURE_CONNECT | ||
}, | ||
{ | ||
name: 'invalid ocspMode', | ||
options: { ocspFailOpen: 'unsupported' }, | ||
errorCode: ErrorCodes.ERR_GLOBAL_CONFIGURE_INVALID_OCSP_MODE | ||
}, | ||
{ | ||
name: 'invalid json parser', | ||
options: { jsonColumnVariantParser: 'unsupported' }, | ||
errorCode: ErrorCodes.ERR_GLOBAL_CONFIGURE_INVALID_JSON_PARSER | ||
}, | ||
{ | ||
name: 'invalid xml parser', | ||
options: { xmlColumnVariantParser: 'unsupported' }, | ||
errorCode: ErrorCodes.ERR_GLOBAL_CONFIGURE_INVALID_XML_PARSER | ||
}, | ||
]; | ||
|
||
negativeTestCases.forEach(testCase => { | ||
it(testCase.name, function () { | ||
let error; | ||
|
||
try { | ||
snowflake.configure(testCase.options); | ||
} catch (err) { | ||
error = err; | ||
} finally { | ||
assert.ok(error); | ||
assert.strictEqual(error.code, testCase.errorCode); | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Test valid arguments', function () { | ||
const testCases = | ||
[ | ||
{ | ||
name: 'logLevel error', | ||
options: | ||
{ | ||
logLevel: LOG_LEVEL_TAGS.ERROR | ||
} | ||
}, | ||
{ | ||
name: 'logLevel warn', | ||
options: | ||
{ | ||
logLevel: LOG_LEVEL_TAGS.WARN | ||
} | ||
}, | ||
{ | ||
name: 'logLevel debug', | ||
options: | ||
{ | ||
logLevel: LOG_LEVEL_TAGS.DEBUG | ||
} | ||
}, | ||
{ | ||
name: 'logLevel info', | ||
options: | ||
{ | ||
logLevel: LOG_LEVEL_TAGS.INFO | ||
} | ||
}, | ||
{ | ||
name: 'logLevel trace', | ||
options: | ||
{ | ||
logLevel: LOG_LEVEL_TAGS.TRACE | ||
} | ||
}, | ||
{ | ||
name: 'insecureConnect false', | ||
options: | ||
{ | ||
insecureConnect: false | ||
} | ||
}, | ||
{ | ||
name: 'insecureConnect true', | ||
options: | ||
{ | ||
insecureConnect: true | ||
} | ||
}, | ||
{ | ||
name: 'ocspFailOpen false', | ||
options: | ||
{ | ||
ocspFailOpen: false | ||
} | ||
}, | ||
{ | ||
name: 'ocspFailOpen true', | ||
options: | ||
{ | ||
ocspFailOpen: true | ||
} | ||
}, | ||
{ | ||
name: 'json parser', | ||
options: | ||
{ | ||
jsonColumnVariantParser: rawColumnValue => require('vm').runInNewContext('(' + rawColumnValue + ')') | ||
} | ||
}, | ||
{ | ||
name: 'xml parser', | ||
options: | ||
{ | ||
xmlColumnVariantParser: rawColumnValue => new (require("fast-xml-parser")).XMLParser().parse(rawColumnValue) | ||
} | ||
}, | ||
]; | ||
|
||
testCases.forEach(testCase => { | ||
it(testCase.name, function () { | ||
snowflake.configure(testCase.options); | ||
Object.keys(testCase.options).forEach(function (key) { | ||
const ref = testCase.options[key]; | ||
let val; | ||
if (key == 'logLevel') { | ||
val = Logger.getInstance().getLevelTag(); | ||
} else if (key == 'insecureConnect') { | ||
val = GlobalConfig.isInsecureConnect(); | ||
} else if (key == 'ocspFailOpen') { | ||
val = GlobalConfig.getOcspFailOpen(); | ||
} else { | ||
val = GlobalConfig[key]; | ||
} | ||
assert.strictEqual(val, ref); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |