mirror of
https://github.com/ScoopInstaller/Scoop.git
synced 2025-10-30 06:07:56 +00:00
test(manifest): Fix manifests validation (#4620)
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
### Tests
|
||||
|
||||
- **test-bin:** Only write output file in CI and fix trailing whitespaces ([#4613](https://github.com/ScoopInstaller/Scoop/issues/4613))
|
||||
- **manifest:** Fix manifests validation ([#4620](https://github.com/ScoopInstaller/Scoop/issues/4620))
|
||||
|
||||
### Documentation
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
invoke-pester "$psscriptroot\..\test"
|
||||
. "$PSScriptRoot\..\test\bin\test.ps1"
|
||||
|
||||
@@ -3,9 +3,9 @@ $repo_dir = (Get-Item $MyInvocation.MyCommand.Path).Directory.Parent.FullName
|
||||
$repo_files = @( Get-ChildItem $repo_dir -File -Recurse -Force )
|
||||
|
||||
$project_file_exclusions = @(
|
||||
$([regex]::Escape($repo_dir) + '(\\|/).git(\\|/).*$'),
|
||||
'.sublime-workspace$',
|
||||
'.DS_Store$',
|
||||
'[\\/]\.git[\\/]',
|
||||
'\.sublime-workspace$',
|
||||
'\.DS_Store$',
|
||||
'supporting(\\|/)validator(\\|/)packages(\\|/)*',
|
||||
'supporting(\\|/)shimexe(\\|/)packages(\\|/)*'
|
||||
)
|
||||
|
||||
@@ -1,26 +1,27 @@
|
||||
if ([String]::IsNullOrEmpty($MyInvocation.PSScriptRoot)) {
|
||||
Write-Error 'This script should not be called directly! It has to be imported from a buckets test file!'
|
||||
exit 1
|
||||
}
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]
|
||||
$repo_dir = (Get-Item $MyInvocation.PSScriptRoot).FullName
|
||||
)
|
||||
|
||||
. "$psscriptroot\Scoop-TestLib.ps1"
|
||||
. "$psscriptroot\..\lib\core.ps1"
|
||||
. "$psscriptroot\..\lib\manifest.ps1"
|
||||
. "$psscriptroot\..\lib\unix.ps1"
|
||||
|
||||
$repo_dir = (Get-Item $MyInvocation.PSScriptRoot).FullName
|
||||
|
||||
$repo_files = @(Get-ChildItem $repo_dir -File -Recurse)
|
||||
|
||||
$project_file_exclusions = @(
|
||||
$([regex]::Escape($repo_dir) + '(\\|/).git(\\|/).*$'),
|
||||
'[\\/]\.git[\\/]',
|
||||
'.sublime-workspace$',
|
||||
'.DS_Store$',
|
||||
'supporting(\\|/)validator(\\|/)packages(\\|/)*'
|
||||
'.DS_Store$'
|
||||
)
|
||||
|
||||
$bucketdir = $repo_dir
|
||||
if (Test-Path("$repo_dir\bucket")) {
|
||||
if (Test-Path("$repo_dir\..\bucket")) {
|
||||
$bucketdir = "$repo_dir\..\bucket"
|
||||
} elseif (Test-Path("$repo_dir\bucket")) {
|
||||
$bucketdir = "$repo_dir\bucket"
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
param($bucketdir = "$psscriptroot\..\bucket\")
|
||||
. "$psscriptroot\Scoop-TestLib.ps1"
|
||||
. "$psscriptroot\..\lib\core.ps1"
|
||||
. "$psscriptroot\..\lib\manifest.ps1"
|
||||
param($bucketdir = "$PSScriptRoot\..\bucket")
|
||||
. "$PSScriptRoot\Scoop-TestLib.ps1"
|
||||
. "$PSScriptRoot\..\lib\core.ps1"
|
||||
. "$PSScriptRoot\..\lib\manifest.ps1"
|
||||
|
||||
Describe -Tag 'Manifests' 'manifest-validation' {
|
||||
Describe 'Manifest Validator' -Tag 'Validator' {
|
||||
BeforeAll {
|
||||
$working_dir = setup_working 'manifest'
|
||||
$schema = "$psscriptroot/../schema.json"
|
||||
Add-Type -Path "$psscriptroot\..\supporting\validator\bin\Newtonsoft.Json.dll"
|
||||
Add-Type -Path "$psscriptroot\..\supporting\validator\bin\Newtonsoft.Json.Schema.dll"
|
||||
Add-Type -Path "$psscriptroot\..\supporting\validator\bin\Scoop.Validator.dll"
|
||||
$schema = "$PSScriptRoot/../schema.json"
|
||||
Add-Type -Path "$PSScriptRoot\..\supporting\validator\bin\Newtonsoft.Json.dll"
|
||||
Add-Type -Path "$PSScriptRoot\..\supporting\validator\bin\Newtonsoft.Json.Schema.dll"
|
||||
Add-Type -Path "$PSScriptRoot\..\supporting\validator\bin\Scoop.Validator.dll"
|
||||
}
|
||||
|
||||
It 'Scoop.Validator is available' {
|
||||
@@ -43,16 +43,14 @@ Describe -Tag 'Manifests' 'manifest-validation' {
|
||||
$validator.Errors | Select-Object -Last 1 | Should -Match 'Required properties are missing from object: version, description\.'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Context 'manifest validates against the schema' {
|
||||
Describe 'manifest validates against the schema' -Tag 'Manifests' {
|
||||
BeforeAll {
|
||||
if ($null -eq $bucketdir) {
|
||||
$bucketdir = "$psscriptroot\..\bucket\"
|
||||
}
|
||||
$changed_manifests = @()
|
||||
if ($env:CI -eq $true) {
|
||||
$commit = if ($env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT) { $env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT } else { $env:APPVEYOR_REPO_COMMIT }
|
||||
$changed_manifests = (Get-GitChangedFile -Include '*.json' -Commit $commit)
|
||||
$changed_manifests = (Get-GitChangedFile -Include 'bucket\*.json' -Commit $commit)
|
||||
}
|
||||
$manifest_files = Get-ChildItem $bucketdir *.json
|
||||
$validator = New-Object Scoop.Validator($schema, $true)
|
||||
@@ -96,5 +94,4 @@ Describe -Tag 'Manifests' 'manifest-validation' {
|
||||
$url | Should -Not -BeNullOrEmpty
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,15 +51,20 @@ if ($env:CI -eq $true) {
|
||||
$excludes += 'Manifests'
|
||||
}
|
||||
|
||||
$changed_manifests = (Get-GitChangedFile -Include '*.json' -Commit $commit)
|
||||
$changed_manifests = (Get-GitChangedFile -Include 'bucket\*.json' -Commit $commit)
|
||||
if (!$changed_manifests) {
|
||||
Write-Warning "Skipping tests and validation for manifest files because they didn't change"
|
||||
$excludes += 'Manifests'
|
||||
}
|
||||
}
|
||||
|
||||
if ($excludes.Length -gt 0) {
|
||||
if (!(Test-Path "$PSScriptRoot\..\..\bucket")) {
|
||||
Write-Warning 'Skipping tests and validation for manifest files because there is no bucket'
|
||||
$excludes += 'Manifests'
|
||||
}
|
||||
|
||||
if ($excludes.Length -gt 0) {
|
||||
$splat.ExcludeTag = $excludes
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host 'Invoke-Pester' @splat
|
||||
|
||||
Reference in New Issue
Block a user