Merge pull request #988 from theseyi/dataset-path

adds unit tests for urn conversion
This commit is contained in:
Seyi Adebajo 2018-02-22 11:17:19 -08:00 committed by GitHub
commit 955e3ccf5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 3 deletions

View File

@ -78,7 +78,7 @@ const convertWhUrnToLiUrn = (whUrn: string): string => {
* @return {string}
*/
const convertWhDatasetPathToLiPath = (platform: DatasetPlatform, path: string): string =>
platform === DatasetPlatform.HDFS ? `/${path}` : path.replace(/\//g, '.');
String(platform).toLowerCase() === DatasetPlatform.HDFS ? `/${path}` : path.replace(/\//g, '.');
/**
* Cached RegExp object for a global search of /
@ -123,6 +123,7 @@ export {
specialFlowUrnRegex,
getPlatformFromUrn,
convertWhUrnToLiUrn,
convertWhDatasetPathToLiPath,
encodeForwardSlash,
encodeUrn,
decodeUrn

View File

@ -1,3 +1,16 @@
const urn = 'urn:li:dataset:(urn:li:dataPlatform:hdfs,%2Fjobs%2Faffinity%2FeAffinity%2Fmaster%2Fold-job-seeker,PROD)';
const urn = 'urn:li:dataset:(urn:li:dataPlatform:hdfs,%2Fseg1s%2Fseg2%2Fseg3%2Fseg4%2Fdataset-node,PROD)';
export { urn };
const whUrnToLiUrnMap = [
['espresso:///ETLInfra/AllTables', 'urn:li:dataset:(urn:li:dataPlatform:espresso,ETLInfra.AllTables,PROD)'],
[
'hdfs:///seg1/seg2/seg3/data/kebab-db-name',
'urn:li:dataset:(urn:li:dataPlatform:hdfs,/seg1/seg2/seg3/data/kebab-db-name,PROD)'
],
[
'hdfs:///seg1/seg2/data/UpperCaseDbName',
'urn:li:dataset:(urn:li:dataPlatform:hdfs,/seg1/seg2/data/UpperCaseDbName,PROD)'
],
['oracle:///ABOOK/ABOOK_DATA', 'urn:li:dataset:(urn:li:dataPlatform:oracle,ABOOK.ABOOK_DATA,PROD)']
];
export { urn, whUrnToLiUrnMap };

View File

@ -0,0 +1,36 @@
import { module, test } from 'qunit';
import {
convertWhDatasetPathToLiPath,
datasetUrnRegexWH,
convertWhUrnToLiUrn
} from 'wherehows-web/utils/validators/urn';
import { whUrnToLiUrnMap } from 'wherehows-web/mirage/fixtures/urn';
module('Unit | Utility | validators/urn');
test('converters exist', function(assert) {
assert.ok(typeof convertWhDatasetPathToLiPath === 'function', 'convertWhDatasetPathToLiPath is a function');
assert.ok(typeof convertWhUrnToLiUrn === 'function', 'convertWhUrnToLiUrn is a function');
});
test('convertWhDatasetPathToLiPath correctly converts an hdfs path', function(assert) {
const [, platform, path] = datasetUrnRegexWH.exec('hdfs:///seg1/seg2/seg3/data/kebab-db-name');
const result = convertWhDatasetPathToLiPath(platform, path);
assert.equal('/seg1/seg2/seg3/data/kebab-db-name', result, 'hdfs path is correctly converted');
});
test('convertWhDatasetPathToLiPath correctly converts a non-hdfs path', function(assert) {
const [, platform, path] = datasetUrnRegexWH.exec('oracle:///ABOOK/ABOOK_DATA');
const result = convertWhDatasetPathToLiPath(platform, path);
assert.equal('ABOOK.ABOOK_DATA', result, 'non hdfs path is correctly converted');
});
test('convertWhUrnToLiUrn correctly converts urns', function(assert) {
assert.expect(whUrnToLiUrnMap.length);
whUrnToLiUrnMap.forEach(([actual, expected]) =>
assert.equal(convertWhUrnToLiUrn(actual), expected, `${actual} is correctly converted to ${expected}`)
);
});