forked from MPCatalog/scom-community-catalog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Index.json.tests.ps1
81 lines (63 loc) · 2.52 KB
/
Index.json.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
<#
.SYNOPSIS
Test file for Pester that will verify that the index.json file is in a valid state and meet all defined guidelines. Pull requests that have failing tests are unlikely to be accepted.
#>
[CmdletBinding()]
Param()
$location = Split-Path $script:MyInvocation.MyCommand.Path
$indexFileName = "Index.json"
Describe "Index.json" -Tag $location {
$path = Join-Path $location $indexFileName
$contents = Get-Content $path -Raw -ErrorAction SilentlyContinue
$json = ConvertFrom-Json $contents -ErrorAction SilentlyContinue
Context 'File Validity' {
It 'Exists' {
$path | Should Exist
}
It 'Has content' {
$contents | Should Not BeNullOrEmpty
}
It 'Contains valid JSON' {
{ConvertFrom-Json $contents} | Should Not Throw
}
}
Context 'Structural Validity' {
It 'Is a valid array' {
# Explicitly wrap to stop PowerShell from unwrapping during pipeline
@(,$json) | Should BeOfType System.Array
}
It 'Contains objects with a ManagementPackSystemName' {
foreach ($pack in $json) {
$pack.ManagementPackSystemName | Should Not BeNullOrEmpty
}
}
It 'Is alphabetically sorted and unique' {
$sortedJson = $json | Sort-Object -Property ManagementPackSystemName -Unique
for ($i = 0; $i -lt $json.Count; $i++) {
$json[$i].ManagementPackSystemName | Should Be $sortedJson[$i].ManagementPackSystemName
}
}
}
Context 'Content Validity' {
foreach ($pack in $json) {
$name = $pack.ManagementPackSystemName
It "Pack $name has valid ManagementPackSystemName" {
$pack.ManagementPackSystemName | Should Match '^[A-Za-z_][A-Za-z0-9_\.]{0,255}$'
}
It "Pack $name matches folder name" {
$path = Join-Path $pwd $name
$path | Should Exist
}
It "Pack $name has valid IsActive" {
$isActive = $null
# Treat as true if not specified, as the catalog does
if (($pack.PSObject.Properties | Select-Object -ExpandProperty Name) -notcontains 'IsActive') {
$isActive = $true
} else {
$isActive = $pack.IsActive
}
$isActive | Should BeOfType System.Boolean
}
}
}
}