Skip to content

Commit

Permalink
Merge pull request #397 from Azure-Player/issue-394
Browse files Browse the repository at this point in the history
`Test-AdfCode` failed when run on Docker image and $ConfigPath param …
  • Loading branch information
NowinskiK authored Jun 17, 2024
2 parents ff846eb + 2824a9c commit 517d2f0
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 17 deletions.
2 changes: 1 addition & 1 deletion azure.datafactory.tools.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'azure.datafactory.tools.psm1'

# Version number of this module.
ModuleVersion = '1.9.0'
ModuleVersion = '1.9.1'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.

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

## [1.9.1] - 2024-06-17
### Fixed
* `Test-AdfCode` failed when run on Docker image and $ConfigPath param is not provided #394

## [1.9.0] - 2024-03-01
### Fixed
* Fixed failure of publishing ADF when globalConfigurations exist in Factory file but Global Params does not #387
Expand Down
40 changes: 24 additions & 16 deletions public/Test-AdfCode.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ function Test-AdfCode {
$adfName = Split-Path -Path "$RootFolder" -Leaf

Write-Host "=== Loading files from location: $RootFolder ..."
if (-not (Test-Path -Path $RootFolder)) {
Write-Error "Location doesn't exist: $RootFolder"
return $result
}
$adf = Import-AdfFromFolder -FactoryName "$adfName" -RootFolder "$RootFolder" -ErrorAction "SilentlyContinue"
$adf.PublishOptions = New-AdfPublishOption
$ObjectsCount = $adf.AllObjects().Count
Expand Down Expand Up @@ -111,32 +115,36 @@ function Test-AdfCode {


Write-Host "=== Validating config files ..."
$filePattern = $null
if (!$ConfigPath) {
$filePattern = Join-Path -Path $adf.Location -ChildPath 'deployment\*'
if (!(Test-Path $filePattern)) { $filePattern = $null }
} else {
$filePattern = $ConfigPath -split ','
}

$files = Get-ChildItem -Path $filePattern -Include '*.csv','*.json'
$err = $null
$adf.PublishOptions.FailsWhenConfigItemNotFound = $True
$adf.PublishOptions.FailsWhenPathNotFound = $True
$files | ForEach-Object {
try {
$FileName = $_.FullName
Write-Host "Checking config file: $FileName..."
Update-PropertiesFromFile -adf $adf -stage $FileName -ErrorVariable err -ErrorAction 'Stop' -dryRun:$True
}
catch {
$result.ErrorCount += 1
Write-Host "ERROR: $($_.Exception.Message)" -ForegroundColor 'Red'
Write-Debug -Message $_.Exception
#$_.Exception
if ($filePattern) {
$files = Get-ChildItem -Path $filePattern -Include '*.csv','*.json'
$err = $null
$adf.PublishOptions.FailsWhenConfigItemNotFound = $True
$adf.PublishOptions.FailsWhenPathNotFound = $True
$files | ForEach-Object {
try {
$FileName = $_.FullName
Write-Host "Checking config file: $FileName..."
Update-PropertiesFromFile -adf $adf -stage $FileName -ErrorVariable err -ErrorAction 'Stop' -dryRun:$True
}
catch {
$result.ErrorCount += 1
Write-Host "ERROR: $($_.Exception.Message)" -ForegroundColor 'Red'
Write-Debug -Message $_.Exception
#$_.Exception
}
}
} else {
Write-Host "ConfigPath is not set or Location doesn't exist. Skipping config files validation."
}



$msg = "Test code completed ($ObjectsCount objects)."
if ($result.ErrorCount -gt 0) { $msg = "Test code failed." }
Expand Down
26 changes: 26 additions & 0 deletions test/Test-AdfCode.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,31 @@ InModuleScope azure.datafactory.tools {
}


Describe 'Test-AdfCode' -Tag 'Unit' {
It 'Should not throw an error when wrong path to DF is provided' {
$DataFactoryName = "nullPathFactory"
$RootFolder = Join-Path -Path $PSScriptRoot -ChildPath $DataFactoryName
{
$script:res = Test-AdfCode -RootFolder $RootFolder -ConfigPath $null
} | Should -Not -Throw
}
}

Describe 'Test-AdfCode' -Tag 'Unit' {
It 'Should not throw an error when Get-ChildItem Path parameter is null' {
$DataFactoryName = "adf2"
$RootFolder = Join-Path -Path $PSScriptRoot -ChildPath $DataFactoryName

# Mock Get-ChildItem cmdlet to raise an error when Path parameter is null
Mock Get-ChildItem {
param($Path)
throw 'Cannot process argument because the value of argument "path" is not valid. Change the value of the "path" argument and run the operation again.'
} -ParameterFilter {$Path -eq $null}

{
$script:res = Test-AdfCode -RootFolder $RootFolder -ConfigPath $null
} | Should -Not -Throw
}
}

}

0 comments on commit 517d2f0

Please sign in to comment.