Testing SAP Connector info
  • Updated on 20 May 2020
  • 1 minute to read
  • Contributors
  • Print
  • Comments
  • Share
  • Dark
    Light

Testing SAP Connector info

  • Print
  • Comments
  • Share
  • Dark
    Light

Next in my series of Pester tests I want to check that all of my API Connectors used by Logic Apps are pointing to the right instance of SAP. To do this I have created a script below which will get all of the connectors via Get-AzResource and it will iterate over them. It will then use the Az-Rest command to get the underlying json from the connector and it will check if it is the SAP connector. I will then parse the json to look for the properties used by the SAP connector and check that they exist and if they do that they are using the right values which I have set in my script.

When I run this locally on my dev environment I can check just against some parameters in the file but if I want to run this in a devops process I can inject the parameters from a pipeline.

The result though of the script is I will identify all of my SAP connectors and check they all point to the right SAP instance.

$sapAppServerHost = 'MYSAPServer'
$sapAppServerService = 'TBC'
$sapClient = 999
$sapSystemNumber = 99

$apiConnections = Get-AzResource -ResourceGroupName $resourcegroup -ResourceType Microsoft.Web/connections

Write-Host '$sapAppServerHost:' $sapAppServerHost
Write-Host '$sapAppServerService:' $sapAppServerService
Write-Host '$sapClient:' $sapClient
Write-Host '$sapSystemNumber:' $sapSystemNumber


Describe 'API Connections to SAP'{
    foreach($apiConnection in $apiConnections){
                
        
        #Get the connector json
        $connectorUrl = $apiConnection.ResourceId + '?api-version=2018-07-01-preview'        
        $connectorJson = az rest --method get --uri $connectorUrl
        $connectorJsonText = $connectorJson | ConvertFrom-Json


        #SAP Connector Tests
        $sapExpression = '/managedApis/sap'
        if($connectorJson -match $sapExpression)
        {
            It "$($apiConnection.Name) sapAppServerHost" {   
                $connectorJsonText.properties.parameterValues.appServerHost | Should Be $sapAppServerHost
            }

            It "$($apiConnection.Name) sapAppServerService" {   
                $connectorJsonText.properties.parameterValues.appServerService | Should Be $sapAppServerService
            }

            It "$($apiConnection.Name) sapClient" {   
                $connectorJsonText.properties.parameterValues.client | Should Be $sapClient
            }

            It "$($apiConnection.Name) sapSystemNumber" {   
                $connectorJsonText.properties.parameterValues.systemNumber | Should Be $sapSystemNumber
            }
        }
    }
}
Was this article helpful?