forked from StefanScherer/choco-packer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.ps1
110 lines (95 loc) · 3.29 KB
/
test.ps1
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
99
100
101
102
103
104
105
106
107
108
109
110
param(
[string]$cpu
)
if (!$cpu) {
$cpu = "x64"
}
if ($cpu -eq "x86") {
$options = "-forcex86"
}
"Running tests for $cpu"
$ErrorActionPreference = "Stop"
"TEST: Uninstall packer first"
. choco uninstall packer
[xml]$spec = Get-Content packer.nuspec
$version = $spec.package.metadata.version
$binaryVersion = $version -replace('^([0-9]+\.[0-9]+\.[0-9]+)\..+$', '$1')
"TEST: Version $version in packer.nuspec file should match"
[xml]$spec = Get-Content packer.nuspec
if ($spec.package.metadata.version.CompareTo($version)) {
Write-Error "FAIL: Wrong version in nuspec file!"
}
"TEST: Package should contain only install script"
Add-Type -assembly "system.io.compression.filesystem"
$zip = [IO.Compression.ZipFile]::OpenRead("$pwd\packer.$version.nupkg")
# Write-Host $zip.Entries.FullName
Write-Host $zip.Entries.Count
if ($zip.Entries.Count -ne 5) {
Write-Error "FAIL: Wrong count in nupkg!"
}
$zip.Dispose()
"TEST: Installation of package should work"
. choco install -y packer $options -source . -version $version
"TEST: Version of binary should match"
$v = $(packer version)
$v
if (-Not $v.Contains("Packer v$binaryVersion")) {
Write-Error "FAIL: Wrong version of packer installed!"
}
$v = $(packer --version)
$v
if (-Not $v.Contains("$binaryVersion")) {
Write-Error "FAIL: Wrong version of packer installed!"
}
"TEST: All plugins are ignored"
. ls C:\programdata\chocolatey\lib\packer
. ls C:\programdata\chocolatey\lib\packer\tools
$numExe = (get-childitem -path C:\programdata\chocolatey\lib\packer\tools\ | where { $_.extension -eq ".exe" }).Count
Write-Host "numExe $numExe"
$numIgnore = (get-childitem -path C:\programdata\chocolatey\lib\packer\tools\ | where { $_.extension -eq ".ignore" }).Count
Write-Host "numIgnore $numIgnore"
if ($numExe - 1 -ne $numIgnore) {
Write-Error "FAIL: Wrong number of ignored plugins!"
}
if ($numIgnore -ne 0) {
Write-Error "FAIL: There mustn't be any ignored plugins!"
}
"TEST: Uninstall show remove the binary"
. choco uninstall packer
try {
. packer
Write-Error "FAIL: packer binary still found"
} catch {
Write-Host "PASS: packer not found"
}
"TEST: Uninstall should not leave files on disk"
if (Test-Path C:\programdata\chocolatey\lib\packer) {
Write-Error "FAIL: Package directory C:\programdata\chocolatey\lib\packer mustn't exist!"
}
"TEST: Update from older version to single binary version works"
. choco install -y packer $options -version 0.8.6.20160211
. choco install -y packer $options -source . -version $version
. ls C:\programdata\chocolatey\lib\packer
. ls C:\programdata\chocolatey\lib\packer\tools
$numExe = (get-childitem -path C:\programdata\chocolatey\lib\packer\tools\ | where { $_.extension -eq ".exe" }).Count
Write-Host "numExe $numExe"
$numIgnore = (get-childitem -path C:\programdata\chocolatey\lib\packer\tools\ | where { $_.extension -eq ".ignore" }).Count
Write-Host "numIgnore $numIgnore"
if ($numExe - 1 -ne $numIgnore) {
Write-Error "FAIL: Wrong number of ignored plugins!"
}
if ($numExe -ne 1) {
Write-Error "FAIL: There mustn't be more than one exe file!"
}
if ($numIgnore -ne 0) {
Write-Error "FAIL: There mustn't be any ignored plugins!"
}
"TEST: Uninstall show remove the binary"
. choco uninstall packer
try {
. packer
Write-Error "FAIL: packer binary still found"
} catch {
Write-Host "PASS: packer not found"
}
"TEST: Finished"