Skip to content

Commit

Permalink
fix: enable integration test for devops variable group description (#400
Browse files Browse the repository at this point in the history
)

* enable `Sets the DevOps variable group description with the release name` test, different way of authenticating to the devops api

* update api version and retrieve description from first value

* remove unused var

* added debug logging

* added debug logging

* add param for url encoded variable group name

* re added $env:ArmOutputs

* fixed requesturi

* remove debug logging

* added comment about PAT

---------

Co-authored-by: Pim Simons <pim.simons@codit.eu>
  • Loading branch information
pim-simons and Pim Simons committed Jul 8, 2023
1 parent 22d99ec commit 7c67ba7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,25 @@ InModuleScope Arcus.Scripting.DevOps {
}
}
}
It "Sets the DevOps variable group description with the release name" -Skip {
It "Sets the DevOps variable group description with the release name" {
# Arrange
$variableGroupName = $config.Arcus.DevOps.VariableGroup.Name
$variableGroupNameUrlEncoded = $config.Arcus.DevOps.VariableGroup.NameUrlEncoded
$env:ArmOutputs = "{ ""my-variable"": { ""type"": ""string"", ""value"": ""my-value"" } }"
#$variableGroupAuthorization contains a PAT with read access to variable groups, create a new one when it expires
$variableGroupAuthorization = $config.Arcus.DevOps.VariableGroup.Authorization
$projectId = $env:SYSTEM_TEAMPROJECTID
$collectionUri = $env:SYSTEM_COLLECTIONURI
$requestUri = "$collectionUri" + "$projectId/_apis/distributedtask/variablegroups?groupName=/" + $variableGroupName + "?api-version=6.0"
$headers = @{ Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN" }
$requestUri = "$collectionUri" + "$projectId/_apis/distributedtask/variablegroups?groupName=" + $variableGroupNameUrlEncoded + "&api-version=6.1-preview.2"
$headers = @{ Authorization = "Basic $variableGroupAuthorization" }

# Act
Set-AzDevOpsArmOutputsToVariableGroup -VariableGroupName $variableGroupName

# Assert
$getResponse = Invoke-WebRequest -Uri $requestUri -Method Get -Headers $headers
$json = ConvertFrom-Json $getResponse.Content
$json.description | Should -BeLike "*$env:Build_DefinitionName*$env:Build_BuildNumber*"
$json.value[0].description | Should -BeLike "*$env:Build_DefinitionName*$env:Build_BuildNumber*"
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/Arcus.Scripting.Tests.Integration/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
},
"DevOps": {
"VariableGroup": {
"Name": "#{Arcus.DevOps.VariableGroup.Name}#"
"Name": "#{Arcus.DevOps.VariableGroup.Name}#",
"NameUrlEncoded": "#{Arcus.DevOps.VariableGroup.Name.UrlEncoded}#",
"Authorization": "#{Arcus.DevOps.VariableGroup.Authorization}#"
}
},
"KeyVault": {
Expand Down

0 comments on commit 7c67ba7

Please sign in to comment.