Skip to content

Commit

Permalink
Added Test-IsNanoServer - Fixes #9 (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
PlagueHO authored Feb 15, 2020
1 parent 18f3c07 commit 06f98c5
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Added more function documentation to the README.md.
- Fix minor style issue in functions.
- Changed the VS Code project settings to trim trailing whitespace for
Expand All @@ -16,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- The deploy step is no longer run on forks.
- Azure Pipelines will no longer trigger on changes to just the CHANGELOG.md.
- Add section "How to implement" in the README.md.
- Added `Test-IsNanoServer` function - fixes [Issue #9](https://github.com/dsccommunity/DscResource.Common/issues/9).

## [0.2.0] - 2020-01-09

Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,8 @@ catch

### `Test-DscParameterState`

This method is used to compare current and desired values for any DSC resource.
This function is used to compare current and desired values for any DSC resource.

### `Test-IsNanoServer`

This function tests if the current OS is a Nano server.
19 changes: 19 additions & 0 deletions source/Public/Test-IsNanoServer.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<#
.SYNOPSIS
Tests if the current OS is a Nano server.
#>
function Test-IsNanoServer
{
[OutputType([System.Boolean])]
[CmdletBinding()]
param ()

$productDatacenterNanoServer = 143
$productStandardNanoServer = 144

$operatingSystemSKU = (Get-CimInstance -ClassName Win32_OperatingSystem).OperatingSystemSKU

Write-Verbose -Message ($script:localizedData.TestIsNanoServerOperatingSystemSku -f $operatingSystemSKU)

return ($operatingSystemSKU -in ($productDatacenterNanoServer, $productStandardNanoServer))
}
1 change: 1 addition & 0 deletions source/en-US/DscResource.Common.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ ConvertFrom-StringData @'
PropertyThatDoesNotMatch = {0} - {1}
ValueOfTypeDoesNotMatch = {0} value for property {1} does not match. Current state is '{2}' and desired state is '{3}'.
UnableToCompareProperty = Unable to compare property {0} as the type {1} is not handled by the Test-DscParameterState cmdlet.
TestIsNanoServerOperatingSystemSku = OperatingSystemSKU {0} was returned by Win32_OperatingSystem when detecting if operating system is Nano Server.
'@
2 changes: 1 addition & 1 deletion tests/Unit/Public/Test-DscParameterState.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,4 @@ InModuleScope $ProjectName {
Assert-VerifiableMock
}

}
}
68 changes: 68 additions & 0 deletions tests/Unit/Public/Test-IsNanoServer.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
$ProjectPath = "$PSScriptRoot\..\..\.." | Convert-Path
$ProjectName = ((Get-ChildItem -Path $ProjectPath\*\*.psd1).Where{
($_.Directory.Name -match 'source|src' -or $_.Directory.Name -eq $_.BaseName) -and
$(try
{
Test-ModuleManifest $_.FullName -ErrorAction Stop
}
catch
{
$false
} )
}).BaseName

Import-Module $ProjectName -Force

Describe 'Test-IsNanoServer' -Tag TestIsNanoServer {
function Get-CimInstance
{
param
(
[Parameter()]
[System.String]
$ClassName
)
}

Context 'When the current computer is a Datacenter Nano server' {
Mock -CommandName Get-CimInstance `
-ModuleName $ProjectName `
-MockWith {
[PSCustomObject] @{
OperatingSystemSKU = 143
}
}

It 'Should retrun true' {
Test-IsNanoServer -Verbose | Should -BeTrue
}
}

Context 'When the current computer is a Standard Nano server' {
Mock -CommandName Get-CimInstance `
-ModuleName $ProjectName `
-MockWith {
[PSCustomObject] @{
OperatingSystemSKU = 144
}
}

It 'Should retrun true' {
Test-IsNanoServer -Verbose | Should -BeTrue
}
}

Context 'When the current computer is not a Nano server' {
Mock -CommandName Get-CimInstance `
-ModuleName $ProjectName `
-MockWith {
[PSCustomObject] @{
OperatingSystemSKU = 1
}
}

It 'Should retrun false' {
Test-IsNanoServer -Verbose | Should -BeFalse
}
}
}

0 comments on commit 06f98c5

Please sign in to comment.