fix pre/post deploy scripts getting double counted in the files for sdk style projects (#17954)

* fix pre/post deploy scripts getting double counted in the files for sdk style projects

* add test

* update comment
This commit is contained in:
Kim Santiago
2021-12-16 15:32:32 -08:00
committed by GitHub
parent 6f3a68bf68
commit b6d38e6e58
4 changed files with 58 additions and 8 deletions

View File

@@ -20,6 +20,13 @@
<Build Include="..\other\file1.sql" />
<Build Include="folder1\*.sql" />
</ItemGroup>
<ItemGroup>
<PreDeploy Include="..\other\folder2\Script.PreDeployment1.sql" />
</ItemGroup>
<ItemGroup>
<PostDeploy Include="..\other\folder2\Script.PostDeployment1.sql" />
<None Include="..\other\folder2\Script.PostDeployment2.sql" />
</ItemGroup>
<ItemGroup>
<ArtifactReference Condition="'$(NetCoreBuild)' == 'true'" Include="$(NETCoreTargetsPath)\SystemDacpacs\150\master.dacpac">
<SuppressMissingDependenciesErrors>False</SuppressMissingDependenciesErrors>

View File

@@ -844,7 +844,7 @@ describe('Project: sdk style project content operations', function (): void {
// Files and folders
should(project.files.filter(f => f.type === EntryType.Folder).length).equal(3);
should(project.files.filter(f => f.type === EntryType.File).length).equal(17);
should(project.files.filter(f => f.type === EntryType.File).length).equal(13);
// SqlCmdVariables
should(Object.keys(project.sqlCmdVariables).length).equal(2);
@@ -883,6 +883,27 @@ describe('Project: sdk style project content operations', function (): void {
should(project.files.filter(f => f.relativePath === 'folder1\\').length).equal(1);
});
it('Should handle pre/post/none deploy scripts outside of project folder', 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.openSdkStyleSqlProjectWithGlobsSpecifiedBaseline, 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);
// verify files, folders, pre/post/none deploy scripts were loaded correctly
should(project.files.filter(f => f.type === EntryType.Folder).length).equal(2);
should(project.files.filter(f => f.type === EntryType.File).length).equal(18);
should(project.preDeployScripts.length).equal(1);
should(project.postDeployScripts.length).equal(1);
should(project.noneDeployScripts.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');
@@ -1056,15 +1077,17 @@ describe('Project: sdk style project content operations', function (): void {
const project: Project = await Project.openProject(projFilePath);
should(project.files.filter(f => f.type === EntryType.File).length).equal(17);
should(project.files.filter(f => f.type === EntryType.File).length).equal(13);
should(project.files.filter(f => f.type === EntryType.Folder).length).equal(3);
should(project.noneDeployScripts.length).equal(2);
// try to exclude a glob included folder
await project.exclude(project.files.find(f => f.relativePath === 'folder1\\')!);
// verify folder and contents are excluded
should(project.files.filter(f => f.type === EntryType.Folder).length).equal(1);
should(project.files.filter(f => f.type === EntryType.File).length).equal(9);
should(project.files.filter(f => f.type === EntryType.File).length).equal(6);
should(project.noneDeployScripts.length).equal(1, 'Script.PostDeployment2.sql should have been excluded');
should(project.files.find(f => f.relativePath === 'folder1\\')).equal(undefined);
// verify sqlproj has glob exclude for folder, but not for files and inner folder
@@ -1082,7 +1105,7 @@ describe('Project: sdk style project content operations', function (): void {
const project: Project = await Project.openProject(projFilePath);
should(project.files.filter(f => f.type === EntryType.File).length).equal(17);
should(project.files.filter(f => f.type === EntryType.File).length).equal(13);
should(project.files.filter(f => f.type === EntryType.Folder).length).equal(3);
// try to exclude a glob included folder
@@ -1090,7 +1113,7 @@ describe('Project: sdk style project content operations', function (): void {
// verify folder and contents are excluded
should(project.files.filter(f => f.type === EntryType.Folder).length).equal(2);
should(project.files.filter(f => f.type === EntryType.File).length).equal(15);
should(project.files.filter(f => f.type === EntryType.File).length).equal(11);
should(project.files.find(f => f.relativePath === 'folder1\\nestedFolder\\')).equal(undefined);
// verify sqlproj has glob exclude for folder, but not for files

View File

@@ -198,6 +198,9 @@ export async function createListOfFiles(filePath?: string): Promise<Uri[]> {
* - folder2
* -file1.sql
* -file2.sql
* - Script.PreDeployment1.sql
* - Script.PostDeployment1.sql
* - Script.PostDeployment2.sql
*
*/
export async function createOtherDummyFiles(testFolderPath: string): Promise<string> {
@@ -221,5 +224,13 @@ export async function createOtherDummyFiles(testFolderPath: string): Promise<str
const testLongerName = path.join(testFolderPath, 'folder1', 'testLongerName.sql');
await fs.writeFile(testLongerName, '');
const preDeploymentScript = path.join(testFolderPath, 'folder2', 'Script.PreDeployment1.sql');
await fs.writeFile(preDeploymentScript, '');
const postDeploymentScript1 = path.join(testFolderPath, 'folder2', 'Script.PostDeployment1.sql');
await fs.writeFile(postDeploymentScript1, '');
const postDeploymentScript2 = path.join(testFolderPath, 'folder2', 'Script.PostDeployment2.sql');
await fs.writeFile(postDeploymentScript2, '');
return testFolderPath;
}