mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-01 09:35:41 -05:00
Add code coverage tests for notebookUtils (#8524)
This commit is contained in:
@@ -6,13 +6,10 @@
|
||||
import * as path from 'vs/base/common/path';
|
||||
import { nb, ServerInfo } from 'azdata';
|
||||
import { DEFAULT_NOTEBOOK_PROVIDER, DEFAULT_NOTEBOOK_FILETYPE, INotebookService } from 'sql/workbench/services/notebook/browser/notebookService';
|
||||
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
||||
import { ICellModel } from 'sql/workbench/contrib/notebook/browser/models/modelInterfaces';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { startsWith } from 'vs/base/common/strings';
|
||||
import { assign } from 'vs/base/common/objects';
|
||||
|
||||
|
||||
export const clusterEndpointsProperty = 'clusterEndpoints';
|
||||
export const hadoopEndpointNameGateway = 'gateway';
|
||||
/**
|
||||
@@ -56,26 +53,6 @@ export function getStandardKernelsForProvider(providerId: string, notebookServic
|
||||
return <IStandardKernelWithProvider[]>(standardKernels);
|
||||
}
|
||||
|
||||
// In the Attach To dropdown, show the database name (if it exists) using the current connection
|
||||
// Example: myFakeServer (myDatabase)
|
||||
export function formatServerNameWithDatabaseNameForAttachTo(connectionProfile: ConnectionProfile): string {
|
||||
if (connectionProfile && connectionProfile.serverName) {
|
||||
return !connectionProfile.databaseName ? connectionProfile.serverName : connectionProfile.serverName + ' (' + connectionProfile.databaseName + ')';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
// Extract server name from format used in Attach To: serverName (databaseName)
|
||||
export function getServerFromFormattedAttachToName(name: string): string {
|
||||
return name.substring(0, name.lastIndexOf(' (')) ? name.substring(0, name.lastIndexOf(' (')) : name;
|
||||
}
|
||||
|
||||
// Extract database name from format used in Attach To: serverName (databaseName)
|
||||
export function getDatabaseFromFormattedAttachToName(name: string): string {
|
||||
return name.substring(name.lastIndexOf('(') + 1, name.lastIndexOf(')')) ?
|
||||
name.substring(name.lastIndexOf('(') + 1, name.lastIndexOf(')')) : '';
|
||||
}
|
||||
|
||||
export interface IStandardKernelWithProvider {
|
||||
readonly name: string;
|
||||
readonly displayName: string;
|
||||
@@ -102,30 +79,12 @@ export function tryMatchCellMagic(input: string): string {
|
||||
return magicName;
|
||||
}
|
||||
|
||||
export async function asyncForEach(array: any, callback: any): Promise<any> {
|
||||
for (let index = 0; index < array.length; index++) {
|
||||
await callback(array[index], index, array);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Only replace vscode-resource with file when in the same (or a sub) directory
|
||||
* This matches Jupyter Notebook viewer behavior
|
||||
*/
|
||||
export function convertVscodeResourceToFileInSubDirectories(htmlContent: string, cellModel: ICellModel): string {
|
||||
let htmlContentCopy = htmlContent;
|
||||
while (htmlContentCopy.search('(?<=img src=\"vscode-resource:)') > 0) {
|
||||
let pathStartIndex = htmlContentCopy.search('(?<=img src=\"vscode-resource:)');
|
||||
let pathEndIndex = htmlContentCopy.indexOf('\" ', pathStartIndex);
|
||||
let filePath = htmlContentCopy.substring(pathStartIndex, pathEndIndex);
|
||||
// If the asset is in the same folder or a subfolder, replace 'vscode-resource:' with 'file:', so the image is visible
|
||||
if (!(path.relative(path.dirname(cellModel.notebookModel.notebookUri.fsPath), filePath).indexOf('..') > -1)) {
|
||||
// ok to change from vscode-resource: to file:
|
||||
htmlContent = htmlContent.replace('vscode-resource:' + filePath, 'file:' + filePath);
|
||||
export async function asyncForEach(array: any[], callback: Function): Promise<any> {
|
||||
if (array && callback) {
|
||||
for (let index = 0; index < array.length; index++) {
|
||||
await callback(array[index], index, array);
|
||||
}
|
||||
htmlContentCopy = htmlContentCopy.slice(pathEndIndex);
|
||||
}
|
||||
return htmlContent;
|
||||
}
|
||||
|
||||
export function getClusterEndpoints(serverInfo: ServerInfo): IEndpoint[] | undefined {
|
||||
@@ -163,7 +122,7 @@ export function getHostAndPortFromEndpoint(endpoint: string): HostAndIp {
|
||||
};
|
||||
}
|
||||
|
||||
interface RawEndpoint {
|
||||
export interface RawEndpoint {
|
||||
serviceName: string;
|
||||
description?: string;
|
||||
endpoint?: string;
|
||||
|
||||
Reference in New Issue
Block a user