|
1 |
| -param($bucketdir = "$psscriptroot\..\bucket\") |
2 |
| -. "$psscriptroot\Scoop-TestLib.ps1" |
3 |
| -. "$psscriptroot\..\lib\core.ps1" |
4 |
| -. "$psscriptroot\..\lib\manifest.ps1" |
| 1 | +param($bucketdir = "$PSScriptRoot\..\bucket") |
| 2 | +. "$PSScriptRoot\Scoop-TestLib.ps1" |
| 3 | +. "$PSScriptRoot\..\lib\core.ps1" |
| 4 | +. "$PSScriptRoot\..\lib\manifest.ps1" |
5 | 5 |
|
6 |
| -Describe -Tag 'Manifests' 'manifest-validation' { |
| 6 | +Describe 'Manifest Validator' -Tag 'Validator' { |
7 | 7 | BeforeAll {
|
8 | 8 | $working_dir = setup_working 'manifest'
|
9 |
| - $schema = "$psscriptroot/../schema.json" |
10 |
| - Add-Type -Path "$psscriptroot\..\supporting\validator\bin\Newtonsoft.Json.dll" |
11 |
| - Add-Type -Path "$psscriptroot\..\supporting\validator\bin\Newtonsoft.Json.Schema.dll" |
12 |
| - Add-Type -Path "$psscriptroot\..\supporting\validator\bin\Scoop.Validator.dll" |
| 9 | + $schema = "$PSScriptRoot/../schema.json" |
| 10 | + Add-Type -Path "$PSScriptRoot\..\supporting\validator\bin\Newtonsoft.Json.dll" |
| 11 | + Add-Type -Path "$PSScriptRoot\..\supporting\validator\bin\Newtonsoft.Json.Schema.dll" |
| 12 | + Add-Type -Path "$PSScriptRoot\..\supporting\validator\bin\Scoop.Validator.dll" |
13 | 13 | }
|
14 | 14 |
|
15 | 15 | It 'Scoop.Validator is available' {
|
@@ -43,58 +43,55 @@ Describe -Tag 'Manifests' 'manifest-validation' {
|
43 | 43 | $validator.Errors | Select-Object -Last 1 | Should -Match 'Required properties are missing from object: version, description\.'
|
44 | 44 | }
|
45 | 45 | }
|
| 46 | +} |
46 | 47 |
|
47 |
| - Context 'manifest validates against the schema' { |
48 |
| - BeforeAll { |
49 |
| - if ($null -eq $bucketdir) { |
50 |
| - $bucketdir = "$psscriptroot\..\bucket\" |
51 |
| - } |
52 |
| - $changed_manifests = @() |
53 |
| - if ($env:CI -eq $true) { |
54 |
| - $commit = if ($env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT) { $env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT } else { $env:APPVEYOR_REPO_COMMIT } |
55 |
| - $changed_manifests = (Get-GitChangedFile -Include '*.json' -Commit $commit) |
56 |
| - } |
57 |
| - $manifest_files = Get-ChildItem $bucketdir *.json |
58 |
| - $validator = New-Object Scoop.Validator($schema, $true) |
| 48 | +Describe 'manifest validates against the schema' -Tag 'Manifests' { |
| 49 | + BeforeAll { |
| 50 | + $changed_manifests = @() |
| 51 | + if ($env:CI -eq $true) { |
| 52 | + $commit = if ($env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT) { $env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT } else { $env:APPVEYOR_REPO_COMMIT } |
| 53 | + $changed_manifests = (Get-GitChangedFile -Include 'bucket\*.json' -Commit $commit) |
59 | 54 | }
|
| 55 | + $manifest_files = Get-ChildItem $bucketdir *.json |
| 56 | + $validator = New-Object Scoop.Validator($schema, $true) |
| 57 | + } |
60 | 58 |
|
61 |
| - $quota_exceeded = $false |
| 59 | + $quota_exceeded = $false |
62 | 60 |
|
63 |
| - $manifest_files | ForEach-Object { |
64 |
| - $skip_manifest = ($changed_manifests -inotcontains $_.FullName) |
65 |
| - if ($env:CI -ne $true -or $changed_manifests -imatch 'schema.json') { |
66 |
| - $skip_manifest = $false |
67 |
| - } |
68 |
| - It "$_" -Skip:$skip_manifest { |
69 |
| - $file = $_ # exception handling may overwrite $_ |
| 61 | + $manifest_files | ForEach-Object { |
| 62 | + $skip_manifest = ($changed_manifests -inotcontains $_.FullName) |
| 63 | + if ($env:CI -ne $true -or $changed_manifests -imatch 'schema.json') { |
| 64 | + $skip_manifest = $false |
| 65 | + } |
| 66 | + It "$_" -Skip:$skip_manifest { |
| 67 | + $file = $_ # exception handling may overwrite $_ |
70 | 68 |
|
71 |
| - if (!($quota_exceeded)) { |
72 |
| - try { |
73 |
| - $validator.Validate($file.fullname) |
| 69 | + if (!($quota_exceeded)) { |
| 70 | + try { |
| 71 | + $validator.Validate($file.fullname) |
74 | 72 |
|
75 |
| - if ($validator.Errors.Count -gt 0) { |
76 |
| - Write-Host -f red " [-] $_ has $($validator.Errors.Count) Error$(If($validator.Errors.Count -gt 1) { 's' })!" |
77 |
| - Write-Host -f yellow $validator.ErrorsAsString |
78 |
| - } |
79 |
| - $validator.Errors.Count | Should -Be 0 |
80 |
| - } catch { |
81 |
| - if ($_.exception.message -like '*The free-quota limit of 1000 schema validations per hour has been reached.*') { |
82 |
| - $quota_exceeded = $true |
83 |
| - Write-Host -f darkyellow 'Schema validation limit exceeded. Will skip further validations.' |
84 |
| - } else { |
85 |
| - throw |
86 |
| - } |
| 73 | + if ($validator.Errors.Count -gt 0) { |
| 74 | + Write-Host -f red " [-] $_ has $($validator.Errors.Count) Error$(If($validator.Errors.Count -gt 1) { 's' })!" |
| 75 | + Write-Host -f yellow $validator.ErrorsAsString |
| 76 | + } |
| 77 | + $validator.Errors.Count | Should -Be 0 |
| 78 | + } catch { |
| 79 | + if ($_.exception.message -like '*The free-quota limit of 1000 schema validations per hour has been reached.*') { |
| 80 | + $quota_exceeded = $true |
| 81 | + Write-Host -f darkyellow 'Schema validation limit exceeded. Will skip further validations.' |
| 82 | + } else { |
| 83 | + throw |
87 | 84 | }
|
88 | 85 | }
|
| 86 | + } |
89 | 87 |
|
90 |
| - $manifest = parse_json $file.fullname |
91 |
| - $url = arch_specific 'url' $manifest '32bit' |
92 |
| - $url64 = arch_specific 'url' $manifest '64bit' |
93 |
| - if (!$url) { |
94 |
| - $url = $url64 |
95 |
| - } |
96 |
| - $url | Should -Not -BeNullOrEmpty |
| 88 | + $manifest = parse_json $file.fullname |
| 89 | + $url = arch_specific 'url' $manifest '32bit' |
| 90 | + $url64 = arch_specific 'url' $manifest '64bit' |
| 91 | + if (!$url) { |
| 92 | + $url = $url64 |
97 | 93 | }
|
| 94 | + $url | Should -Not -BeNullOrEmpty |
98 | 95 | }
|
99 | 96 | }
|
100 | 97 | }
|
0 commit comments