-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added initial Pester test and limited repo clone to specific directories
- Loading branch information
Showing
3 changed files
with
167 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
BeforeAll { | ||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 | ||
|
||
Set-StrictMode -Version Latest | ||
|
||
[string]$baseUrl = "$env:IPAM_URL/api" | ||
[System.Security.SecureString]$accessToken = ConvertTo-SecureString (Get-AzAccessToken -ResourceUrl api://$env:IPAM_ENGINE_APP_ID).Token -AsPlainText | ||
[hashtable]$headers = @{ | ||
"Content-Type" = "application/json" | ||
} | ||
|
||
# GET API Request | ||
Function Get-ApiResource { | ||
[CmdletBinding()] | ||
Param ( | ||
[Parameter(Mandatory=$True, Position=0)] | ||
[string]$resource | ||
) | ||
|
||
$response = Invoke-RestMethod ` | ||
-Method Get ` | ||
-Authentication Bearer ` | ||
-Token $accessToken ` | ||
-Uri "${baseUrl}${resource}" ` | ||
-Headers $headers | ||
|
||
Write-Output $response | ||
} | ||
|
||
# POST API Request | ||
Function New-ApiResource { | ||
[CmdletBinding()] | ||
Param( | ||
[Parameter(Mandatory=$True, Position=0)] | ||
[string]$resource, | ||
|
||
[Parameter(Mandatory=$True, Position=1)] | ||
[hashtable]$body | ||
) | ||
|
||
$jsonBody = $body | ConvertTo-Json | ||
$response = Invoke-RestMethod ` | ||
-Method Post ` | ||
-Authentication Bearer ` | ||
-Token $accessToken ` | ||
-Uri "${baseUrl}${resource}" ` | ||
-Headers $headers ` | ||
-Body $jsonBody | ||
|
||
Write-Output $response | ||
} | ||
|
||
# PUT API Request | ||
Function Set-ApiResource { | ||
[CmdletBinding()] | ||
Param( | ||
[Parameter(Mandatory=$True, Position=0)] | ||
[string]$resource, | ||
|
||
[Parameter(Mandatory=$True, Position=1)] | ||
[hashtable]$body | ||
) | ||
|
||
$jsonBody = $body | ConvertTo-Json | ||
$response = Invoke-RestMethod ` | ||
-Method Put ` | ||
-Authentication Bearer ` | ||
-Token $accessToken ` | ||
-Uri "${baseUrl}${resource}" ` | ||
-Headers $headers ` | ||
-Body $jsonBody | ||
|
||
Write-Output $response | ||
} | ||
|
||
# PATCH API Request | ||
Function Update-ApiResource { | ||
[CmdletBinding()] | ||
Param( | ||
[Parameter(Mandatory=$True, Position=0)] | ||
[string]$resource, | ||
|
||
[Parameter(Mandatory=$True, Position=1)] | ||
[hashtable]$body | ||
) | ||
|
||
$jsonBody = $body | ConvertTo-Json | ||
$response = Invoke-RestMethod ` | ||
-Method Patch ` | ||
-Authentication Bearer ` | ||
-Token $accessToken ` | ||
-Uri "${baseUrl}${resource}" ` | ||
-Headers $headers ` | ||
-Body $jsonBody | ||
|
||
Write-Output $response | ||
} | ||
|
||
# DELETE API Request | ||
Function Remove-ApiResource { | ||
[CmdletBinding()] | ||
Param( | ||
[Parameter(Mandatory=$True, Position=0)] | ||
[string]$resource | ||
) | ||
|
||
$response = Invoke-RestMethod ` | ||
-Method Delete ` | ||
-Autjentication Bearer ` | ||
-Token $accessToken ` | ||
-Uri "${baseUrl}${resource}" ` | ||
-Headers $headers | ||
|
||
Write-Output $response | ||
} | ||
} | ||
|
||
Describe 'Get-Posts' { | ||
|
||
It 'Spaces is empty' { | ||
|
||
$spaces = Get-ApiResource '/spaces' | ||
|
||
$spaces | Should -Be $null | ||
} | ||
|
||
} |