Cleanup generated test files and folders for Sql DB projects (#20862)

* Cleanup generated test files and folders

* Add await to fix tests
This commit is contained in:
Sakshi Sharma
2022-10-21 13:00:03 -07:00
committed by GitHub
parent 8acda681b4
commit 2a2ac74032
14 changed files with 97 additions and 10 deletions

View File

@@ -13,6 +13,7 @@ import should = require('should');
import { AssertionError } from 'assert';
import { Project } from '../models/project';
import { Uri } from 'vscode';
import { exists } from '../common/utils';
export async function shouldThrowSpecificError(block: Function, expectedMessage: string, details?: string) {
let succeeded = false;
@@ -47,12 +48,17 @@ export async function createTestDataSources(contents: string, folderPath?: strin
}
export async function generateTestFolderPath(): Promise<string> {
const folderPath = path.join(os.tmpdir(), 'ADS_Tests', `TestRun_${new Date().getTime()}`);
const folderPath = path.join(generateBaseFolderName(), `TestRun_${new Date().getTime()}`);
await fs.mkdir(folderPath, { recursive: true });
return folderPath;
}
export function generateBaseFolderName(): string {
const folderPath = path.join(os.tmpdir(), 'ADS_Tests');
return folderPath;
}
export async function createTestFile(contents: string, fileName: string, folderPath?: string): Promise<string> {
folderPath = folderPath ?? await generateTestFolderPath();
const filePath = path.join(folderPath, fileName);
@@ -249,3 +255,14 @@ export async function createOtherDummyFiles(testFolderPath: string): Promise<Uri
return filesList;
}
/**
* Deletes folder generated for testing
*/
export async function deleteGeneratedTestFolder(): Promise<void> {
const testFolderPath: string = generateBaseFolderName();
if (await exists(testFolderPath)) {
// cleanup folder
await fs.rm(testFolderPath, { recursive: true });
}
}