138 lines
5.6 KiB
PowerShell
138 lines
5.6 KiB
PowerShell
. $PSScriptRoot\..\..\Load-PesterModules.ps1
|
|
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.tests\.', '.'
|
|
$functionPath = Join-Path -Path $here -ChildPath $sut
|
|
Write-Host "Overriding SUT: $functionPath"
|
|
Import-Module $functionPath -Force
|
|
$moduleForMock = ""
|
|
|
|
Describe "Set-InfrastructureConfiguration" {
|
|
|
|
Context "Function Tests" {
|
|
|
|
|
|
It "Uses the Supplied ServerRole in the Output File" {
|
|
|
|
$testConfiguration = "TestDrive:\newrelic-infra.yml"
|
|
Mock -CommandName Get-NewRelicYamlPath -MockWith { "TestDrive:\newrelic-infra.yml" }
|
|
Mock -CommandName Get-NewRelicAccountDetails -ModuleName $moduleForMock {
|
|
|
|
return New-Object PSObject -Property @{
|
|
LicenseKey = "abcdefg123456";
|
|
}
|
|
}
|
|
|
|
Set-InfrastructureConfiguration -ServerRole "BitcoinMiner" -Pod "99" -EnvironmentKey "abcdefg123456" `
|
|
|
|
$content = Get-Content $testConfiguration -Raw
|
|
$content | Should -Match " ServerRole: BitcoinMiner"
|
|
}
|
|
|
|
It "Uses the Supplied Pod in the Output File" {
|
|
|
|
$testConfiguration = "TestDrive:\newrelic-infra.yml"
|
|
Mock -CommandName Get-NewRelicYamlPath -MockWith { "TestDrive:\newrelic-infra.yml" }
|
|
Mock -CommandName Get-NewRelicAccountDetails -ModuleName $moduleForMock {
|
|
|
|
return New-Object PSObject -Property @{
|
|
LicenseKey = "abcdefg123456";
|
|
}
|
|
}
|
|
|
|
Set-InfrastructureConfiguration -ServerRole "Web" -Pod "98.70" -EnvironmentKey "abcdefg123456" `
|
|
|
|
$content = Get-Content $testConfiguration -Raw
|
|
$content | Should -Match " Pod: '98\.70'"
|
|
}
|
|
|
|
It "Does not use the Supplied Pod in the Output File" {
|
|
|
|
$testConfiguration = "TestDrive:\newrelic-infra.yml"
|
|
Mock -CommandName Get-NewRelicYamlPath -MockWith { "TestDrive:\newrelic-infra.yml" }
|
|
Mock -CommandName Get-NewRelicAccountDetails -ModuleName $moduleForMock {
|
|
|
|
return New-Object PSObject -Property @{
|
|
LicenseKey = "abcdefg123456";
|
|
}
|
|
}
|
|
|
|
Set-InfrastructureConfiguration -ServerRole "Web" -Pod "98670" -EnvironmentKey "abcdefg123456" `
|
|
|
|
$content = Get-Content $testConfiguration -Raw
|
|
$content | Should -Not -Match " Pod: '98\.70'"
|
|
}
|
|
|
|
It "Does not use the Supplied Pod in the Output File with no single quotes" {
|
|
|
|
$testConfiguration = "TestDrive:\newrelic-infra.yml"
|
|
Mock -CommandName Get-NewRelicYamlPath -MockWith { "TestDrive:\newrelic-infra.yml" }
|
|
Mock -CommandName Get-NewRelicAccountDetails -ModuleName $moduleForMock {
|
|
|
|
return New-Object PSObject -Property @{
|
|
LicenseKey = "abcdefg123456";
|
|
}
|
|
}
|
|
|
|
Set-InfrastructureConfiguration -ServerRole "Web" -Pod "98.70" -EnvironmentKey "abcdefg123456" `
|
|
|
|
$content = Get-Content $testConfiguration -Raw
|
|
$content | Should -Not -Match " Pod: 98\.70"
|
|
}
|
|
|
|
It "Uses the Supplied LicenseKey in the Output File" {
|
|
|
|
$testConfiguration = "TestDrive:\newrelic-infra.yml"
|
|
Mock -CommandName Get-NewRelicYamlPath -MockWith { "TestDrive:\newrelic-infra.yml" }
|
|
Mock -CommandName Get-NewRelicAccountDetails -ModuleName $moduleForMock {
|
|
|
|
return New-Object PSObject -Property @{
|
|
LicenseKey = "hunter2";
|
|
}
|
|
}
|
|
|
|
Set-InfrastructureConfiguration -ServerRole "Web" -Pod "187" -EnvironmentKey "abcdefg123456" `
|
|
|
|
$content = Get-Content $testConfiguration -Raw
|
|
$content | Should -Match "^license_key: hunter2"
|
|
}
|
|
|
|
It "Uses 4 Preceeding Spaces for All Indented Lines" {
|
|
|
|
$testConfiguration = "TestDrive:\newrelic-infra.yml"
|
|
Mock -CommandName Get-NewRelicYamlPath -MockWith { "TestDrive:\newrelic-infra.yml" }
|
|
Mock -CommandName Get-NewRelicAccountDetails -ModuleName $moduleForMock {
|
|
|
|
return New-Object PSObject -Property @{
|
|
LicenseKey = "fakelicense";
|
|
}
|
|
}
|
|
|
|
Set-InfrastructureConfiguration -ServerRole "FakeRole" -Pod "FakePod" -EnvironmentKey "abcdefg123456" `
|
|
|
|
$leadingWhiteSpaceContent = Get-Content $testConfiguration | Where-Object { $_ -match "^\s" }
|
|
|
|
foreach ($contentLine in $leadingWhiteSpaceContent) {
|
|
|
|
$contentLine | Should -Match "^ " -Because "YAML Indented Lines Must Start with 4 Spaces, Not Tabs"
|
|
$contentLine | Should -Not -Match "^\t" -Because "YAML Indented Lines Must Start with 4 Spaces, Not Tabs"
|
|
}
|
|
}
|
|
|
|
It "Includes the Disable Cloud Instance ID Attribute" {
|
|
|
|
$testConfiguration = "TestDrive:\newrelic-infra.yml"
|
|
Mock -CommandName Get-NewRelicYamlPath -MockWith { "TestDrive:\newrelic-infra.yml" }
|
|
Mock -CommandName Get-NewRelicAccountDetails -ModuleName $moduleForMock {
|
|
|
|
return New-Object PSObject -Property @{
|
|
LicenseKey = "fakelicense2";
|
|
}
|
|
}
|
|
|
|
Set-InfrastructureConfiguration -ServerRole "FakeRole2" -Pod "FakePod2" -EnvironmentKey "abcdefg1234562" `
|
|
|
|
$content = Get-Content $testConfiguration -Raw
|
|
$content | Should -Match "disable_cloud_instance_id: true" -Because "NewRelic Infrastructure May Use the Instance ID instead of Hostname if Not Present"
|
|
}
|
|
}
|
|
} |