mirror of
https://github.com/datahub-project/datahub.git
synced 2025-09-02 13:53:06 +00:00
Merge pull request #988 from theseyi/dataset-path
adds unit tests for urn conversion
This commit is contained in:
commit
955e3ccf5e
@ -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
|
||||
|
@ -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 };
|
||||
|
36
wherehows-web/tests/unit/utils/validators/urn-test.js
Normal file
36
wherehows-web/tests/unit/utils/validators/urn-test.js
Normal 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}`)
|
||||
);
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user