|
1 |
| - |
| 1 | + |
2 | 2 | Describe "choco pack" -Tag Chocolatey, PackCommand {
|
3 | 3 | BeforeDiscovery {
|
4 | 4 | $successPack = @('basic'; 'basic-dependencies'; "cdata"; "full")
|
5 | 5 | # Required elements, that can also not be empty
|
6 | 6 | $missingFailures = @('id'; 'version'; 'authors'; 'description')
|
7 |
| -# Elements that can not be set to an empty string, but are not required |
8 |
| -$emptyFailures = @( |
9 |
| - "projectUrl" |
10 |
| - "projectSourceUrl" |
11 |
| - "docsUrl" |
12 |
| - "bugTrackerUrl" |
13 |
| - "mailingListUrl" |
14 |
| - "iconUrl" |
15 |
| - "licenseUrl" |
16 |
| -) |
17 |
| -# Elements that will return an invalid failure (usually due to serialization) |
18 |
| -$invalidFailures = @( |
19 |
| - @{id = 'projectUrl'; message = "ERROR: CHCU0001: 'invalid project url' is not a valid URL for the projectUrl element in the package nuspec file." } |
20 |
| - @{id = 'projectSourceUrl'; message = "ERROR: CHCU0001: 'invalid project source url' is not a valid URL for the projectSourceUrl element in the package nuspec file." } |
21 |
| - @{id = 'docsUrl'; message = "ERROR: CHCU0001: 'invalid docs url' is not a valid URL for the docsUrl element in the package nuspec file." } |
22 |
| - @{id = 'bugTrackerUrl'; message = "ERROR: CHCU0001: 'invalid bug tracker url' is not a valid URL for the bugTrackerUrl element in the package nuspec file." } |
23 |
| - @{id = 'mailingListUrl'; message = "ERROR: CHCU0001: 'invalid mailing list url' is not a valid URL for the mailingListUrl element in the package nuspec file." } |
24 |
| - @{id = 'iconUrl'; message = "ERROR: CHCU0001: 'invalid icon url' is not a valid URL for the iconUrl element in the package nuspec file." } |
25 |
| - @{id = 'licenseUrl'; message = "ERROR: CHCU0001: 'invalid license url' is not a valid URL for the licenseUrl element in the package nuspec file." } |
26 |
| - @{id = "version"; message = "ERROR: CHCU0001: 'INVALID' is not a valid version string in the package nuspec file." } |
27 |
| - @{id = "no-content"; message = "Cannot create a package that has no dependencies nor content." } # This is a message from NuGet.Client, we may want to take ownership of it eventually. |
| 7 | + # Elements that can not be set to an empty string, but are not required |
| 8 | + $emptyFailures = @( |
| 9 | + "projectUrl" |
| 10 | + "projectSourceUrl" |
| 11 | + "docsUrl" |
| 12 | + "bugTrackerUrl" |
| 13 | + "mailingListUrl" |
| 14 | + "iconUrl" |
| 15 | + "licenseUrl" |
| 16 | + ) |
| 17 | + # Elements that will return an invalid failure (usually due to serialization) |
| 18 | + $invalidFailures = @( |
| 19 | + @{id = 'projectUrl'; message = "ERROR: CHCU0001: 'invalid project url' is not a valid URL for the projectUrl element in the package nuspec file." } |
| 20 | + @{id = 'projectSourceUrl'; message = "ERROR: CHCU0001: 'invalid project source url' is not a valid URL for the projectSourceUrl element in the package nuspec file." } |
| 21 | + @{id = 'docsUrl'; message = "ERROR: CHCU0001: 'invalid docs url' is not a valid URL for the docsUrl element in the package nuspec file." } |
| 22 | + @{id = 'bugTrackerUrl'; message = "ERROR: CHCU0001: 'invalid bug tracker url' is not a valid URL for the bugTrackerUrl element in the package nuspec file." } |
| 23 | + @{id = 'mailingListUrl'; message = "ERROR: CHCU0001: 'invalid mailing list url' is not a valid URL for the mailingListUrl element in the package nuspec file." } |
| 24 | + @{id = 'iconUrl'; message = "ERROR: CHCU0001: 'invalid icon url' is not a valid URL for the iconUrl element in the package nuspec file." } |
| 25 | + @{id = 'licenseUrl'; message = "ERROR: CHCU0001: 'invalid license url' is not a valid URL for the licenseUrl element in the package nuspec file." } |
| 26 | + @{id = "version"; message = "ERROR: CHCU0001: 'INVALID' is not a valid version string in the package nuspec file." } |
| 27 | + @{id = "no-content"; message = "Cannot create a package that has no dependencies nor content." } # This is a message from NuGet.Client, we may want to take ownership of it eventually. |
28 | 28 | @{id = "id"; message = "The package ID 'invalid id' contains invalid characters. Examples of valid package IDs include 'MyPackage' and 'MyPackage.Sample'." } # This is a message from NuGet.Client, we may want to take ownership of it eventually.
|
29 | 29 | @{id = "requirelicenseacceptance"; message = "ERROR: CHCR0002: Enabling license acceptance requires a license url." }
|
30 | 30 | )
|
@@ -585,6 +585,45 @@ $invalidFailures = @(
|
585 | 585 | }
|
586 | 586 | }
|
587 | 587 |
|
| 588 | + Context 'Packing a package with non-normalized versions generates normalized versions' -ForEach @( |
| 589 | + @{ ExpectedPackageVersion = '0.1.0' ; ProvidedVersion = '0.1.0.0' } |
| 590 | + @{ ExpectedPackageVersion = '1.2.3.4' ; ProvidedVersion = '01.02.03.04' } |
| 591 | + @{ ExpectedPackageVersion = '1.2.4' ; ProvidedVersion = '01.02.04' } |
| 592 | + @{ ExpectedPackageVersion = '1.2.0' ; ProvidedVersion = '01.02' } |
| 593 | + @{ ExpectedPackageVersion = '1.2.3' ; ProvidedVersion = '0001.0002.0003' } |
| 594 | + ) { |
| 595 | + BeforeAll { |
| 596 | + Restore-ChocolateyInstallSnapshot |
| 597 | + $PackageUnderTest = 'nonnormalizedversions' |
| 598 | + Push-Location (New-Item "$(Get-TempDirectory)/$(New-Guid)" -ItemType Directory) |
| 599 | + $null = Invoke-Choco new $PackageUnderTest --version $ProvidedVersion |
| 600 | + $SourceNuspec = "$PWD/$PackageUnderTest/$PackageUnderTest.nuspec" |
| 601 | + $Output = Invoke-Choco pack $SourceNuspec |
| 602 | + } |
| 603 | + |
| 604 | + AfterAll { |
| 605 | + Pop-Location |
| 606 | + } |
| 607 | + |
| 608 | + It "Should exit with success (0)" { |
| 609 | + $Output.ExitCode | Should -Be 0 -Because $Output.String |
| 610 | + } |
| 611 | + |
| 612 | + It "Should report successful installation" { |
| 613 | + $Output.Lines | Should -Contain "Successfully created package '$PWD\$PackageUnderTest.$ExpectedPackageVersion.nupkg'" -Because $Output.String |
| 614 | + } |
| 615 | + |
| 616 | + It "Should have generated the correct files" { |
| 617 | + $ExpectedNupkg = "$PWD/$PackageUnderTest.$ExpectedPackageVersion.nupkg" |
| 618 | + $ExpectedNupkg | Should -Exist -Because $Output.String |
| 619 | + Expand-ZipArchive -Source $ExpectedNupkg -Destination "$PWD/$PackageUnderTest-expanded" |
| 620 | + $SourceNuspecContents = [xml](Get-Content $SourceNuspec) |
| 621 | + $PackedNuspecContents = [xml](Get-Content "$PWD/$PackageUnderTest-expanded/$PackageUnderTest.nuspec") |
| 622 | + $SourceNuspecContents.package.metadata.version | Should -Be $ProvidedVersion |
| 623 | + $PackedNuspecContents.package.metadata.version | Should -Be $ExpectedPackageVersion |
| 624 | + } |
| 625 | + } |
| 626 | + |
588 | 627 | # This needs to be the last test in this block, to ensure NuGet configurations aren't being created.
|
589 | 628 | Test-NuGetPaths
|
590 | 629 | }
|
0 commit comments