Skip to content

Commit db1be5c

Browse files
authored
basic tests added (#2)
* basic tests added * VSTS temp folder * create temp dir * more verbose cloning * more verbose * even more verbose * adding another error * got the error * brackets * cannot figure it out * got it? * rolling back slowly * see verbose, run more tests * quiet mode, multiple tests * remove content of temp dir, non verbose tests * diagnostics only in vsts
1 parent 3cb32c2 commit db1be5c

6 files changed

Lines changed: 61 additions & 7 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PesterTestResults.xml

InvokeTests.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
# Display diagnostic information
77
#
88

9-
$PSVersionTable
10-
Get-ChildItem Env:\
9+
if ($env:TF_BUILD) {
10+
$PSVersionTable
11+
Get-ChildItem Env:\
12+
}
1113

1214
#
1315
# Install Pester v4, if needed

Public/Get-GitModule.ps1

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ function Get-GitModule {
2424
# TODO: Add more details
2525
}
2626

27-
$tmpRoot = [System.IO.Path]::GetTempPath()
27+
if ($env:AGENT_TEMPDIRECTORY) {
28+
$tmpRoot = $env:AGENT_TEMPDIRECTORY
29+
} else {
30+
$tmpRoot = [System.IO.Path]::GetTempPath()
31+
}
2832

2933
}
3034

@@ -36,8 +40,15 @@ function Get-GitModule {
3640

3741
$ModuleName = ($P1 -split '/')[-1]
3842
$tempDir = Join-Path $tmpRoot $ModuleName
43+
if (!(Test-Path $tempDir)) {
44+
Write-Verbose -Message "$(Get-Date -f T) creating directory $tempDir"
45+
New-Item $tempDir -ItemType Directory -Force | Out-Null
46+
} elseif (Get-ChildItem $tempDir -Force) {
47+
Write-Verbose -Message "$(Get-Date -f T) deleting content of temp directory $tempDir"
48+
Remove-Item (Join-Path $tempDir '*') -Recurse -Force
49+
}
3950
Write-Verbose -Message "$(Get-Date -f T) cloning repository to $tempDir"
40-
git clone $P1 --branch $Branch --single-branch $tempDir 2>&1 | Out-Null
51+
git clone $P1 --branch $Branch --single-branch $tempDir --quiet
4152
$psd1 = (Get-ChildItem $tempDir -Include *.psd1 -Recurse).FullName
4253

4354
if($psd1 -is [array]) {

Public/Install-GitModule.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function Install-GitModule {
4242
Write-Verbose -Message "$(Get-Date -f T) processing $P1"
4343

4444
$ModuleInfo = Get-GitModule -ProjectUri $P1 -KeepTempCopy
45-
if (!$ModuleInfo) {continue} # we have the error in get-gitmodule
45+
if (!$ModuleInfo -or ($ModuleInfo.Count -gt 1)) {continue} # we have the error in get-gitmodule
4646
if (!$ModuleInfo.Root) {Write-Warning -Message "$FunctionName installing module with manifest not located in module root directory"}
4747

4848
# check target directory

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ _(not yet available)_
2424
```PowerShell
2525
C:> Get-GitModule 'https://github.com/iricigor/FIFA2018' -Verbose
2626
27-
C:> Install-GitModule 'https://github.com/iricigor/psaptgetupdate' | Select -Expand Name | Import-Module
27+
C:> Install-GitModule 'https://github.com/iricigor/psaptgetupdate' -Force | Select -Expand Name | Import-Module
2828
```
2929

3030
## Commands

Tests/Module.Tests.ps1

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Describe "Fake-Test" {
2626

2727

2828
#
29-
# Module should import six functions
29+
# Module should import two functions
3030
#
3131

3232

@@ -43,6 +43,46 @@ Describe 'Proper Declarations' {
4343
}
4444

4545

46+
#
47+
# Basic tests, this should be added to individual files
48+
#
49+
50+
Describe 'Basic testing' {
51+
52+
$moduleName = 'FIFA2018'
53+
$moduleURL = 'https://github.com/iricigor/' + $moduleName
54+
It 'Get-GitModule does not throw an exception' {
55+
{Get-GitModule $moduleURL} | Should -Not -Throw
56+
}
57+
58+
It 'Get-GitModule returns some value' {
59+
Get-GitModule $moduleURL | Should -Not -Be $null
60+
}
61+
62+
It 'Get-GitModule returns proper value' {
63+
(Get-GitModule $moduleURL).Name | Should -Be $moduleName
64+
}
65+
66+
$moduleName = 'psaptgetupdate'
67+
$moduleURL = 'https://github.com/iricigor/' + $moduleName
68+
It 'Install-GitModule does not throw an exception' {
69+
{Install-GitModule $moduleURL -Force} | Should -Not -Throw
70+
}
71+
72+
It 'Install-GitModule returns some value' {
73+
Install-GitModule $moduleURL -Force | Should -Not -Be $null
74+
}
75+
76+
It 'Install-GitModule returns proper value' {
77+
(Install-GitModule $moduleURL -Force).Name | Should -Be $moduleName
78+
}
79+
80+
It 'Install-GitModule really installs module' {
81+
Get-Module $moduleName -ListAvailable | Should -Not -Be $null
82+
}
83+
}
84+
85+
4686
Describe 'Proper Documentation' {
4787

4888
It 'Updates documentation and does git diff' {

0 commit comments

Comments
 (0)