Enable sql-database-projects tests with few fixes (#10610)

* Added 2tests related to import. Fixed a few issues. Enable sql-database-projects

* Addressed comment
This commit is contained in:
Sakshi Sharma
2020-05-30 09:05:55 -07:00
committed by GitHub
parent 7d31239e64
commit 84492049e8
5 changed files with 50 additions and 15 deletions

View File

@@ -14,7 +14,7 @@ import { Project, EntryType } from '../models/project';
let projFilePath: string;
describe('Project: sqlproj content operations', function (): void {
before(async function () : Promise<void> {
before(async function() : Promise<void> {
await baselines.loadBaselines();
});
@@ -52,7 +52,7 @@ describe('Project: sqlproj content operations', function (): void {
const newFileContents = (await fs.readFile(path.join(newProject.projectFolderPath, filePath))).toString();
should (newFileContents).equal(fileContents);
should(newFileContents).equal(fileContents);
});
it('Should add Folder and Build entries to sqlproj with pre-existing scripts on disk', async function (): Promise<void> {
@@ -65,6 +65,20 @@ describe('Project: sqlproj content operations', function (): void {
await project.addToProject(list);
should(project.files.filter(f => f.type === EntryType.File).length).equal(11); // txt file shouldn't be added to the project
should(project.files.filter(f => f.type === EntryType.Folder).length).equal(3); // 2folders + default Properties folder
should(project.files.filter(f => f.type === EntryType.Folder).length).equal(3); // 2folders + default Properties folder
});
it('Should throw error while adding Folder and Build entries to sqlproj when a file/folder does not exist on disk', async function (): Promise<void> {
projFilePath = await testUtils.createTestSqlProjFile(baselines.newProjectFileBaseline);
const project = new Project(projFilePath);
await project.readProjFile();
let list: string[] = [];
let testFolderPath: string = await testUtils.createDummyFileStructure(true, list, path.dirname(projFilePath));
const nonexistentFile = path.join(testFolderPath, 'nonexistentFile.sql');
list.push(nonexistentFile);
await testUtils.shouldThrowSpecificError(async () => await project.addToProject(list), `ENOENT: no such file or directory, stat \'${nonexistentFile}\'`);
});
});

View File

@@ -42,9 +42,12 @@ const mockConnectionProfile: azdata.IConnectionProfile = {
options: undefined as any
};
beforeEach(async function (): Promise<void> {
testContext = createContext();
});
describe('ProjectsController: project controller operations', function (): void {
before(async function (): Promise<void> {
testContext = createContext();
await templates.loadTemplates(path.join(__dirname, '..', '..', 'resources', 'templates'));
await baselines.loadBaselines();
});
@@ -157,8 +160,10 @@ describe('ProjectsController: import operations', function (): void {
});
it('Should error out for inaccessible path', async function (): Promise<void> {
testContext.apiWrapper.setup(x => x.showErrorMessage(TypeMoq.It.isAny())).returns((s) => { throw new Error(s); });
let testFolderPath = await testUtils.generateTestFolderPath();
testFolderPath += '_nonExistant'; // Modify folder path to point to a non-existant location
testFolderPath += '_nonexistentFolder'; // Modify folder path to point to a nonexistent location
const projController = new ProjectsController(testContext.apiWrapper.object, new SqlDatabaseProjectTreeViewProvider());
@@ -187,7 +192,7 @@ describe('ProjectsController: import operations', function (): void {
it('Should show error when no location provided with ExtractTarget = File', async function (): Promise<void> {
testContext.apiWrapper.setup(x => x.showInputBox(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve('MyProjectName'));
testContext.apiWrapper.setup(x => x.showQuickPick(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve({label: 'File'}));
testContext.apiWrapper.setup(x => x.showQuickPick(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve({ label: 'File' }));
testContext.apiWrapper.setup(x => x.showSaveDialog(TypeMoq.It.isAny())).returns(() => Promise.resolve(undefined));
testContext.apiWrapper.setup(x => x.showErrorMessage(TypeMoq.It.isAny())).returns((s) => { throw new Error(s); });
@@ -197,7 +202,7 @@ describe('ProjectsController: import operations', function (): void {
it('Should show error when no location provided with ExtractTarget = SchemaObjectType', async function (): Promise<void> {
testContext.apiWrapper.setup(x => x.showInputBox(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve('MyProjectName'));
testContext.apiWrapper.setup(x => x.showQuickPick(TypeMoq.It.isAny())).returns(() => Promise.resolve({label: 'SchemaObjectType'}));
testContext.apiWrapper.setup(x => x.showQuickPick(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve({ label: 'SchemaObjectType' }));
testContext.apiWrapper.setup(x => x.showOpenDialog(TypeMoq.It.isAny())).returns(() => Promise.resolve(undefined));
testContext.apiWrapper.setup(x => x.workspaceFolders()).returns(() => undefined);
testContext.apiWrapper.setup(x => x.showErrorMessage(TypeMoq.It.isAny())).returns((s) => { throw new Error(s); });
@@ -205,4 +210,18 @@ describe('ProjectsController: import operations', function (): void {
const projController = new ProjectsController(testContext.apiWrapper.object, new SqlDatabaseProjectTreeViewProvider());
await testUtils.shouldThrowSpecificError(async () => await projController.importNewDatabaseProject(mockConnectionProfile), constants.projectLocationRequired);
});
it('Should show error when selected folder is not empty', async function (): Promise<void> {
const testFolderPath = await testUtils.createDummyFileStructure();
testContext.apiWrapper.setup(x => x.showInputBox(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve('MyProjectName'));
testContext.apiWrapper.setup(x => x.showQuickPick(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve({ label: 'ObjectType' }));
testContext.apiWrapper.setup(x => x.showOpenDialog(TypeMoq.It.isAny())).returns(() => Promise.resolve([vscode.Uri.file(testFolderPath)]));
testContext.apiWrapper.setup(x => x.workspaceFolders()).returns(() => undefined);
testContext.apiWrapper.setup(x => x.showErrorMessage(TypeMoq.It.isAny())).returns((s) => { throw new Error(s); });
const projController = new ProjectsController(testContext.apiWrapper.object, new SqlDatabaseProjectTreeViewProvider());
await testUtils.shouldThrowSpecificError(async () => await projController.importNewDatabaseProject(mockConnectionProfile), constants.projectLocationNotEmpty);
});
});

View File

@@ -79,7 +79,7 @@ export async function createDummyFileStructure(createList?: boolean, list?: stri
testFolderPath = testFolderPath ?? await generateTestFolderPath();
let filePath = path.join(testFolderPath, 'file1.sql');
await fs.open(filePath, 'w');
await fs.writeFile(filePath, '');
if (createList) {
list?.push(testFolderPath);
list?.push(filePath);
@@ -88,13 +88,14 @@ export async function createDummyFileStructure(createList?: boolean, list?: stri
for (let dirCount = 1; dirCount <= 2; dirCount++) {
let dirName = path.join(testFolderPath, `folder${dirCount}`);
await fs.mkdir(dirName, { recursive: true });
if (createList) {
list?.push(dirName);
}
for (let fileCount = 1; fileCount <= 5; fileCount++) {
let fileName = path.join(dirName, `file${fileCount}.sql`);
await fs.open(fileName, 'w');
await fs.writeFile(fileName, '');
if (createList) {
list?.push(fileName);
}
@@ -102,7 +103,8 @@ export async function createDummyFileStructure(createList?: boolean, list?: stri
}
filePath = path.join(testFolderPath, 'file2.txt');
await fs.open(filePath, 'w');
//await touchFile(filePath);
await fs.writeFile(filePath, '');
if (createList) {
list?.push(filePath);
}