Skip to content

Commit a8c4706

Browse files
authored
Merge pull request #162 from SQLPlayer/develop
Ver.0.95
2 parents 9b3cb05 + 5d4380f commit a8c4706

File tree

7 files changed

+77
-22
lines changed

7 files changed

+77
-22
lines changed

azure.datafactory.tools.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
RootModule = 'azure.datafactory.tools.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '0.94.0'
15+
ModuleVersion = '0.95.0'
1616

1717
# Supported PSEditions
1818
# CompatiblePSEditions = @()

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

7+
## [0.95.0] - 2021-10-23
8+
* Added structure to return object for Test-AdfCode which allows to check number of warnings too
9+
* Fixed tests
10+
711
## [0.94.0] - 2021-10-20
812
* Fixed bug: add 'properties' node to ManagedVirtualNetwork if does not exist in default.json file #157
913

private/ToArray.ps1

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,16 @@ function ToArray
1212
{
1313
return ,$output;
1414
}
15-
}
15+
}
16+
17+
function Test-ErrorNoTermination {
18+
Write-Error -Message 'Test error message with no termination' -ErrorAction 'Continue'
19+
}
20+
21+
function Test-ErrorTermination {
22+
Write-Error -Message 'Test error message with termination' -ErrorAction 'Stop'
23+
}
24+
25+
function Test-Exception {
26+
Throw 'Test error message'
27+
}

public/Test-AdfCode.ps1

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,14 @@ function Test-AdfCode {
2424
[String] $ConfigPath
2525
)
2626

27-
$ErrorCount = 0
28-
$WarningCount = 0
27+
class ReturnClass {
28+
[int] $ErrorCount
29+
[int] $WarningCount
30+
}
31+
$result = New-Object 'ReturnClass'
32+
33+
$result.ErrorCount = 0
34+
$result.WarningCount = 0
2935
$adfName = Split-Path -Path "$RootFolder" -Leaf
3036

3137
Write-Host "=== Loading files from location: $RootFolder ..."
@@ -38,7 +44,7 @@ function Test-AdfCode {
3844
$ErrorActionPreference = 'Continue'
3945

4046
if ($ObjectsCount -eq 0) {
41-
$WarningCount += 1
47+
$result.WarningCount += 1
4248
Write-Warning "No Azure Data Factory files have been found in a given location."
4349
}
4450

@@ -47,22 +53,22 @@ function Test-AdfCode {
4753
Write-Host "Checking: $FullName..."
4854
$HasBody = $null -ne $_.Body
4955
if (-not $HasBody) {
50-
$ErrorCount += 1
51-
Write-Error -Message "Object $FullName was not loaded properly."
56+
$result.ErrorCount += 1
57+
Write-Error -Message "Object $FullName was not loaded properly." -ErrorAction 'Continue'
5258
}
5359
if ($HasBody) {
5460

5561
if ($_.name -ne $_.Body.name) {
56-
$ErrorCount += 1
57-
Write-Error -Message "Object $FullName has mismatch file name."
62+
$result.ErrorCount += 1
63+
Write-Error -Message "Object $FullName has mismatch file name." -ErrorAction 'Continue'
5864
}
5965

6066
$_.DependsOn | ForEach-Object {
6167
Write-Verbose -Message " - Checking dependency: [$_]"
6268
$ref_arr = $adf.GetObjectsByFullName("$_")
6369
if ($ref_arr.Count -eq 0) {
64-
$ErrorCount += 1
65-
Write-Error -Message "Couldn't find referenced object $_."
70+
$result.ErrorCount += 1
71+
Write-Error -Message "Couldn't find referenced object $_." -ErrorAction 'Continue'
6672
}
6773
}
6874
}
@@ -74,15 +80,15 @@ function Test-AdfCode {
7480
$r = $adf.GetObjectsByFullName("*." + $_)
7581
if ($r.Count -gt 1) {
7682
Write-Warning "Duplication of object name: $_"
77-
$WarningCount += 1
83+
$result.WarningCount += 1
7884
}
7985
}
8086

8187
$adf.LinkedServices + $adf.DataSets + $adf.Pipelines + $adf.DataFlows | ForEach-Object {
8288
[string] $name = $_.Name
8389
if ($name.Contains('-')) {
8490
Write-Warning "Dashes ('-') are not allowed in the names of linked services, data flows, and datasets ($name)."
85-
$WarningCount += 1
91+
$result.WarningCount += 1
8692
}
8793
}
8894

@@ -91,7 +97,7 @@ function Test-AdfCode {
9197
[string] $name = $_.Name
9298
if ($name.Contains('-')) {
9399
Write-Warning "Dashes ('-') are not allowed in the names of global parameters ($name)."
94-
$WarningCount += 1
100+
$result.WarningCount += 1
95101
}
96102
}
97103
}
@@ -115,7 +121,7 @@ function Test-AdfCode {
115121
Update-PropertiesFromFile -adf $adf -stage $FileName -ErrorVariable err -ErrorAction 'Stop' -dryRun:$True
116122
}
117123
catch {
118-
$ErrorCount += 1
124+
$result.ErrorCount += 1
119125
Write-Host "ERROR: $($_.Exception.Message)" -ForegroundColor 'Red'
120126
Write-Debug -Message $_.Exception
121127
#$_.Exception
@@ -125,13 +131,13 @@ function Test-AdfCode {
125131

126132

127133
$msg = "Test code completed ($ObjectsCount objects)."
128-
if ($ErrorCount -gt 0) { $msg = "Test code failed." }
129-
$line1 = $adf.Name.PadRight(63) + " # of Errors: $ErrorCount".PadLeft(28)
130-
$line2 = $msg.PadRight(63) + "# of Warnings: $WarningCount".PadLeft(28)
134+
if ($result.ErrorCount -gt 0) { $msg = "Test code failed." }
135+
$line1 = $adf.Name.PadRight(63) + " # of Errors: $($result.ErrorCount)".PadLeft(28)
136+
$line2 = $msg.PadRight(63) + "# of Warnings: $($result.WarningCount)".PadLeft(28)
131137
Write-Host "============================================================================================="
132138
Write-Host " $line1"
133139
Write-Host " $line2"
134140
Write-Host "============================================================================================="
135141

136-
return $ErrorCount;
142+
return $result;
137143
}

test/!RunAllTests.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ try{
5757
$configuration.Should.ErrorAction = 'Continue'
5858
$configuration.CodeCoverage.Enabled = $false
5959
$configuration.TestResult.OutputFormat = "NUnitXml"
60-
$configuration.TestResult.OutputPath = "TEST-Results.xml"
60+
$configuration.TestResult.OutputPath = "$folder\TEST-Results.xml"
6161
$configuration.TestResult.Enabled = $true
6262
$configuration.Output.Verbosity = 'Detailed'
6363
if ($LocalTestsOnly) {
@@ -73,6 +73,8 @@ try{
7373
#$r.Passed[0]
7474
$r.Failed | Format-Table -Property Result, StartLine, Duration, Path
7575

76+
#Get-ChildItem -Path $folder | Format-Table
77+
7678
} finally {
7779
Pop-Location
7880
}

test/Test-AdfCode.Tests.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ InModuleScope azure.datafactory.tools {
3030
$script:res = Test-AdfCode -RootFolder $RootFolder
3131
} | Should -Not -Throw
3232
}
33-
It 'Should return 1 error' {
34-
$res | Should -Be 1
33+
It 'Should return 1 error and 6 warnings in ReturnClass' {
34+
$res.GetType() | Should -Be 'Test-AdfCode.ReturnClass'
35+
$res.ErrorCount | Should -Be 1
36+
$res.WarningCount | Should -Be 6
3537
}
3638

3739
}

test/Test-Exceptions.Tests.ps1

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BeforeDiscovery {
2+
$ModuleRootPath = $PSScriptRoot | Split-Path -Parent
3+
$moduleManifestName = 'azure.datafactory.tools.psd1'
4+
$moduleManifestPath = Join-Path -Path $ModuleRootPath -ChildPath $moduleManifestName
5+
6+
Import-Module -Name $moduleManifestPath -Force -Verbose:$false
7+
}
8+
9+
InModuleScope azure.datafactory.tools {
10+
$testHelperPath = $PSScriptRoot | Join-Path -ChildPath 'TestHelper'
11+
Import-Module -Name $testHelperPath -Force
12+
13+
# Variables for use in tests
14+
15+
Describe 'Test-Exceptions' -Tag 'Unit' {
16+
It 'Test-ErrorNoTermination should not throw error' {
17+
{ Test-ErrorNoTermination } | Should -Not -Throw
18+
}
19+
It 'Test-ErrorNoTermination should throw error' {
20+
{ Test-ErrorTermination } | Should -Throw
21+
}
22+
It 'Test-Exception should throw error' {
23+
{ Test-Exception } | Should -Throw -ExceptionType ([System.Management.Automation.RuntimeException])
24+
}
25+
}
26+
27+
28+
29+
}

0 commit comments

Comments
 (0)