Skip to content

Commit 3ef3f1c

Browse files
committed
Fix tests and add more
1 parent 357c04f commit 3ef3f1c

66 files changed

Lines changed: 416 additions & 123 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/CI.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
name: CI
2-
#on: [push, pull_request]
2+
33
on:
4+
push:
5+
pull_request:
46
workflow_dispatch:
7+
58
jobs:
69
test:
710
name: Run Tests

.github/workflows/test.yaml

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,18 @@
1-
# No content - module is "compiled" during build and all functions are copied here at that time.
1+
# Only dot-source files at development time. At build time, all classes and functions are embedded in the PSM1 file.
2+
if (Get-ChildItem $PSScriptRoot\Classes\*.ps1 -ErrorAction SilentlyContinue) {
3+
[object[]]$classes = Get-ChildItem $PSScriptRoot\Classes\*.ps1
4+
[object[]]$private = Get-ChildItem $PSScriptRoot\Private\*.ps1
5+
[object[]]$public = Get-ChildItem $PSScriptRoot\Public\*.ps1
6+
$classes, $private, $public | ForEach-Object {
7+
$_ | ForEach-Object {
8+
$file = $_
9+
try {
10+
. $file
11+
} catch {
12+
Write-Warning "Failed to dot-source $($file.FullName): $_"
13+
throw
14+
}
15+
}
16+
}
17+
Export-ModuleMember -Function $public.BaseName
18+
}

MilestoneSystems.PowerShell.MediaDB/Public/Open-MediaDatabase.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ function Open-MediaDatabase {
5454
"file:\$DatabasePath"
5555
)
5656
} catch {
57-
Close-MediaDatabase -LiteralPath $DatabasePath
57+
# Must remove all servers - removing just the one that failed to open will throw UriFormatException
58+
[videoos.platform.sdk.environment]::RemoveAllServers()
5859
throw
5960
}
6061
}

psakeFile.ps1

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ properties {
77

88
$psake.context.tasks.stagefiles.PostAction = {
99
$outputManifestPath = [io.path]::Combine($PSBPreference.Build.ModuleOutDir, "$($PSBPreference.General.ModuleName).psd1")
10-
Write-Host "Updating ModuleVersion in output manifest '$outputManifestPath' to NBGV-based version $($PSBPreference.General.ModuleVersion)"
11-
BuildHelpers\Update-Metadata -Path $outputManifestPath -Property ModuleVersion -Value $PSBPreference.General.ModuleVersion
12-
#$content = Get-Content $outputManifestPath | ForEach-Object { $_ -replace "'0.1.0'", "'$($PSBPreference.General.ModuleVersion)'" }
13-
#$content | Set-Content $outputManifestPath -Encoding UTF8
10+
Write-Verbose "Updating ModuleVersion in output manifest '$outputManifestPath' to NBGV-based version $($PSBPreference.General.ModuleVersion)"
11+
12+
if (Get-Module MilestonePSTools) {
13+
# Unload the MilestonePSTools module due to conflicting Get-Metadata command
14+
Remove-Module MilestonePSTools -Force
15+
}
16+
17+
Update-Metadata -Path $outputManifestPath -Value $PSBPreference.General.ModuleVersion
1418

1519
Write-Verbose "Converting root module to UTF8 since PowerShellBuild generates a Unicode file on Windows PowerShell"
1620
Import-Module (Join-Path $env:BHProjectPath 'tests/MetaFixers.psm1')

tests/Export-Mdb.tests.ps1

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Context "Export-Mdb" {
2+
BeforeAll {
3+
$script:EncryptedDbPath = [io.path]::Combine($PSScriptRoot, 'data', 'EncryptedExport', 'cache.xml')
4+
$script:UnencryptedDbPath = [io.path]::Combine($PSScriptRoot, 'data', 'UnencryptedExport', 'cache.xml')
5+
}
6+
7+
AfterEach {
8+
Close-MediaDatabase
9+
}
10+
11+
It "Can export from encrypted database" {
12+
$password = 'rzxW&s3Ftw' | ConvertTo-SecureString -AsPlainText -Force
13+
Open-MediaDatabase -Path $script:EncryptedDbPath -Password $password
14+
15+
$folder = Get-MdbCamera | Get-MdbSequence -Type RecordingSequence | ForEach-Object {
16+
$item = [videoos.platform.configuration]::Instance.GetItem($_.FQID)
17+
$path = 'TestDrive:\{0}_{1}_Database' -f $_.Source, $_.Start.ToString('yyyy-MM-dd_HH-mm-ss')
18+
$exportParams = @{
19+
Device = $item
20+
Start = $_.Start
21+
End = $_.End
22+
Path = $path
23+
}
24+
Export-Mdb @exportParams
25+
}
26+
$folder | Should -Not -BeNullOrEmpty
27+
(Test-Path $folder -PathType Container) | Should -Be $true
28+
}
29+
}

tests/Export-MdbMkv.tests.ps1

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Context "Export-MdbMkv" {
2+
BeforeAll {
3+
$script:EncryptedDbPath = [io.path]::Combine($PSScriptRoot, 'data', 'EncryptedExport', 'cache.xml')
4+
$script:UnencryptedDbPath = [io.path]::Combine($PSScriptRoot, 'data', 'UnencryptedExport', 'cache.xml')
5+
}
6+
7+
AfterEach {
8+
Close-MediaDatabase
9+
}
10+
11+
It "Can export from encrypted database" {
12+
$password = 'rzxW&s3Ftw' | ConvertTo-SecureString -AsPlainText -Force
13+
Open-MediaDatabase -Path $script:EncryptedDbPath -Password $password
14+
15+
$mkvFile = Get-MdbCamera | Get-MdbSequence -Type RecordingSequence | ForEach-Object {
16+
$item = [videoos.platform.configuration]::Instance.GetItem($_.FQID)
17+
$path = 'TestDrive:\{0}_{1}.mkv' -f $_.Source, $_.Start.ToString('yyyy-MM-dd_HH-mm-ss')
18+
$exportParams = @{
19+
Device = $item
20+
Start = $_.Start
21+
End = $_.End
22+
Path = $path
23+
}
24+
Export-MdbMkv @exportParams
25+
}
26+
$mkvFile | Should -Not -BeNullOrEmpty
27+
}
28+
}

tests/Open-MediaDatabase.tests.ps1

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Context "Open-MediaDatabase" {
2+
BeforeAll {
3+
$script:EncryptedDbPath = [io.path]::Combine($PSScriptRoot, 'data', 'EncryptedExport', 'cache.xml')
4+
$script:UnencryptedDbPath = [io.path]::Combine($PSScriptRoot, 'data', 'UnencryptedExport', 'cache.xml')
5+
}
6+
7+
AfterEach {
8+
Close-MediaDatabase
9+
}
10+
11+
It "Can open encrypted database" {
12+
$password = 'rzxW&s3Ftw' | ConvertTo-SecureString -AsPlainText -Force
13+
Open-MediaDatabase -Path $script:EncryptedDbPath -Password $password
14+
$cameras = Get-MdbCamera
15+
$cameras.Count | Should -BeExactly 2
16+
}
17+
18+
It "Can open unencrypted database" {
19+
Open-MediaDatabase -Path $script:UnencryptedDbPath
20+
$cameras = Get-MdbCamera
21+
$cameras.Count | Should -BeExactly 2
22+
}
23+
24+
It "Throws expected error with incorrect password" {
25+
try {
26+
$password = 'wrong-password' | ConvertTo-SecureString -AsPlainText -Force
27+
Open-MediaDatabase -Path $script:EncryptedDbPath -Password $password
28+
} catch {
29+
$exception = $_.Exception.InnerException
30+
}
31+
$exception | Should -BeOfType ([VideoOS.Platform.NotAuthorizedMIPException])
32+
}
33+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
2+
<BookmarkExport version="1.0" deviceid="e227d322-9fba-426a-92bc-7e05290eda00" begintime="2025-02-27T21:37:56.6135067Z" endtime="2025-02-27T21:38:57.4488977Z">
3+
<Bookmarks />
4+
</BookmarkExport>
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<bank version="1.2">
3-
<description>Shoe Store</description>
4-
<encryption>
5-
<algorithm>AES</algorithm>
6-
<size_to_encrypt>0</size_to_encrypt>
7-
<password_selection>1</password_selection>
8-
</encryption>
9-
<meta_data>
10-
<entry key="device_type">Camera</entry>
11-
</meta_data>
12-
</bank>
1+
<?xml version="1.0" encoding="UTF-8" standalone="no" ?> <bank version="1.2">
2+
<description>Shoe Store</description>
3+
<encryption>
4+
<algorithm>AES</algorithm>
5+
<size_to_encrypt>0</size_to_encrypt>
6+
<password_selection>1</password_selection>
7+
</encryption>
8+
<meta_data>
9+
<entry key="device_type">Camera</entry>
10+
</meta_data>
11+
</bank>

0 commit comments

Comments
 (0)