Tests/Integration/CircleNode.Integration.Tests.ps1
$script:dscModuleName = 'CircleCIDSC' $script:dscResourceFriendlyName = 'CircleNode' $script:dscResourceName = "$($script:dscResourceFriendlyName)" Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1') #region HEADER # Integration Test Template Version: 1.3.3 [String] $script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or ` (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) { & git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath 'DscResource.Tests')) } Import-Module -Name (Join-Path -Path $script:moduleRoot -ChildPath (Join-Path -Path 'DSCResource.Tests' -ChildPath 'TestHelper.psm1')) -Force $TestEnvironment = Initialize-TestEnvironment ` -DSCModuleName $script:dscModuleName ` -DSCResourceName $script:dscResourceName ` -TestType Integration #endregion # Using try/finally to always cleanup. try { #region Integration Tests $configurationFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1" . $configurationFile Describe "$($script:dscResourceName)_Integration" { BeforeAll { $resourceId = "[$($script:dscResourceFriendlyName)]Integration_Test" } $configurationName = "$($script:dscResourceName)_Integration_Config" Context ('When using configuration {0}' -f $configurationName) { It 'Should compile and apply the MOF without throwing' { { $configurationParameters = @{ ConfigurationData = $ConfigurationData OutputPath = $TestDrive } & $configurationName @configurationParameters $startDscConfigurationParameters = @{ Path = $TestDrive ComputerName = 'localhost' Wait = $true Verbose = $true Force = $true ErrorAction = 'Stop' } Start-DscConfiguration @startDscConfigurationParameters } | Should -Not -Throw } Update-Paths It 'Should be able to call Get-DscConfiguration without throwing' { { $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw } It 'Should have set the resource and all the parameters should match' { $resourceCurrentState = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq $configurationName ` -and $_.ResourceId -eq $resourceId } $resourceCurrentState.Property | Should -Be $ConfigurationData.AllNodes.Property1 } Describe "NVM" { It "is installed" { $(Get-Command -Name "nvm").Count | Should -Eq 1 } It "has node 14 installed and set to default" { $(nvm list)[1] | Should -Match "14.17.5" } } Describe "yarn" { It "is installed" { & refreshenv & nvm on $(Get-Command -Name "yarn").Count | Should -Eq 1 } } It 'Should return $true when Test-DscConfiguration is run' { Test-DscConfiguration -Verbose | Should -Be 'True' } } } #endregion } finally { #region FOOTER Restore-TestEnvironment -TestEnvironment $TestEnvironment #endregion # TODO: (Optional) Other cleanup code goes here. } |