forked from ScoopInstaller/Scoop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScoop-Manifest.Tests.ps1
87 lines (77 loc) · 3.59 KB
/
Scoop-Manifest.Tests.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
. "$psscriptroot\Scoop-TestLib.ps1"
. "$psscriptroot\..\lib\core.ps1"
. "$psscriptroot\..\lib\manifest.ps1"
describe "manifest-validation" {
beforeall {
$working_dir = setup_working "manifest"
$schema = "$psscriptroot/../schema.json"
Add-Type -Path "$psscriptroot\..\supporting\validator\Newtonsoft.Json.dll"
Add-Type -Path "$psscriptroot\..\supporting\validator\Newtonsoft.Json.Schema.dll"
Add-Type -Path "$psscriptroot\..\supporting\validator\Scoop.Validator.dll"
}
it "Scoop.Validator is available" {
([System.Management.Automation.PSTypeName]'Scoop.Validator').Type | should be 'Scoop.Validator'
}
context "parse_json function" {
it "fails with invalid json" {
{ parse_json "$working_dir\broken_wget.json" } | should throw
}
}
context "schema validation" {
it "fails with broken schema" {
$validator = new-object Scoop.Validator("$working_dir/broken_schema.json", $true)
$validator.Validate("$working_dir/wget.json") | should be $false
$validator.Errors.Count | should be 1
$validator.Errors | select-object -First 1 | should match "broken_schema.*(line 6).*(position 4)"
}
it "fails with broken manifest" {
$validator = new-object Scoop.Validator($schema, $true)
$validator.Validate("$working_dir/broken_wget.json") | should be $false
$validator.Errors.Count | should be 1
$validator.Errors | select-object -First 1 | should match "broken_wget.*(line 5).*(position 4)"
}
it "fails with invalid manifest" {
$validator = new-object Scoop.Validator($schema, $true)
$validator.Validate("$working_dir/invalid_wget.json") | should be $false
$validator.Errors.Count | should be 16
$validator.Errors | select-object -First 1 | should match "invalid_wget.*randomproperty.*properties\.$"
$validator.Errors | select-object -Last 1 | should match "invalid_wget.*version\.$"
}
}
context "manifest validates against the schema" {
beforeall {
$bucketdir = "$psscriptroot\..\bucket\"
$manifest_files = gci $bucketdir *.json
$validator = new-object Scoop.Validator($schema, $true)
}
$global:quota_exceeded = $false
$manifest_files | % {
it "$_" {
$file = $_ # exception handling may overwrite $_
if(!($global:quota_exceeded)) {
try {
$validator.Validate($file.fullname)
if ($validator.Errors.Count -gt 0) {
write-host -f yellow $validator.ErrorsAsString
}
$validator.Errors.Count | should be 0
} catch {
if($_.exception.message -like '*The free-quota limit of 1000 schema validations per hour has been reached.*') {
$global:quota_exceeded = $true
write-host -f darkyellow 'Schema validation limit exceeded. Will skip further validations.'
} else {
throw
}
}
}
$manifest = parse_json $file.fullname
$url = arch_specific "url" $manifest "32bit"
$url64 = arch_specific "url" $manifest "64bit"
if(!$url) {
$url = $url64
}
$url | should not benullorempty
}
}
}
}