Skip to content
Merged
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
77 changes: 77 additions & 0 deletions test/powershell/dsc/dsc.profileresource.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

Describe "DSC PowerShell Profile Resource Tests" -Tag "CI" {
BeforeAll {

$isMsix = $pshome -like '*WindowsApps*'
if ($isMsix) {
Write-Verbose "Running in MSIX context. Marking tests as pending." -Verbose
return
}

$DSC_ROOT = $env:DSC_ROOT
$skipCleanup = $false

Expand Down Expand Up @@ -46,6 +53,10 @@ Describe "DSC PowerShell Profile Resource Tests" -Tag "CI" {
return
}

if ($isMsix) {
return
}

# Restore original profile
$testProfilePathCurrentUserCurrentHost = $PROFILE.CurrentUserCurrentHost
if (Test-Path "$TestDrive/currentuser-currenthost-profile.bak") {
Expand All @@ -69,6 +80,12 @@ Describe "DSC PowerShell Profile Resource Tests" -Tag "CI" {
}

It 'DSC resource is located at $PSHome' {

if ($isMsix) {
Set-ItResult -Pending -Because "Running in MSIX context. Skipping test."
return
}

$resourceFile = Join-Path -Path $PSHome -ChildPath 'pwsh.profile.resource.ps1'
$resourceFile | Should -Exist

Expand All @@ -77,16 +94,31 @@ Describe "DSC PowerShell Profile Resource Tests" -Tag "CI" {
}

It 'DSC resource can be found' {
if ($isMsix) {
Set-ItResult -Pending -Because "Running in MSIX context. Skipping test."
return
}

(& $dscExe resource list -o json | ConvertFrom-Json | Select-Object -Property type).type | Should -Contain 'Microsoft.PowerShell/Profile'
}

It 'DSC resource can set current user current host profile' {
if ($isMsix) {
Set-ItResult -Pending -Because "Running in MSIX context. Skipping test."
return
}

$setOutput = (& $dscExe config set --file $PSScriptRoot/psprofile_currentuser_currenthost.dsc.yaml -o json) | ConvertFrom-Json
$expectedContent = "Write-Host 'Welcome to your PowerShell profile - CurrentUserCurrentHost!'"
$setOutput.results.result.afterState.content | Should -BeExactly $expectedContent
}

It 'DSC resource can get current user current host profile' {
if ($isMsix) {
Set-ItResult -Pending -Because "Running in MSIX context. Skipping test."
return
}

$getOutput = (& $dscExe config get --file $PSScriptRoot/psprofile_currentuser_currenthost.dsc.yaml -o json) | ConvertFrom-Json
$expectedContent = "Write-Host 'Welcome to your PowerShell profile - CurrentUserCurrentHost!'"
$getOutput.results.result.actualState.content | Should -BeExactly $expectedContent
Expand All @@ -98,18 +130,33 @@ Describe "DSC PowerShell Profile Resource Tests" -Tag "CI" {
}

It 'DSC resource can set current user all hosts profile' {
if ($isMsix) {
Set-ItResult -Pending -Because "Running in MSIX context. Skipping test."
return
}

$setOutput = (& $dscExe config set --file $PSScriptRoot/psprofile_currentuser_allhosts.dsc.yaml -o json) | ConvertFrom-Json
$expectedContent = "Write-Host 'Welcome to your PowerShell profile - CurrentUserAllHosts!'"
$setOutput.results.result.afterState.content | Should -BeExactly $expectedContent
}

It 'DSC resource can get current user all hosts profile' {
if ($isMsix) {
Set-ItResult -Pending -Because "Running in MSIX context. Skipping test."
return
}

$getOutput = (& $dscExe config get --file $PSScriptRoot/psprofile_currentuser_allhosts.dsc.yaml -o json) | ConvertFrom-Json
$expectedContent = "Write-Host 'Welcome to your PowerShell profile - CurrentUserAllHosts!'"
$getOutput.results.result.actualState.content | Should -BeExactly $expectedContent
}

It 'DSC resource can export all profiles' {
if ($isMsix) {
Set-ItResult -Pending -Because "Running in MSIX context. Skipping test."
return
}

$exportOutput = (& $dscExe config export --file $PSScriptRoot/psprofile_export.dsc.yaml -o json) | ConvertFrom-Json

$exportOutput.resources | Should -HaveCount 4
Expand All @@ -123,6 +170,12 @@ Describe "DSC PowerShell Profile Resource Tests" -Tag "CI" {

Describe "DSC PowerShell Profile resource elevated tests" -Tag "CI", 'RequireAdminOnWindows', 'RequireSudoOnUnix' {
BeforeAll {
$isMsix = $pshome -like '*WindowsApps*'
if ($isMsix) {
Write-Verbose "Running in MSIX context. Marking tests as pending." -Verbose
return
}

$DSC_ROOT = $env:DSC_ROOT
$skipCleanup = $false

Expand Down Expand Up @@ -166,6 +219,10 @@ Describe "DSC PowerShell Profile resource elevated tests" -Tag "CI", 'RequireAdm
return
}

if ($isMsix) {
return
}

$env:PATH = $originalPath

$testProfilePathAllUsersCurrentHost = $PROFILE.AllUsersCurrentHost
Expand All @@ -189,24 +246,44 @@ Describe "DSC PowerShell Profile resource elevated tests" -Tag "CI", 'RequireAdm
}

It 'DSC resource can set all users all hosts profile' {
if ($isMsix) {
Set-ItResult -Pending -Because "Running in MSIX context. Skipping test."
return
}

$setOutput = (& $dscExe config set --file $PSScriptRoot/psprofile_alluser_allhost.dsc.yaml -o json) | ConvertFrom-Json
$expectedContent = "Write-Host 'Welcome to your PowerShell profile - AllUsersAllHosts!'"
$setOutput.results.result.afterState.content | Should -BeExactly $expectedContent
}

It 'DSC resource can get all users all hosts profile' {
if ($isMsix) {
Set-ItResult -Pending -Because "Running in MSIX context. Skipping test."
return
}

$getOutput = (& $dscExe config get --file $PSScriptRoot/psprofile_alluser_allhost.dsc.yaml -o json) | ConvertFrom-Json
$expectedContent = "Write-Host 'Welcome to your PowerShell profile - AllUsersAllHosts!'"
$getOutput.results.result.actualState.content | Should -BeExactly $expectedContent
}

It 'DSC resource can set all users current hosts profile' {
if ($isMsix) {
Set-ItResult -Pending -Because "Running in MSIX context. Skipping test."
return
}

$setOutput = (& $dscExe config set --file $PSScriptRoot/psprofile_allusers_currenthost.dsc.yaml -o json) | ConvertFrom-Json
$expectedContent = "Write-Host 'Welcome to your PowerShell profile - AllUsersCurrentHost!'"
$setOutput.results.result.afterState.content | Should -BeExactly $expectedContent
}

It 'DSC resource can get all users current hosts profile' {
if ($isMsix) {
Set-ItResult -Pending -Because "Running in MSIX context. Skipping test."
return
}

$getOutput = (& $dscExe config get --file $PSScriptRoot/psprofile_allusers_currenthost.dsc.yaml -o json) | ConvertFrom-Json
$expectedContent = "Write-Host 'Welcome to your PowerShell profile - AllUsersCurrentHost!'"
$getOutput.results.result.actualState.content | Should -BeExactly $expectedContent
Expand Down
Loading