Skip to content

Commit

Permalink
added Get-ProductApplicationInsights script
Browse files Browse the repository at this point in the history
  • Loading branch information
calumrees99 committed Dec 5, 2024
1 parent c84bc57 commit d16e51c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Infrastructure-Scripts/Get-ProductApplicationInsights.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<#
.SYNOPSIS
Gets and outputs the connection string and resource id of the services application insights.
.DESCRIPTION
Gets and outputs the connection string and resource id of the services application insights.
.PARAMETER AppInsightsResourceGroup
The name of the resource group the application insights is deployed to
.PARAMETER AppInsightsName
The name of the product application insights
.EXAMPLE
.\Get-ProductApplicationInsights.ps1 -ResourceGroupName das-foo-bar-rg -Name das-foo-shared-bar-ai
#>

[CmdletBinding()]
Param (
[Parameter(Mandatory = $true)]
[String]$AppInsightsResourceGroup,
[Parameter(Mandatory = $true)]
[String]$AppInsightsName
)

$applicationInsights = Get-AzApplicationInsights -ResourceGroupName $AppInsightsResourceGroup -Name $AppInsightsName

$applicationInsightsResourceId = $applicationInsights.Id
$applicationInsightsConnectionString = $applicationInsights.Connectionstring

Write-Output "Setting value of application insights respirce Id to pipeline variable"
Write-Output "##vso[task.setvariable variable=applicationInsightsResourceId]$applicationInsightsResourceId"

Write-Output "Setting value of application insights connection string to secret pipeline variable"
Write-Output "##vso[task.setvariable variable=applicationInsightsConnectionString;issecret=true]$applicationInsightsConnectionString"
26 changes: 26 additions & 0 deletions Tests/UT.Get-ProductApplicationInsights.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
$Config = Get-Content $PSScriptRoot\..\Tests\Configuration\Unit.Tests.Config.json -Raw | ConvertFrom-Json
Set-Location $PSScriptRoot\..\Infrastructure-Scripts\

Describe "Get-ProductApplicationInsights Unit Tests" -Tags @("Unit") {

Context "Could not find application insights due to bad paramater values" {

It "The specified application insights was not found, throw an error" {
Mock Get-ProductApplicationInsights -MockWith { return $null }
{ ./Get-ProductApplicationInsights -AppInsightsResourceGroup $Config.resourceGroupName -AppInsightsName $Config.instanceName } | Should throw
Assert-MockCalled -CommandName 'Get-ProductApplicationInsights' -Times 1 -Scope It
}

}

Context "Application insights found" {

It "Application insights found" {
Mock Get-ProductApplicationInsights -MockWith { return @{ "ApplicationInsightsName" = "ApplicationInsightsName" } }
{ ./Get-ProductApplicationInsights -AppInsightsResourceGroup $Config.resourceGroupName -AppInsightsName $Config.instanceName } | Should not throw
Assert-MockCalled -CommandName 'Get-ProductApplicationInsights' -Times 1 -Scope It
}

}

}

0 comments on commit d16e51c

Please sign in to comment.