forked from deadlydog/PowerShell.tiPS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInvoke-SmokeTests.ps1
More file actions
98 lines (84 loc) · 3.35 KB
/
Invoke-SmokeTests.ps1
File metadata and controls
98 lines (84 loc) · 3.35 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# These tests are runs as part of the deployment process to ensure the newly published module is working as expected.
# These tests run against the installed module, not the source code, so they are a real-world test and should not use mocks.
# Since mocks are not used, we must be careful to not rely on state stored on the machine, such as the module Configuration file.
# This is a great place to put tests that differ between operating systems, since they will be ran on multiple platforms.
# To run these tests on your local machine, see the comments in the BeforeAll block.
BeforeAll {
Import-Module -Name tiPS -Force
# To run these tests on your local machine, comment out the Import-Module command above and uncomment the one below.
# Do this to use the module version from source code, not the installed version.
# This is necessary to test functionality that you've added to the module, but have not yet published and installed.
# Import-Module "$PSScriptRoot\..\src\tiPS" -Force
}
Describe 'Get-PowerShellTip' {
Context 'Given no parameters' {
It 'Should return a tip' {
$tip = Get-PowerShellTip
$tip | Should -Not -BeNullOrEmpty
}
It 'Should not return an error' {
$Error.Clear()
{ Get-PowerShellTip } | Should -Not -Throw
$Error[0] | Should -BeNullOrEmpty
}
}
Context 'Given a valid tip ID' {
It 'Should return the tip with the specified ID' {
$tip = Get-PowerShellTip -Id '2023-07-16-powershell-is-open-source'
$tip.Id | Should -Be '2023-07-16-powershell-is-open-source'
}
It 'Should not return an error' {
$Error.Clear()
{ Get-PowerShellTip -Id '2023-07-16-powershell-is-open-source' } | Should -Not -Throw
$Error[0] | Should -BeNullOrEmpty
}
}
Context 'Given an invalid tip ID' {
It 'Should write an error' {
Get-PowerShellTip -Id 'TipIdThatDoesNotExist' -ErrorVariable tipError -ErrorAction SilentlyContinue > $null
$tipError | Should -Not -BeNullOrEmpty
}
}
Context 'Given the All switch' {
It 'Should return all tips' {
$allTips = Get-PowerShellTip -All
$allTips | Should -Not -BeNullOrEmpty
$allTips.Count | Should -BeGreaterThan 2
}
It 'Should not return any expired tips, as they should have been removed during initialization' {
$allTips = Get-PowerShellTip -All
$expiredTips = $allTips.Values | Where-Object { $_.ExpiryDate -lt [DateTime]::Today }
$expiredTips | Should -BeNullOrEmpty
}
}
}
Describe 'Write-PowerShellTip' {
Context 'Given no parameters' {
It 'Should write a tip to the terminal without error' {
$Error.Clear()
{ Write-PowerShellTip } | Should -Not -Throw
$Error[0] | Should -BeNullOrEmpty
}
}
Context 'Given a valid tip ID' {
It 'Should write the tip to the terminal without error' {
$Error.Clear()
{ Write-PowerShellTip -Id '2023-07-16-powershell-is-open-source' } | Should -Not -Throw
$Error[0] | Should -BeNullOrEmpty
}
}
Context 'Given an invalid tip ID' {
It 'Should write an error' {
Write-PowerShellTip -Id 'TipIdThatDoesNotExist' -ErrorVariable tipError -ErrorAction SilentlyContinue > $null
$tipError | Should -Not -BeNullOrEmpty
}
}
}
Describe 'Test-PowerShellProfileImportsTiPS' {
Context 'Given the module module was just installed' {
It 'Should not detect that the module is imported by the PowerShell profile' {
$profileImportsTiPS = Test-PowerShellProfileImportsTiPS
$profileImportsTiPS | Should -Be $false
}
}
}