mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Move SQL 2019 extension's notebook code into Azure Data Studio (#4090)
This commit is contained in:
66
extensions/notebook/src/test/common/port.test.ts
Normal file
66
extensions/notebook/src/test/common/port.test.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
// This code is originally from https://github.com/Microsoft/vscode/blob/master/src/vs/base/test/node/port.test.ts
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import * as net from 'net';
|
||||
import 'mocha';
|
||||
|
||||
import * as ports from '../../common/ports';
|
||||
|
||||
describe('Ports', () => {
|
||||
it('Should Find a free port (no timeout)', function (done): void {
|
||||
this.timeout(1000 * 10); // higher timeout for this test
|
||||
|
||||
// get an initial freeport >= 7000
|
||||
ports.findFreePort(7000, 100, 300000).then(initialPort => {
|
||||
assert.ok(initialPort >= 7000);
|
||||
|
||||
// create a server to block this port
|
||||
const server = net.createServer();
|
||||
server.listen(initialPort, undefined, undefined, () => {
|
||||
|
||||
// once listening, find another free port and assert that the port is different from the opened one
|
||||
ports.findFreePort(7000, 50, 300000).then(freePort => {
|
||||
assert.ok(freePort >= 7000 && freePort !== initialPort);
|
||||
server.close();
|
||||
|
||||
done();
|
||||
}, err => done(err));
|
||||
});
|
||||
}, err => done(err));
|
||||
});
|
||||
|
||||
it('Should Find a free port in strict mode', function (done): void {
|
||||
this.timeout(1000 * 10); // higher timeout for this test
|
||||
|
||||
// get an initial freeport >= 7000
|
||||
let options = new ports.StrictPortFindOptions(7000, 7100, 7200);
|
||||
options.timeout = 300000;
|
||||
ports.strictFindFreePort(options).then(initialPort => {
|
||||
assert.ok(initialPort >= 7000);
|
||||
|
||||
// create a server to block this port
|
||||
const server = net.createServer();
|
||||
server.listen(initialPort, undefined, undefined, () => {
|
||||
|
||||
// once listening, find another free port and assert that the port is different from the opened one
|
||||
options.startPort = initialPort;
|
||||
options.maxRetriesPerStartPort = 1;
|
||||
options.totalRetryLoops = 50;
|
||||
ports.strictFindFreePort(options).then(freePort => {
|
||||
assert.ok(freePort >= 7100 && freePort !== initialPort);
|
||||
server.close();
|
||||
|
||||
done();
|
||||
}, err => done(err));
|
||||
});
|
||||
}, err => done(err));
|
||||
});
|
||||
});
|
||||
|
||||
24
extensions/notebook/src/test/common/querybookUtils.test.ts
Normal file
24
extensions/notebook/src/test/common/querybookUtils.test.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as should from 'should';
|
||||
import 'mocha';
|
||||
|
||||
import * as notebookUtils from '../../common/notebookUtils';
|
||||
|
||||
describe('Random Token', () => {
|
||||
it('Should have default length and be hex only', async function (): Promise<void> {
|
||||
|
||||
let token = await notebookUtils.getRandomToken();
|
||||
should(token).have.length(48);
|
||||
let validChars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
|
||||
for (let i = 0; i < token.length; i++) {
|
||||
let char = token.charAt(i);
|
||||
should(validChars.indexOf(char)).be.greaterThan(-1);
|
||||
}
|
||||
});
|
||||
});
|
||||
46
extensions/notebook/src/test/common/stubs.ts
Normal file
46
extensions/notebook/src/test/common/stubs.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
export class MockExtensionContext implements vscode.ExtensionContext {
|
||||
logger: undefined;
|
||||
logDirectory: './';
|
||||
subscriptions: { dispose(): any; }[];
|
||||
workspaceState: vscode.Memento;
|
||||
globalState: vscode.Memento;
|
||||
extensionPath: string;
|
||||
asAbsolutePath(relativePath: string): string {
|
||||
return relativePath;
|
||||
}
|
||||
storagePath: string;
|
||||
|
||||
constructor() {
|
||||
this.subscriptions = [];
|
||||
}
|
||||
}
|
||||
|
||||
export class MockOutputChannel implements vscode.OutputChannel {
|
||||
name: string;
|
||||
|
||||
append(value: string): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
appendLine(value: string): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
clear(): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
show(preserveFocus?: boolean): void;
|
||||
show(column?: vscode.ViewColumn, preserveFocus?: boolean): void;
|
||||
show(column?: any, preserveFocus?: any): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
hide(): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
dispose(): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
}
|
||||
22
extensions/notebook/src/test/common/testUtils.ts
Normal file
22
extensions/notebook/src/test/common/testUtils.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
|
||||
export async function assertThrowsAsync(fn, regExp): Promise<void> {
|
||||
let f = () => {
|
||||
// Empty
|
||||
};
|
||||
try {
|
||||
await fn();
|
||||
} catch (e) {
|
||||
f = () => { throw e; };
|
||||
} finally {
|
||||
assert.throws(f, regExp);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user