|
1 | 1 | #requires -Module ModuleBuilder
|
2 | 2 | Describe "ResolveOutputFolder" {
|
3 |
| - |
4 |
| - Context "Given an OutputDirectory and ModuleBase" { |
5 |
| - |
6 |
| - $Result = InModuleScope -ModuleName ModuleBuilder { |
7 |
| - ResolveOutputFolder -OutputDirectory TestDrive:\Output -ModuleBase TestDrive:\Source |
| 3 | + $CommandInTest = InModuleScope ModuleBuilder { Get-Command ResolveOutputFolder } |
| 4 | + filter ToTestDrive { "$_".Replace($TestDrive, "TestDrive:") } |
| 5 | + |
| 6 | + $TestCases = [Hashtable[]]@( |
| 7 | + @{ Source = "Source" |
| 8 | + Output = "Output" |
| 9 | + Result = "Output\ModuleName" |
| 10 | + Forced = "Output\ModuleName\1.2.3" |
8 | 11 | }
|
9 |
| - |
10 |
| - It "Creates the Output directory" { |
11 |
| - $Result | Should -Be (Convert-Path "TestDrive:\Output") |
12 |
| - $Result | Should -Exist |
| 12 | + @{ Output = "ModuleName\Output" |
| 13 | + Source = "ModuleName\Source" |
| 14 | + Result = "ModuleName\Output\ModuleName" |
| 15 | + Forced = "ModuleName\Output\ModuleName\1.2.3" |
13 | 16 | }
|
14 |
| - } |
15 |
| - |
16 |
| - Context "Given an OutputDirectory, ModuleBase and ModuleVersion but no switch" { |
17 |
| - |
18 |
| - $Result = InModuleScope -ModuleName ModuleBuilder { |
19 |
| - ResolveOutputFolder -OutputDirectory TestDrive:\Output -ModuleVersion "1.0.0" -ModuleBase TestDrive:\Source |
| 17 | + @{ # Be like Jaykul |
| 18 | + Source = "ModuleName\Source" |
| 19 | + Output = "ModuleName" |
| 20 | + Result = "ModuleName\1.2.3" |
| 21 | + Forced = "ModuleName\1.2.3" |
20 | 22 | }
|
21 |
| - |
22 |
| - It "Creates the Output directory" { |
23 |
| - "TestDrive:\Output" | Should -Exist |
| 23 | + @{ # Be like azure |
| 24 | + Source = "1\s" |
| 25 | + Output = "1\b" |
| 26 | + Result = "1\b\ModuleName" |
| 27 | + Forced = "1\b\ModuleName\1.2.3" |
24 | 28 | }
|
25 |
| - |
26 |
| - It "Returns the Output directory" { |
27 |
| - $Result | Should -Be (Convert-Path "TestDrive:\Output") |
| 29 | + @{ # An edge case, build straight to a modules folder |
| 30 | + Source = "ModuleName\Source" |
| 31 | + Output = "Modules" |
| 32 | + Result = "Modules\ModuleName" |
| 33 | + Forced = "Modules\ModuleName\1.2.3" |
28 | 34 | }
|
29 |
| - |
30 |
| - It "Does not creates children in Output" { |
31 |
| - Get-ChildItem $Result | Should -BeNullOrEmpty |
| 35 | + @{ # What if they pass in the correct path ahead of time? |
| 36 | + Source = "1\s" |
| 37 | + Output = "1\b\ModuleName" |
| 38 | + Result = "1\b\ModuleName" |
| 39 | + Forced = "1\b\ModuleName\1.2.3" |
32 | 40 | }
|
33 |
| - } |
34 |
| - |
35 |
| - Context "Given an OutputDirectory, ModuleBase, ModuleVersion and switch" { |
36 |
| - |
37 |
| - $Result = InModuleScope -ModuleName ModuleBuilder { |
38 |
| - ResolveOutputFolder -OutputDirectory TestDrive:\Output -ModuleVersion "1.0.0" -VersionedOutput -ModuleBase TestDrive:\Source |
| 41 | + @{ # What if they pass in the correct path ahead of time? |
| 42 | + Source = "1\s" |
| 43 | + Output = "1\b\ModuleName\1.2.3" |
| 44 | + Result = "1\b\ModuleName\1.2.3" |
| 45 | + Forced = "1\b\ModuleName\1.2.3" |
39 | 46 | }
|
40 |
| - |
41 |
| - It "Creates the Output directory" { |
42 |
| - "TestDrive:\Output" | Should -Exist |
| 47 | + @{ # Super edge case: what if they pass in an incorrectly versioned output path? |
| 48 | + Source = "1\s" |
| 49 | + Output = "1\b\ModuleName\4.5.6" |
| 50 | + Result = "1\b\ModuleName\4.5.6\ModuleName" |
| 51 | + Forced = "1\b\ModuleName\4.5.6\ModuleName\1.2.3" |
43 | 52 | }
|
44 |
| - |
45 |
| - It "Creates the version directory" { |
46 |
| - "TestDrive:\Output\1.0.0" | Should -Exist |
| 53 | + ) |
| 54 | + Context "Build ModuleName" { |
| 55 | + It "From '<Source>' to '<Output>' creates '<Result>'" -TestCases $TestCases { |
| 56 | + param($Source, $Output, $Result) |
| 57 | + |
| 58 | + $Parameters = @{ |
| 59 | + Source = "TestDrive:\$Source" |
| 60 | + Output = "TestDrive:\$Output" |
| 61 | + } |
| 62 | + |
| 63 | + $Actual = &$CommandInTest @Parameters -Name ModuleName -Target Build -Version 1.2.3 | ToTestDrive |
| 64 | + $Actual | Should -Exist |
| 65 | + $Actual | Should -Be "TestDrive:\$Result" |
47 | 66 | }
|
48 | 67 |
|
49 |
| - It "Returns the Output directory" { |
50 |
| - $Result | Should -Be (Convert-Path "TestDrive:\Output\1.0.0") |
| 68 | + It "From '<Source>' to '<Output>' -ForceVersion creates '<Forced>'" -TestCases $TestCases { |
| 69 | + param($Source, $Output, $Forced) |
| 70 | + |
| 71 | + $Parameters = @{ |
| 72 | + Source = "TestDrive:\$Source" |
| 73 | + Output = "TestDrive:\$Output" |
| 74 | + } |
| 75 | + |
| 76 | + $Actual = &$CommandInTest @Parameters -Name ModuleName -Target Build -Version 1.2.3 -Force | ToTestDrive |
| 77 | + $Actual | Should -Exist |
| 78 | + $Actual | Should -Be "TestDrive:\$Forced" |
51 | 79 | }
|
52 | 80 | }
|
| 81 | + Context "Cleaned ModuleName" { |
| 82 | + It "From '<Source>' to '<Output>' deletes '<Result>'" -TestCases $TestCases { |
| 83 | + param($Source, $Output, $Result) |
| 84 | + |
| 85 | + $Parameters = @{ |
| 86 | + Source = "TestDrive:\$Source" |
| 87 | + Output = "TestDrive:\$Output" |
| 88 | + } |
| 89 | + |
| 90 | + $null = mkdir "TestDrive:\$Result" -Force |
| 91 | + |
| 92 | + # There's no output when we're cleaning |
| 93 | + &$CommandInTest @Parameters -Name ModuleName -Version 1.2.3 -Target Clean | Should -BeNullOrEmpty |
| 94 | + "TestDrive:\$Result" | Should -Not -Exist |
| 95 | + # NOTE: This is only true because we made it above |
| 96 | + "TestDrive:\$Result" | Split-Path | Should -Exist |
| 97 | + } |
53 | 98 |
|
54 |
| - Context "Given a relative OutputDirectory, the Folder is created relative to ModuleBase" { |
| 99 | + It "From '<Source>' to '<Output>' -ForceVersion deletes '<Forced>'" -TestCases $TestCases { |
| 100 | + param($Source, $Output, $Forced) |
55 | 101 |
|
| 102 | + $Parameters = @{ |
| 103 | + Source = "TestDrive:\$Source" |
| 104 | + Output = "TestDrive:\$Output" |
| 105 | + } |
| 106 | + $null = mkdir "TestDrive:\$Forced" -Force |
56 | 107 |
|
57 |
| - $Result = InModuleScope -ModuleName ModuleBuilder { |
58 |
| - ResolveOutputFolder -OutputDirectory '..\Output' -ModuleBase TestDrive:\Source |
| 108 | + # There's no output when we're cleaning |
| 109 | + &$CommandInTest @Parameters -Name ModuleName -Version 1.2.3 -Force -Target Clean | Should -BeNullOrEmpty |
| 110 | + "TestDrive:\$Forced" | Should -Not -Exist |
| 111 | + # NOTE: This is only true because we made it above |
| 112 | + "TestDrive:\$Forced" | Split-Path | Should -Exist |
59 | 113 | }
|
| 114 | + } |
| 115 | + Context "Error Cases" { |
| 116 | + It "Won't remove a file that blocks the folder path" { |
| 117 | + $null = mkdir TestDrive:\ModuleName\Source -force |
| 118 | + New-Item TestDrive:\ModuleName\1.2.3 -ItemType File -Value "Hello World" |
60 | 119 |
|
61 |
| - It "Returns an absolute FileSystem path" { |
62 |
| - { [io.path]::IsPathRooted($Result) } | Should -Not -Throw |
63 |
| - } |
| 120 | + $Parameters = @{ |
| 121 | + Source = "TestDrive:\ModuleName\Source" |
| 122 | + Output = "TestDrive:\ModuleName\" |
| 123 | + } |
64 | 124 |
|
65 |
| - It "has created the Folder" { |
66 |
| - (Test-Path $Result) | Should -Be $True |
| 125 | + { &$CommandInTest @Parameters -Name ModuleName -Target Build -Version 1.2.3 -Force } | Should -throw "There is a file in the way" |
67 | 126 | }
|
68 |
| - |
69 | 127 | }
|
70 | 128 | }
|
0 commit comments