Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.packed/
.work/
/TEST-pesterResults.xml
2 changes: 1 addition & 1 deletion Run-Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ $pesterConfig.Run.Exit = $True
$pesterConfig.Run.Path = "$PSScriptRoot/tests"
$pesterConfig.TestResult.Enabled = $True
$pesterConfig.TestResult.OutputFormat = 'NUnit3'
$pesterConfig.TestResult.OutputPath = '$PSScriptRoot/TEST-pesterResults.xml'
$pesterConfig.TestResult.OutputPath = "$PSScriptRoot/TEST-pesterResults.xml"
Invoke-Pester -Configuration $pesterConfig
4 changes: 4 additions & 0 deletions tests/Helpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ function New-CatletName {
"clt$(Get-Date -Format 'yyMMddHHmmss')"
}

function New-CatletSpecificationName {
"spc$(Get-Date -Format 'yyMMddHHmmss')"
}

function Setup-Gene {
param(
[Parameter(Mandatory = $true)]
Expand Down
135 changes: 135 additions & 0 deletions tests/catlets/Deploy-Catlet.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#Requires -Version 7.4
#Requires -Module Pester
#Requires -Module Assert
BeforeAll {
. $PSScriptRoot/../../Use-Settings.ps1
. $PSScriptRoot/../Helpers.ps1
Setup-GenePool
}

Describe "Catlets" {

BeforeEach {
$project = New-TestProject
$specificationName = New-CatletSpecificationName
}

Context "Deploy-Catlet" {

It "Deploys properly configured catlet without parent" {
$config = @"
name: $specificationName
cpu:
count: 3
memory:
startup: 1024
minimum: 256
maximum: 2048
drives:
- name: sda
size: 50
networks:
- name: default
adapter_name: public
network_adapters:
- name: public
"@
$specification = New-CatletSpecification -Comment 'first version' -ProjectName $project.Name -Config $config

Deploy-Catlet -SpecificationId $specification.Id -SpecificationVersionId $specification.Latest.Id

$vm = Get-VM -Name $specificationName

$vm.ProcessorCount | Should -BeExactly 3

$vm.DynamicMemoryEnabled | Should -BeTrue
$vm.MemoryStartup | Should -BeExactly 1024MB
$vm.MemoryMinimum | Should -BeExactly 256MB
$vm.MemoryMaximum | Should -BeExactly 2048MB

$vm.HardDrives | Should -HaveCount 1
$vm.HardDrives[0].Path | Should -BeLike "*\p_$($project.Name)\*\sda.vhdx"
$vhd = Get-VHD -Path $vm.HardDrives[0].Path
$vhd.Size | Should -BeExactly 50GB

$vm.NetworkAdapters | Should -HaveCount 1
$vm.NetworkAdapters[0].Name | Should -BeExactly 'public'
$vm.NetworkAdapters[0].SwitchName | Should -BeExactly 'eryph_overlay'
}

It "Deploys catlet with parameterized fodder" {
$config = @"
name: $specificationName
parent: dbosoft/e2etests-os/base
variables:
- name: userName
fodder:
- name: add-user-greeting
type: shellscript
content: |
#!/bin/bash
echo 'Hello {{ userName }}!' >> hello-world.txt
- name: write-vm-id
type: shellscript
content: |
#!/bin/bash
echo '{{ vmId }}' >> hyperv-vm-id.txt
"@

$specification = New-CatletSpecification -Comment 'first version' -ProjectName $project.Name -Config $config

$catlet = Deploy-Catlet -SpecificationId $specification.Id -SpecificationVersionId $specification.Latest.Id -Variables @{ username = "Eve E2E" }

$catlet = Get-Catlet -Id $catlet.Id
$catlet.Project.Id | Should -Be $project.Id
$catlet.Name | Should -Be $specificationName
$catlet.Specification.SpecificationId | Should -Be $specification.Id
$catlet.Specification.SpecificationVersionId | Should -be $specification.Latest.Id

$specification = Get-CatletSpecification -Id $specification.Id
$specification.CatletId | Should -Be $catlet.Id

$sshSession = Connect-Catlet -CatletId $catlet.Id -WaitForCloudInit
$helloWorldResponse = Invoke-SSHCommand -Command "cat /hello-world.txt" -SSHSession $sshSession
$helloWorldResponse.Output | Should -Be "Hello Eve E2E!"

$vm = Get-VM -Name $specificationName
$vmIdResponse = Invoke-SSHCommand -Command "cat /hyperv-vm-id.txt" -SSHSession $sshSession
$vmIdResponse.Output | Should -Be $vm.Id
}

It "Redeploys existing catlet" {
$config = @"
name: $specificationName
parent: dbosoft/e2etests-os/base
"@

$specification = New-CatletSpecification -Comment 'first version' -ProjectName $project.Name -Config $config

$firstCatlet = Deploy-Catlet -SpecificationId $specification.Id -SpecificationVersionId $specification.Latest.Id -Variables @{ username = "Eve E2E" }

$firstCatlet.Specification.SpecificationId | Should -Be $specification.Id
$firstCatlet.Specification.SpecificationVersionId | Should -be $specification.Latest.Id

$specification = Get-CatletSpecification -Id $specification.Id
$specification.CatletId | Should -Be $firstCatlet.Id

$secondCatlet = Deploy-Catlet -SpecificationId $specification.Id -SpecificationVersionId $specification.Latest.Id -Redeploy -Force

$secondCatlet.Specification.SpecificationId | Should -Be $specification.Id
$secondCatlet.Specification.SpecificationVersionId | Should -be $specification.Latest.Id

$secondcatlet.Id | Should -Not -Be $firstCatlet.Id

$specification = Get-CatletSpecification -Id $specification.Id
$specification.CatletId | Should -Be $secondCatlet.Id

$catlets = Get-Catlet -ProjectName $project.Name
$catlets | Should -HaveCount 1
}
}

AfterEach {
Remove-EryphProject -Id $project.Id -Force
}
}
86 changes: 86 additions & 0 deletions tests/catletspecifications/New-CatletSpecification.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#Requires -Version 7.4
#Requires -Module Pester
#Requires -Module Assert
BeforeAll {
. $PSScriptRoot/../../Use-Settings.ps1
. $PSScriptRoot/../Helpers.ps1
Setup-GenePool
}

Describe "Catlet-Specifications" {

BeforeEach {
$project = New-TestProject
$specificationName = New-CatletSpecificationName
}

Context "New-CatletSpecification" {
It "Creates catlet specification with JSON config" {
$config = @"
{
"name": "$specificationName",
"parent": "dbosoft/e2etests-os/base",
"variables": [
{
"name": "userName"
}
],
"fodder": [
{
"source": "gene:dbosoft/e2etests-fodder:greet-solar-system"
}
]
}
"@

$specification = New-CatletSpecification -Comment 'first version' -ProjectName $project.Name -Config $config
$versions = Get-CatletSpecificationVersion -SpecificationId $specification.Id
$versions | Should -HaveCount 1
$latestVersion = Get-CatletSpecificationVersion -SpecificationId $specification.Id -Id $versions[0].Id
$latestVersion.Comment | Should -Be 'first version'
$latestVersion.Configuration.ContentType | Should -Be 'application/yaml'
$latestVersion.Configuration.Content | Should -be $config.ReplaceLineEndings("`n")
$latestVersion.Variants | Should -HaveCount 1
$latestVersion.Variants[0].Architecture | Should -Be 'hyperv/amd64'
$latestVersion.Variants[0].PinnedGenes | Should -HaveCount 3
$latestVersion.Variants[0].PinnedGenes[0].GeneSet | Should -Be 'dbosoft/e2etests-os/base-0.1'
$latestVersion.Variants[0].PinnedGenes[0].Name | Should -Be 'catlet'
$latestVersion.Variants[0].PinnedGenes[1].GeneSet | Should -Be 'dbosoft/ubuntu-24.04/20250913'
$latestVersion.Variants[0].PinnedGenes[1].Name | Should -Be 'sda'
$latestVersion.Variants[0].PinnedGenes[2].GeneSet | Should -Be 'dbosoft/e2etests-fodder/0.1'
$latestVersion.Variants[0].PinnedGenes[2].Name | Should -Be 'greet-solar-system'
}

It "Creates catlet specification with YAML config" {
$config = @"
name: $specificationName
parent: dbosoft/e2etests-os/base
variables:
- name: userName
fodder:
- source: gene:dbosoft/e2etests-fodder:greet-solar-system
"@

$specification = New-CatletSpecification -Comment 'first version' -ProjectName $project.Name -Config $config
$versions = Get-CatletSpecificationVersion -SpecificationId $specification.Id
$versions | Should -HaveCount 1
$latestVersion = Get-CatletSpecificationVersion -SpecificationId $specification.Id -Id $versions[0].Id
$latestVersion.Comment | Should -Be 'first version'
$latestVersion.Configuration.ContentType | Should -Be 'application/yaml'
$latestVersion.Configuration.Content | Should -be $config.ReplaceLineEndings("`n")
$latestVersion.Variants | Should -HaveCount 1
$latestVersion.Variants[0].Architecture | Should -Be 'hyperv/amd64'
$latestVersion.Variants[0].PinnedGenes | Should -HaveCount 3
$latestVersion.Variants[0].PinnedGenes[0].GeneSet | Should -Be 'dbosoft/e2etests-os/base-0.1'
$latestVersion.Variants[0].PinnedGenes[0].Name | Should -Be 'catlet'
$latestVersion.Variants[0].PinnedGenes[1].GeneSet | Should -Be 'dbosoft/ubuntu-24.04/20250913'
$latestVersion.Variants[0].PinnedGenes[1].Name | Should -Be 'sda'
$latestVersion.Variants[0].PinnedGenes[2].GeneSet | Should -Be 'dbosoft/e2etests-fodder/0.1'
$latestVersion.Variants[0].PinnedGenes[2].Name | Should -Be 'greet-solar-system'
}
}

AfterEach {
Remove-EryphProject -Id $project.Id -Force
}
}
70 changes: 70 additions & 0 deletions tests/catletspecifications/Remove-CatletSpecification.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#Requires -Version 7.4
#Requires -Module Pester
#Requires -Module Assert
BeforeAll {
. $PSScriptRoot/../../Use-Settings.ps1
. $PSScriptRoot/../Helpers.ps1
Setup-GenePool
}

Describe "Catlet-Specifications" {

BeforeEach {
$project = New-TestProject
$specificationName = New-CatletSpecificationName
}

Context "Remove-CatletSpecification" {

It "Removes catlet specification which is not deployed" {
$config = @"
name: $specificationName
"@

$specification = New-CatletSpecification -Comment 'first version' -ProjectName $project.Name -Config $config
$versions = Get-CatletSpecificationVersion -SpecificationId $specification.Id
$versions | Should -HaveCount 1

Remove-CatletSpecification -Id $specification.Id -Force
$specifications = Get-CatletSpecification -ProjectName $project.Name
$specifications | Should -HaveCount 0
}

It "Removes catlet specification which is deployed" {
$config = @"
name: $specificationName
"@

$specification = New-CatletSpecification -Comment 'first version' -ProjectName $project.Name -Config $config
$versions = Get-CatletSpecificationVersion -SpecificationId $specification.Id
$versions | Should -HaveCount 1

Deploy-Catlet -SpecificationId $specification.Id -SpecificationVersionId $specification.Latest.Id

Remove-CatletSpecification -Id $specification.Id -RemoveCatlet -Force
$specifications = Get-CatletSpecification -ProjectName $project.Name
$specifications | Should -HaveCount 0
}

It "Does not remove catlet specification which is deployed" {
$config = @"
name: $specificationName
"@

$specification = New-CatletSpecification -Comment 'first version' -ProjectName $project.Name -Config $config
$versions = Get-CatletSpecificationVersion -SpecificationId $specification.Id
$versions | Should -HaveCount 1

Deploy-Catlet -SpecificationId $specification.Id -SpecificationVersionId $specification.Latest.Id

{ Remove-CatletSpecification -Id $specification.Id -Force } | Should -Throw '*The catlet specification is deployed as a catlet.*'
$specifications = Get-CatletSpecification -ProjectName $project.Name
$specifications | Should -HaveCount 1
$specifications[0].Id | Should -Be $specification.Id
}
}

AfterEach {
Remove-EryphProject -Id $project.Id -Force
}
}
Loading
Loading