-
-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathPublish-PSBuildModule.tests.ps1
More file actions
77 lines (60 loc) · 2.96 KB
/
Publish-PSBuildModule.tests.ps1
File metadata and controls
77 lines (60 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
Describe 'Publish-PSBuildModule' {
BeforeAll {
$script:moduleRoot = Split-Path -Path $PSScriptRoot -Parent
Import-Module ([IO.Path]::Combine($script:moduleRoot, 'PowerShellBuild', 'PowerShellBuild.psd1')) -Force
}
It 'Should exist and be exported' {
Get-Command Publish-PSBuildModule -Module PowerShellBuild -ErrorAction SilentlyContinue |
Should -Not -BeNullOrEmpty
}
It 'Requires Path parameter' {
$command = Get-Command Publish-PSBuildModule
$command.Parameters['Path'].Attributes.Where({ $_.TypeId.Name -eq 'ParameterAttribute' }).Mandatory |
Should -Contain $true
}
It 'Requires Version parameter' {
$command = Get-Command Publish-PSBuildModule
$command.Parameters['Version'].Attributes.Where({ $_.TypeId.Name -eq 'ParameterAttribute' }).Mandatory |
Should -Contain $true
}
It 'Requires Repository parameter' {
$command = Get-Command Publish-PSBuildModule
$command.Parameters['Repository'].Attributes.Where({ $_.TypeId.Name -eq 'ParameterAttribute' }).Mandatory |
Should -Contain $true
}
It 'Throws when Path does not exist' {
$missingPath = Join-Path -Path $TestDrive -ChildPath 'does-not-exist'
{ Publish-PSBuildModule -Path $missingPath -Version '1.0.0' -Repository 'PSGallery' } |
Should -Throw
}
It 'Throws when Path is a file instead of a directory' {
$filePath = Join-Path -Path $TestDrive -ChildPath 'module.psm1'
New-Item -Path $filePath -ItemType File -Force | Out-Null
{ Publish-PSBuildModule -Path $filePath -Version '1.0.0' -Repository 'PSGallery' } |
Should -Throw
}
It 'Passes NuGetApiKey to Publish-Module when provided' {
$modulePath = Join-Path -Path $TestDrive -ChildPath 'MyModule'
New-Item -Path $modulePath -ItemType Directory -Force | Out-Null
Mock Publish-Module {}
Publish-PSBuildModule -Path $modulePath -Version '1.0.0' -Repository 'PSGallery' -NuGetApiKey 'abc123'
Should -Invoke Publish-Module -Times 1 -Exactly -ParameterFilter {
$Path -eq $modulePath -and
$Repository -eq 'PSGallery' -and
$NuGetApiKey -eq 'abc123'
}
}
It 'Passes Credential to Publish-Module when provided' {
$modulePath = Join-Path -Path $TestDrive -ChildPath 'MyModuleWithCred'
New-Item -Path $modulePath -ItemType Directory -Force | Out-Null
$securePassword = ConvertTo-SecureString -String 'pw' -AsPlainText -Force
$credential = [PSCredential]::new('user', $securePassword)
Mock Publish-Module {}
Publish-PSBuildModule -Path $modulePath -Version '1.0.0' -Repository 'PSGallery' -Credential $credential
Should -Invoke Publish-Module -Times 1 -Exactly -ParameterFilter {
$Path -eq $modulePath -and
$Repository -eq 'PSGallery' -and
$Credential.UserName -eq 'user'
}
}
}