Skip to content

Commit c97337b

Browse files
authored
Merge pull request #104 from sqlcollaborative/feature/fix-match
Files in subfolders are not being added when -Match is used
2 parents 9451038 + 5a93812 commit c97337b

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

internal/functions/Get-DbopsFile.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
)
1515
Write-PSFMessage -Level Debug -Message "Getting child items from $Item; Root defined as $Root"
1616
$fileItems = Get-ChildItem $Item.FullName
17-
if ($Match) { $fileItems = $fileItems | Where-Object Name -match ($Match -join '|') }
1817
foreach ($childItem in $fileItems) {
1918
if ($childItem.PSIsContainer) {
2019
if ($Recurse) { Select-DbopsFile -Item (Get-Item $childItem.FullName) -Root $Root }
2120
}
2221
else {
22+
if ($Match -and $childItem.Name -notmatch ($Match -join '|')) { continue }
2323
if ($Relative) {
2424
$pkgPath = Resolve-Path $childItem.FullName -Relative
2525
}

tests/Add-DBOBuild.Tests.ps1

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ Describe "Add-DBOBuild tests" -Tag $commandName, UnitTests {
192192
$testResults.Name | Should Be (Split-Path $packageNameTest -Leaf)
193193
Test-Path $packageNameTest | Should Be $true
194194
$scripts = $testResults.GetBuild('2.0').Scripts
195-
Join-PSFPath -Normalize 'content\2.0' ((Resolve-Path $v2scripts -Relative) -replace '^\.\\|^\.\/', '')| Should BeIn $scripts.GetPackagePath()
195+
Join-PSFPath -Normalize 'content\2.0' ((Resolve-Path $v2scripts -Relative) -replace '^\.\\|^\.\/', '') | Should BeIn $scripts.GetPackagePath()
196196
Join-PSFPath -Normalize 'content\2.0\1.sql' | Should Not BeIn $scripts.GetPackagePath()
197197
$items = Get-ArchiveItem $packageNameTest
198198
Join-PSFPath -Normalize 'content\1.0\1.sql' | Should BeIn $items.Path
@@ -204,7 +204,7 @@ Describe "Add-DBOBuild tests" -Tag $commandName, UnitTests {
204204
$testResults.Name | Should Be (Split-Path $packageNameTest -Leaf)
205205
Test-Path $packageNameTest | Should Be $true
206206
$scripts = $testResults.GetBuild('2.0').Scripts
207-
Join-PSFPath -Normalize 'content\2.0' ($v2scripts -replace ':', '')| Should BeIn $scripts.GetPackagePath()
207+
Join-PSFPath -Normalize 'content\2.0' ($v2scripts -replace ':', '') | Should BeIn $scripts.GetPackagePath()
208208
Join-PSFPath -Normalize 'content\2.0\1.sql' | Should Not BeIn $scripts.GetPackagePath()
209209
$items = Get-ArchiveItem $packageNameTest
210210
Join-PSFPath -Normalize 'content\1.0\1.sql' | Should BeIn $items.Path
@@ -242,6 +242,22 @@ Describe "Add-DBOBuild tests" -Tag $commandName, UnitTests {
242242
Join-PSFPath -Normalize 'content\2.0\2.sql' | Should BeIn $items.Path
243243
Join-PSFPath -Normalize 'content\2.0\3.sql' | Should Not BeIn $items.Path
244244
}
245+
It "Should add only matched files from a recursive folder" {
246+
$testResults = Add-DBOBuild -ScriptPath $noRecurseFolder\* -Name $packageNameTest -Build 2.0 -Match '2\.sql'
247+
$testResults | Should Not Be $null
248+
$testResults.Name | Should Be (Split-Path $packageNameTest -Leaf)
249+
Test-Path $packageNameTest | Should Be $true
250+
$scripts = $testResults.GetBuild('2.0').Scripts
251+
$scripts | Should -Not -BeNullOrEmpty
252+
Join-PSFPath -Normalize 'content\2.0\success\1.sql' | Should Not BeIn $scripts.GetPackagePath()
253+
Join-PSFPath -Normalize 'content\2.0\success\2.sql' | Should BeIn $scripts.GetPackagePath()
254+
Join-PSFPath -Normalize 'content\2.0\success\3.sql' | Should Not BeIn $scripts.GetPackagePath()
255+
$items = Get-ArchiveItem $packageNameTest
256+
Join-PSFPath -Normalize 'content\1.0\1.sql' | Should BeIn $items.Path
257+
Join-PSFPath -Normalize 'content\2.0\success\1.sql' | Should Not BeIn $items.Path
258+
Join-PSFPath -Normalize 'content\2.0\success\2.sql' | Should BeIn $items.Path
259+
Join-PSFPath -Normalize 'content\2.0\success\3.sql' | Should Not BeIn $items.Path
260+
}
245261
}
246262
Context "negative tests" {
247263
BeforeAll {
@@ -267,7 +283,7 @@ Describe "Add-DBOBuild tests" -Tag $commandName, UnitTests {
267283
$errorResult.Exception.Message -join ';' | Should BeLike '*Incorrect package format*'
268284
}
269285
It "should throw error when package zip does not exist" {
270-
{ Add-DBOBuild -Name ".\nonexistingpackage.zip" -ScriptPath $v1scripts -ErrorAction Stop} | Should Throw
286+
{ Add-DBOBuild -Name ".\nonexistingpackage.zip" -ScriptPath $v1scripts -ErrorAction Stop } | Should Throw
271287
}
272288
It "should throw error when path cannot be resolved" {
273289
try {

0 commit comments

Comments
 (0)