Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration tests for Build Definitions #71

Merged
merged 18 commits into from
Aug 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,22 @@ The cases of every file is very important. This module is to be used on Windows,

### 3.0.5

Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/70) from [Geert van der Cruijsen](https://github.com/Geertvdc) which included the following:
Merged [Pull Request 70](https://github.com/DarqueWarrior/vsteam/pull/70) and [Pull Request 72](https://github.com/DarqueWarrior/vsteam/pull/72) from [Geert van der Cruijsen](https://github.com/Geertvdc) which included the following:

Added a function to remove vsts agents from a pool. by calling Remove-Agent or Remove-VSTeamAgent
- Added a function to remove vsts agents from a pool by calling Remove-Agent or Remove-VSTeamAgent
- Disable & Enable agents in pool

Add [Pull Request 70](https://github.com/DarqueWarrior/vsteam/pull/71) from [Kai Walter](https://github.com/KaiWalter) which included the following:

Integration tests for Build Definitions

### 3.0.4

The ProjectName dynamic parameter that enables Tab Complete of project names was getting called approximately 20 times when tab completing a function name. To reduce the number of calls a rudimentary cache was put in place.

### 3.0.3

Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/66) from [Kai Walter](https://github.com/KaiWalter) which included the following:
Merged [Pull Request 66](https://github.com/DarqueWarrior/vsteam/pull/66) from [Kai Walter](https://github.com/KaiWalter) which included the following:

Updated integration tests to account for the new hosted agent pool.

Expand Down
96 changes: 96 additions & 0 deletions integration/test/010_builddef_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"options": [],
"variables": {
"system.debug": {
"value": "false",
"allowOverride": true
}
},
"retentionRules": [{
"branches": ["+refs/heads/*"],
"artifacts": [],
"artifactTypesToDelete": ["FilePath", "SymbolStore"],
"daysToKeep": 10,
"minimumToKeep": 1,
"deleteBuildRecord": true,
"deleteTestResults": true
}],
"properties": {},
"tags": [],
"jobAuthorizationScope": 1,
"jobTimeoutInMinutes": 60,
"jobCancelTimeoutInMinutes": 5,
"process": {
"phases": [{
"steps": [{
"environment": {},
"enabled": true,
"continueOnError": false,
"alwaysRun": false,
"displayName": "PowerShell Script",
"timeoutInMinutes": 0,
"condition": "succeeded()",
"task": {
"id": "e213ff0f-5d5c-4791-802d-52ea3e7be1f1",
"versionSpec": "2.*",
"definitionType": "task"
},
"inputs": {
"targetType": "inline",
"filePath": "",
"arguments": "",
"script": "Write-Host \"Hello World\"",
"errorActionPreference": "stop",
"failOnStderr": "false",
"ignoreLASTEXITCODE": "false",
"workingDirectory": ""
}
}],
"name": "Phase 1",
"refName": "Phase_1",
"condition": "succeeded()",
"target": {
"executionOptions": {
"type": 0
},
"allowScriptsAuthAccessOption": false,
"type": 1
},
"jobAuthorizationScope": "projectCollection",
"jobCancelTimeoutInMinutes": 1
}],
"type": 1
},
"repository": {
"properties": {
"cleanOptions": "0",
"labelSources": "0",
"labelSourcesFormat": "$(build.buildNumber)",
"reportBuildStatus": "true",
"gitLfsSupport": "false",
"skipSyncSource": "false",
"checkoutNestedSubmodules": "false",
"fetchDepth": "0"
},
"id": "1c78f0c9-82a4-4444-955b-ce0def7e2399",
"type": "TfsGit",
"name": "CI",
"defaultBranch": "refs/heads/master",
"clean": "false",
"checkoutSubmodules": false
},
"processParameters": {},
"quality": 1,
"drafts": [],
"queue": {
"id": 231
},
"name": "TeamModuleIntegrationfd41f186cd1-CI",
"path": "\\",
"type": 2,
"queueStatus": 0,
"revision": 1,
"project": {
"id": "a4513ce5-464e-4a57-82ec-8bcfd4a671c7"
}
}
125 changes: 125 additions & 0 deletions integration/test/010_builddef_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{
"options": [],
"variables": {
"system.debug": {
"value": "false",
"allowOverride": true
}
},
"retentionRules": [{
"branches": ["+refs/heads/*"],
"artifacts": [],
"artifactTypesToDelete": ["FilePath", "SymbolStore"],
"daysToKeep": 10,
"minimumToKeep": 1,
"deleteBuildRecord": true,
"deleteTestResults": true
}],
"properties": {},
"tags": [],
"jobAuthorizationScope": 1,
"jobTimeoutInMinutes": 60,
"jobCancelTimeoutInMinutes": 5,
"process": {
"phases": [{
"steps": [{
"environment": {},
"enabled": true,
"continueOnError": false,
"alwaysRun": false,
"displayName": "PowerShell Script",
"timeoutInMinutes": 0,
"condition": "succeeded()",
"task": {
"id": "e213ff0f-5d5c-4791-802d-52ea3e7be1f1",
"versionSpec": "2.*",
"definitionType": "task"
},
"inputs": {
"targetType": "inline",
"filePath": "",
"arguments": "",
"script": "Write-Host \"Hello World\"",
"errorActionPreference": "stop",
"failOnStderr": "false",
"ignoreLASTEXITCODE": "false",
"workingDirectory": ""
}
}],
"name": "Phase 1",
"refName": "Phase_1",
"condition": "succeeded()",
"target": {
"executionOptions": {
"type": 0
},
"allowScriptsAuthAccessOption": false,
"type": 1
},
"jobAuthorizationScope": "projectCollection",
"jobCancelTimeoutInMinutes": 1
}, {
"steps": [{
"environment": {},
"enabled": true,
"continueOnError": false,
"alwaysRun": false,
"displayName": "Delay by 1 minutes",
"timeoutInMinutes": 0,
"condition": "succeeded()",
"task": {
"id": "28782b92-5e8e-4458-9751-a71cd1492bae",
"versionSpec": "1.*",
"definitionType": "task"
},
"inputs": {
"delayForMinutes": "1"
}
}],
"name": "Agentless phase",
"refName": "Phase_2",
"condition": "succeeded()",
"target": {
"executionOptions": {
"type": 0
},
"type": 2
},
"jobAuthorizationScope": "projectCollection",
"jobCancelTimeoutInMinutes": 1
}],
"type": 1
},
"repository": {
"properties": {
"cleanOptions": "0",
"labelSources": "0",
"labelSourcesFormat": "$(build.buildNumber)",
"reportBuildStatus": "true",
"gitLfsSupport": "false",
"skipSyncSource": "false",
"checkoutNestedSubmodules": "false",
"fetchDepth": "0"
},
"id": "1c78f0c9-82a4-4444-955b-ce0def7e2399",
"type": "TfsGit",
"name": "CI",
"defaultBranch": "refs/heads/master",
"clean": "false",
"checkoutSubmodules": false
},
"processParameters": {},
"quality": 1,
"drafts": [],
"queue": {
"id": 231
},
"name": "TeamModuleIntegrationfd41f186cd1-CI",
"path": "\\",
"type": 2,
"queueStatus": 0,
"revision": 1,
"project": {
"id": "a4513ce5-464e-4a57-82ec-8bcfd4a671c7"
}
}
62 changes: 61 additions & 1 deletion integration/test/010_projects.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Describe 'VSTeam Integration Tests' -Tag 'integration' {

# The way we search for the account is different for VSTS and TFS
$search = "*$acct*"
if($api -eq 'VSTS') {
if ($api -eq 'VSTS') {
$search = "*//$acct.*"
}

Expand Down Expand Up @@ -162,6 +162,66 @@ Describe 'VSTeam Integration Tests' -Tag 'integration' {
}
}

Context 'BuildDefinition full exercise' {

Add-VSTeamGitRepository -ProjectName $newProjectName -Name 'CI'
$project = $repo = Get-VSTeamProject -Name $newProjectName
$repo = Get-VSTeamGitRepository -ProjectName $newProjectName -Name 'CI'

if ($acct -like "http://*") {
$defaultQueue = Get-VSTeamQueue -ProjectName $newProjectName | Where-Object {$_.poolName -eq "Default"}
}
else {
$defaultQueue = Get-VSTeamQueue -ProjectName $newProjectName | Where-Object {$_.poolName -eq "Hosted"}
}

$srcBuildDef = Get-Content $(Join-Path $PSScriptRoot "010_builddef_1.json") | ConvertFrom-Json
$srcBuildDef.project.id = $project.Id
$srcBuildDef.queue.id = $defaultQueue.Id
$srcBuildDef.repository.id = $repo.Id
$srcBuildDef.name = $newProjectName + "-CI1"
$tmpBuildDef1 = (New-TemporaryFile).FullName
$srcBuildDef | ConvertTo-Json -Depth 10 | Set-Content -Path $tmpBuildDef1

$srcBuildDef = Get-Content $(Join-Path $PSScriptRoot "010_builddef_2.json") | ConvertFrom-Json
$srcBuildDef.project.id = $project.Id
$srcBuildDef.queue.id = $defaultQueue.Id
$srcBuildDef.repository.id = $repo.Id
$srcBuildDef.name = $newProjectName + "-CI2"
$tmpBuildDef2 = (New-TemporaryFile).FullName
$srcBuildDef | ConvertTo-Json -Depth 10 | Set-Content -Path $tmpBuildDef2

It 'Add-VSTeamBuildDefinition should add a build definition' {
Add-VSTeamBuildDefinition -ProjectName $newProjectName -InFile $tmpBuildDef1
$buildDef = Get-VSTeamBuildDefinition -ProjectName $newProjectName
$buildDef | Should Not Be $null
}

It 'Add-VSTeamBuildDefinition should add another build definition' {
Add-VSTeamBuildDefinition -ProjectName $newProjectName -InFile $tmpBuildDef2
$buildDefs = Get-VSTeamBuildDefinition -ProjectName $newProjectName
$buildDefs.Count | Should Be 2
}

# Only run for VSTS
if ($api -eq 'VSTS') {
It 'Get-VSTeamBuildDefinition by Id should return 1 phase for 1st build definition' {
$buildDefId = (Get-VSTeamBuildDefinition -ProjectName $newProjectName | Where-Object {$_.Name -like "*CI1"}).Id
((Get-VSTeamBuildDefinition -ProjectName $newProjectName -Id $buildDefId).Process.Phases).Count | Should Be 1
}

It 'Get-VSTeamBuildDefinition by Id should return 2 phase for 2nd build definition' {
$buildDefId = (Get-VSTeamBuildDefinition -ProjectName $newProjectName | Where-Object {$_.Name -like "*CI2"}).Id
((Get-VSTeamBuildDefinition -ProjectName $newProjectName -Id $buildDefId).Process.Phases).Count | Should Be 2
}
}

It 'Remove-VSTeamBuildDefinition should delete build definition' {
Get-VSTeamBuildDefinition -ProjectName $newProjectName | Remove-VSTeamBuildDefinition -ProjectName $newProjectName -Force
Get-VSTeamBuildDefinition -ProjectName $newProjectName | Should Be $null
}
}

Context 'Pool full exercise' {
It 'Get-VSTeamPool Should return agent pools' {
$actual = Get-VSTeamPool
Expand Down