mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-19 17:22:48 -05:00
Add support for showing files for glob style sql projects (#17518)
* use glob to get files for new style msbuild sdk sqlproj * add tests * cleanup * fix test * don't show bin and obj files and folders * handle other glob patterns * fix duplicate entries getting added for glob patterns in project's folder
This commit is contained in:
@@ -827,6 +827,95 @@ describe('Project: sqlproj content operations', function (): void {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Project: Msbuild sdk style project content operations', function (): void {
|
||||
before(async function (): Promise<void> {
|
||||
await baselines.loadBaselines();
|
||||
});
|
||||
|
||||
beforeEach(function (): void {
|
||||
sinon.restore();
|
||||
});
|
||||
|
||||
it('Should read project from sqlproj and files and folders by globbing', async function (): Promise<void> {
|
||||
projFilePath = await testUtils.createTestSqlProjFile(baselines.openNewStyleSqlProjectBaseline);
|
||||
await testUtils.createDummyFileStructureWithPrePostDeployScripts(false, undefined, path.dirname(projFilePath));
|
||||
const project: Project = await Project.openProject(projFilePath);
|
||||
|
||||
// Files and folders
|
||||
should(project.files.filter(f => f.type === EntryType.Folder).length).equal(2);
|
||||
should(project.files.filter(f => f.type === EntryType.File).length).equal(15);
|
||||
|
||||
// SqlCmdVariables
|
||||
should(Object.keys(project.sqlCmdVariables).length).equal(2);
|
||||
should(project.sqlCmdVariables['ProdDatabaseName']).equal('MyProdDatabase');
|
||||
should(project.sqlCmdVariables['BackupDatabaseName']).equal('MyBackupDatabase');
|
||||
|
||||
// Database references
|
||||
// should only have one database reference even though there are two master.dacpac references (1 for ADS and 1 for SSDT)
|
||||
should(project.databaseReferences.length).equal(1);
|
||||
should(project.databaseReferences[0].databaseName).containEql(constants.master);
|
||||
should(project.databaseReferences[0] instanceof SystemDatabaseReferenceProjectEntry).equal(true);
|
||||
|
||||
// // Pre-post deployment scripts
|
||||
should(project.preDeployScripts.length).equal(1);
|
||||
should(project.postDeployScripts.length).equal(1);
|
||||
should(project.noneDeployScripts.length).equal(2);
|
||||
should(project.preDeployScripts.find(f => f.type === EntryType.File && f.relativePath === 'Script.PreDeployment1.sql')).not.equal(undefined, 'File Script.PreDeployment1.sql not read');
|
||||
should(project.noneDeployScripts.find(f => f.type === EntryType.File && f.relativePath === 'Script.PreDeployment2.sql')).not.equal(undefined, 'File Script.PreDeployment2.sql not read');
|
||||
should(project.postDeployScripts.find(f => f.type === EntryType.File && f.relativePath === 'Script.PostDeployment1.sql')).not.equal(undefined, 'File Script.PostDeployment1.sql not read');
|
||||
should(project.noneDeployScripts.find(f => f.type === EntryType.File && f.relativePath === 'folder1\\Script.PostDeployment2.sql')).not.equal(undefined, 'File folder1\\Script.PostDeployment2.sql not read');
|
||||
});
|
||||
|
||||
it('Should handle files listed in sqlproj', async function (): Promise<void> {
|
||||
projFilePath = await testUtils.createTestSqlProjFile(baselines.openNewStyleSqlProjectWithFilesSpecifiedBaseline);
|
||||
await testUtils.createDummyFileStructure(false, undefined, path.dirname(projFilePath));
|
||||
|
||||
const project: Project = await Project.openProject(projFilePath);
|
||||
|
||||
// Files and folders
|
||||
should(project.files.filter(f => f.type === EntryType.Folder).length).equal(2);
|
||||
should(project.files.filter(f => f.type === EntryType.File).length).equal(11);
|
||||
|
||||
// these are also listed in the sqlproj, but there shouldn't be duplicate entries for them
|
||||
should(project.files.filter(f => f.relativePath === 'folder1\\file2.sql').length).equal(1);
|
||||
should(project.files.filter(f => f.relativePath === 'file1.sql').length).equal(1);
|
||||
should(project.files.filter(f => f.relativePath === 'folder1').length).equal(1);
|
||||
});
|
||||
|
||||
it('Should handle globbing patterns listed in sqlproj', async function (): Promise<void> {
|
||||
const testFolderPath = await testUtils.generateTestFolderPath();
|
||||
const mainProjectPath = path.join(testFolderPath, 'project');
|
||||
const otherFolderPath = path.join(testFolderPath, 'other');
|
||||
projFilePath = await testUtils.createTestSqlProjFile(baselines.openNewStyleSqlProjectWithGlobsSpecifiedBaseline, mainProjectPath);
|
||||
await testUtils.createDummyFileStructure(false, undefined, path.dirname(projFilePath));
|
||||
|
||||
// create files outside of project folder that are included in the project file
|
||||
await fs.mkdir(otherFolderPath);
|
||||
await testUtils.createOtherDummyFiles(otherFolderPath);
|
||||
|
||||
const project: Project = await Project.openProject(projFilePath);
|
||||
|
||||
should(project.files.filter(f => f.type === EntryType.File).length).equal(17);
|
||||
|
||||
// make sure all the correct files from the globbing patterns were included
|
||||
// ..\other\folder1\test?.sql
|
||||
should(project.files.filter(f => f.relativePath === '..\\other\\folder1\\test1.sql').length).equal(1);
|
||||
should(project.files.filter(f => f.relativePath === '..\\other\\folder1\\test2.sql').length).equal(1);
|
||||
should(project.files.filter(f => f.relativePath === '..\\other\\folder1\\testLongerName.sql').length).equal(0);
|
||||
|
||||
// ..\other\folder1\file*.sql
|
||||
should(project.files.filter(f => f.relativePath === '..\\other\\folder1\\file1.sql').length).equal(1);
|
||||
should(project.files.filter(f => f.relativePath === '..\\other\\folder1\\file2.sql').length).equal(1);
|
||||
|
||||
// ..\other\folder2\*.sql
|
||||
should(project.files.filter(f => f.relativePath === '..\\other\\folder2\\file1.sql').length).equal(1);
|
||||
should(project.files.filter(f => f.relativePath === '..\\other\\folder2\\file2.sql').length).equal(1);
|
||||
|
||||
// make sure no duplicates from folder1\*.sql
|
||||
should(project.files.filter(f => f.relativePath === 'folder1\\file1.sql').length).equal(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Project: add SQLCMD Variables', function (): void {
|
||||
before(async function (): Promise<void> {
|
||||
await baselines.loadBaselines();
|
||||
|
||||
Reference in New Issue
Block a user