mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Remove old CTP code, add test (#9877)
This commit is contained in:
@@ -7,7 +7,7 @@ import * as assert from 'assert';
|
|||||||
import * as TypeMoq from 'typemoq';
|
import * as TypeMoq from 'typemoq';
|
||||||
|
|
||||||
import { nb, ServerInfo } from 'azdata';
|
import { nb, ServerInfo } from 'azdata';
|
||||||
import { getHostAndPortFromEndpoint, isStream, getProvidersForFileName, asyncForEach, clusterEndpointsProperty, getClusterEndpoints, RawEndpoint, IEndpoint, getStandardKernelsForProvider, IStandardKernelWithProvider } from 'sql/workbench/services/notebook/browser/models/notebookUtils';
|
import { getHostAndPortFromEndpoint, isStream, getProvidersForFileName, asyncForEach, clusterEndpointsProperty, getClusterEndpoints, RawEndpoint, IEndpoint, getStandardKernelsForProvider, IStandardKernelWithProvider, rewriteUrlUsingRegex } from 'sql/workbench/services/notebook/browser/models/notebookUtils';
|
||||||
import { INotebookService, DEFAULT_NOTEBOOK_FILETYPE, DEFAULT_NOTEBOOK_PROVIDER } from 'sql/workbench/services/notebook/browser/notebookService';
|
import { INotebookService, DEFAULT_NOTEBOOK_FILETYPE, DEFAULT_NOTEBOOK_PROVIDER } from 'sql/workbench/services/notebook/browser/notebookService';
|
||||||
import { NotebookServiceStub } from 'sql/workbench/contrib/notebook/test/stubs';
|
import { NotebookServiceStub } from 'sql/workbench/contrib/notebook/test/stubs';
|
||||||
import { tryMatchCellMagic } from 'sql/workbench/services/notebook/browser/utils';
|
import { tryMatchCellMagic } from 'sql/workbench/services/notebook/browser/utils';
|
||||||
@@ -204,4 +204,16 @@ suite('notebookUtils', function (): void {
|
|||||||
assert.strictEqual(result.host, '');
|
assert.strictEqual(result.host, '');
|
||||||
assert.strictEqual(result.port, undefined);
|
assert.strictEqual(result.port, undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('rewriteUrlUsingRegex Test', async function (): Promise<void> {
|
||||||
|
// Give a URL that should be rewritten
|
||||||
|
let html = '<a target="_blank" href="https://sparkhead-0.sparkhead-svc:8090/proxy/application_1/“>Link</a>';
|
||||||
|
let result = rewriteUrlUsingRegex(/(https?:\/\/sparkhead.*\/proxy)(.*)/g, html, '1.1.1.1', ':999', '/gateway/default/yarn/proxy');
|
||||||
|
assert.strictEqual(result, '<a target="_blank" href="https://1.1.1.1:999/gateway/default/yarn/proxy/application_1/“>Link</a>', 'Target URL does not match after substitution');
|
||||||
|
|
||||||
|
// Give a URL that should not be rewritten
|
||||||
|
html = '<a target="_blank" href="https://storage-0-0.storage-0-svc.mssql-cluster.svc.cluster.local:8044/node/containerlogs/container_7/root“>Link</a>';
|
||||||
|
result = rewriteUrlUsingRegex(/(https?:\/\/sparkhead.*\/proxy)(.*)/g, html, '1.1.1.1', ':999', '/gateway/default/yarn/proxy');
|
||||||
|
assert.strictEqual(result, '<a target="_blank" href="https://storage-0-0.storage-0-svc.mssql-cluster.svc.cluster.local:8044/node/containerlogs/container_7/root“>Link</a>', 'Target URL should not have been edited');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -536,12 +536,10 @@ export class CellModel implements ICellModel {
|
|||||||
let host = hostAndIp.host ? hostAndIp.host : model.context.serverName;
|
let host = hostAndIp.host ? hostAndIp.host : model.context.serverName;
|
||||||
let port = hostAndIp.port ? ':' + hostAndIp.port : defaultPort;
|
let port = hostAndIp.port ? ':' + hostAndIp.port : defaultPort;
|
||||||
let html = result.data['text/html'];
|
let html = result.data['text/html'];
|
||||||
// CTP 3.1 and earlier Spark link
|
// BDC Spark UI Link
|
||||||
html = this.rewriteUrlUsingRegex(/(https?:\/\/master.*\/proxy)(.*)/g, html, host, port, yarnUi);
|
html = notebookUtils.rewriteUrlUsingRegex(/(https?:\/\/sparkhead.*\/proxy)(.*)/g, html, host, port, yarnUi);
|
||||||
// CTP 3.2 and later spark link
|
|
||||||
html = this.rewriteUrlUsingRegex(/(https?:\/\/sparkhead.*\/proxy)(.*)/g, html, host, port, yarnUi);
|
|
||||||
// Driver link
|
// Driver link
|
||||||
html = this.rewriteUrlUsingRegex(/(https?:\/\/storage.*\/containerlogs)(.*)/g, html, host, port, driverLog);
|
html = notebookUtils.rewriteUrlUsingRegex(/(https?:\/\/storage.*\/containerlogs)(.*)/g, html, host, port, driverLog);
|
||||||
(<nb.IDisplayResult>output).data['text/html'] = html;
|
(<nb.IDisplayResult>output).data['text/html'] = html;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -552,19 +550,6 @@ export class CellModel implements ICellModel {
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
private rewriteUrlUsingRegex(regex: RegExp, html: string, host: string, port: string, target: string): string {
|
|
||||||
return html.replace(regex, function (a, b, c) {
|
|
||||||
let ret = '';
|
|
||||||
if (b !== '') {
|
|
||||||
ret = 'https://' + host + port + target;
|
|
||||||
}
|
|
||||||
if (c !== '') {
|
|
||||||
ret = ret + c;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public setStdInHandler(handler: nb.MessageHandler<nb.IStdinMessage>): void {
|
public setStdInHandler(handler: nb.MessageHandler<nb.IStdinMessage>): void {
|
||||||
this._stdInHandler = handler;
|
this._stdInHandler = handler;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,6 +110,19 @@ export function getHostAndPortFromEndpoint(endpoint: string): HostAndIp {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function rewriteUrlUsingRegex(regex: RegExp, html: string, host: string, port: string, target: string): string {
|
||||||
|
return html.replace(regex, function (a, b, c) {
|
||||||
|
let ret = '';
|
||||||
|
if (b !== '') {
|
||||||
|
ret = 'https://' + host + port + target;
|
||||||
|
}
|
||||||
|
if (c !== '') {
|
||||||
|
ret = ret + c;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export interface RawEndpoint {
|
export interface RawEndpoint {
|
||||||
serviceName: string;
|
serviceName: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user