-
Notifications
You must be signed in to change notification settings - Fork 53
added build scripts and pester tests #43
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
Changes from 1 commit
42cf6a8
8a95b68
e45744a
1633c61
0acc29a
e524a63
6f5a19f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# | ||
# Copyright (c) Microsoft. All rights reserved. | ||
# Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
# | ||
|
||
param( | ||
[string[]] | ||
$Tasks | ||
) | ||
|
||
if ($MyInvocation.ScriptName -notlike '*Invoke-Build.ps1') { | ||
Invoke-Build $Tasks $MyInvocation.MyCommand.Path @PSBoundParameters | ||
return | ||
} | ||
|
||
$BuildRoot = $PSScriptRoot | ||
|
||
task Clean { | ||
exec { dotnet clean } | ||
Remove-Item -Recurse -Force src/bin -ErrorAction SilentlyContinue | ||
Remove-Item -Recurse -Force src/obj -ErrorAction SilentlyContinue | ||
|
||
# Remove the built nuget package | ||
Remove-Item -Recurse -Force package/bin -ErrorAction SilentlyContinue | ||
Remove-Item -Recurse -Force package/obj -ErrorAction SilentlyContinue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not |
||
} | ||
|
||
task Build { | ||
exec { dotnet build } | ||
exec { dotnet publish } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we pass in the configuration to use for the build and publish? |
||
Set-Location package | ||
exec { dotnet pack } | ||
TylerLeonhardt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
task Test { | ||
Set-Location test | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are assuming There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is assumed because InvokeBuild sets the location to whatever BuildRoot is set to: |
||
exec { dotnet test } | ||
Set-Location Modules | ||
Invoke-Pester | ||
TylerLeonhardt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
task . Clean, Build, Test | ||
TylerLeonhardt marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#!/usr/bin/env pwsh | ||
param( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Forgot header oops |
||
[Parameter()] | ||
[switch] | ||
$Bootstrap, | ||
|
||
[Parameter()] | ||
[switch] | ||
$Clean, | ||
|
||
[Parameter()] | ||
[switch] | ||
$Test | ||
TylerLeonhardt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
$NeededTools = @{ | ||
DotnetSdk = ".NET SDK latest" | ||
PowerShellGet = "PowerShellGet latest" | ||
TylerLeonhardt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
InvokeBuild = "InvokeBuild latest" | ||
} | ||
|
||
function needsDotnetSdk () { | ||
try { | ||
$opensslVersion = (dotnet --version) | ||
} catch { | ||
return $true | ||
} | ||
return $false | ||
} | ||
|
||
function needsPowerShellGet () { | ||
$modules = Get-Module -ListAvailable -Name PowerShellGet | Where-Object Version -gt 1.6.0 | ||
if ($modules.Count -gt 0) { | ||
return $true | ||
} | ||
return $false | ||
} | ||
|
||
function needsInvokeBuild () { | ||
if (Get-Module -ListAvailable -Name InvokeBuild) { | ||
return $false | ||
} | ||
return $true | ||
} | ||
|
||
function getMissingTools () { | ||
$missingTools = @() | ||
|
||
if (needsDotnetSdk) { | ||
$missingTools += $NeededTools.DotnetSdk | ||
} | ||
if (needsPowerShellGet) { | ||
$missingTools += $NeededTools.PowerShellGet | ||
} | ||
if (needsInvokeBuild) { | ||
$missingTools += $NeededTools.InvokeBuild | ||
} | ||
|
||
return $missingTools | ||
} | ||
|
||
function hasMissingTools () { | ||
return ((getMissingTools).Count -gt 0) | ||
} | ||
TylerLeonhardt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if ($Bootstrap) { | ||
TylerLeonhardt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$string = "Here is what your environment is missing:`n" | ||
$missingTools = getMissingTools | ||
if (($missingTools).Count -eq 0) { | ||
$string += "* nothing!`n`n Run this script without a flag to build or a -Clean to clean." | ||
} else { | ||
$missingTools | ForEach-Object {$string += "* $_`n"} | ||
} | ||
Write-Host "`n$string`n" | ||
} elseif(hasMissingTools) { | ||
Write-Host "You are missing needed tools. Run './build.ps1 -Bootstrap' to see what they are." | ||
TylerLeonhardt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else { | ||
if($Clean) { | ||
Invoke-Build Clean | ||
} | ||
|
||
Invoke-Build Build | ||
|
||
if($Test) { | ||
Invoke-Build Test | ||
} | ||
} | ||
TylerLeonhardt marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
# | ||
# Copyright (c) Microsoft. All rights reserved. | ||
# Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
# | ||
|
||
Describe 'Azure Functions PowerShell Langauge Worker Helper Module Tests' { | ||
|
||
# Helper function that tests hashtable equality | ||
function IsEqualHashtable ($h1, $h2) { | ||
# Handle nulls | ||
if (!$h1) { | ||
if(!$h2) { | ||
return $true | ||
} | ||
return $false | ||
} | ||
if (!$h1) { | ||
TylerLeonhardt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return $false | ||
} | ||
|
||
# If they don't have the same amount of key value pairs, fail early | ||
if ($h1.Keys.Count -ne $h2.Keys.Count){ | ||
TylerLeonhardt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return $false | ||
} | ||
|
||
# Check to make sure every key exists in the other and that the values are the same | ||
foreach ($key in $h1.Keys) { | ||
if (!$h2.ContainsKey($key) -or $h1[$key] -ne $h2[$key]) { | ||
return $false | ||
} | ||
} | ||
return $true | ||
} | ||
|
||
Context 'Push-OutputBinding tests' { | ||
BeforeEach { | ||
Import-Module "$PSScriptRoot/../../src/Modules/Microsoft.Azure.Functions.PowerShellWorker/Microsoft.Azure.Functions.PowerShellWorker.psd1" -Force | ||
$module = (Get-Module Microsoft.Azure.Functions.PowerShellWorker)[0] | ||
} | ||
|
||
It 'Can add a value via parameters' { | ||
$Key = 'Test' | ||
$Value = 5 | ||
|
||
Push-OutputBinding -Name $Key -Value $Value | ||
$result = & $module { $script:_OutputBindings } | ||
$result[$Key] | Should -BeExactly $Value | ||
} | ||
|
||
It 'Can add a value via pipeline - <Description>' -TestCases @( | ||
@{ | ||
InputData = @{ Foo = 1; Bar = 'Baz'} | ||
Expected = @{ Foo = 1; Bar = 'Baz'} | ||
Description = 'ValueFromPipeline' | ||
}, | ||
@{ | ||
InputData = @([PSCustomObject]@{ Name = 'Foo'; Value = 5 }, [PSCustomObject]@{ Name = 'Bar'; Value = 'Baz' }) | ||
Expected = @{ Foo = 5; Bar = 'Baz'} | ||
Description = 'ValueFromPipelineByPropertyName' | ||
}) -Test { | ||
param ( | ||
[object] $InputData, | ||
[hashtable] $Expected, | ||
[string] $Description | ||
) | ||
|
||
$InputData | Push-OutputBinding | ||
$result = & $module { $script:_OutputBindings } | ||
IsEqualHashtable $result $Expected | Should -BeTrue ` | ||
-Because 'The hashtables should be identical' | ||
} | ||
|
||
It 'Throws if you attempt to overwrite an Output binding' { | ||
Push-OutputBinding Foo 5 | ||
{ Push-OutputBinding Foo 6} | Should -Throw | ||
} | ||
|
||
It 'Can overwrite values if "-Force" is specified' { | ||
$internalHashtable = & $module { $script:_OutputBindings } | ||
Push-OutputBinding Foo 5 | ||
IsEqualHashtable @{Foo = 5} $internalHashtable | Should -BeTrue ` | ||
-Because 'The hashtables should be identical' | ||
|
||
Push-OutputBinding Foo 6 -Force | ||
IsEqualHashtable @{Foo = 6} $internalHashtable | Should -BeTrue ` | ||
-Because '-Force should let you overwrite the output binding' | ||
} | ||
} | ||
|
||
Context 'Get-OutputBinding tests' { | ||
BeforeAll { | ||
Import-Module "$PSScriptRoot/../../src/Modules/Microsoft.Azure.Functions.PowerShellWorker/Microsoft.Azure.Functions.PowerShellWorker.psd1" -Force | ||
$module = (Get-Module Microsoft.Azure.Functions.PowerShellWorker)[0] | ||
& $module { | ||
$script:_OutputBindings = @{ Foo = 1; Bar = 'Baz'; Food = 'apple'} | ||
} | ||
} | ||
|
||
It 'Can get the output binding hashmap - <Description>' -TestCases @( | ||
@{ | ||
Query = @{} | ||
Expected = @{ Foo = 1; Bar = 'Baz'; Food = 'apple'} | ||
Description = 'No name specified' | ||
}, | ||
@{ | ||
Query = @{ Name = 'Foo' } | ||
Expected = @{ Foo = 1; } | ||
Description = 'Explicit name specified' | ||
}, | ||
@{ | ||
Query = @{ Name = 'DoesNotExist' } | ||
Expected = @{} | ||
Description = 'Explicit name specified that does not exist' | ||
}, | ||
@{ | ||
Query = @{ Name = 'F*' } | ||
Expected = @{ Foo = 1; Food = 'apple' } | ||
Description = 'Wildcard name specified' | ||
}) -Test { | ||
param ( | ||
[object] $Query, | ||
[hashtable] $Expected, | ||
[string] $Description | ||
) | ||
|
||
$result = Get-OutputBinding @Query | ||
IsEqualHashtable $result $Expected | Should -BeTrue ` | ||
-Because 'The hashtables should be identical' | ||
} | ||
|
||
It 'Can use the "-Purge" flag to clear the Output bindings' { | ||
$initialState = (& $module { $script:_OutputBindings }).Clone() | ||
|
||
$result = Get-OutputBinding -Purge | ||
IsEqualHashtable $result $initialState | Should -BeTrue ` | ||
-Because 'The full hashtable should be returned' | ||
|
||
$newState = & $module { $script:_OutputBindings } | ||
IsEqualHashtable @{} $newState | Should -BeTrue ` | ||
-Because 'The OutputBindings should be empty' | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please explain what is this for? Is it for when calling
azure-functions-powershell-worker.build.ps1 task-A
directly?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you got it.
you can say
azure-functions-powershell-worker.build.ps1 Clean,Build
which will do the same thing as:
Invoke-Build Clean,Build
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then, is
$MyInvocation.MyCommand.Path @PSBoundParameters
needed here? You cannot provide more parameters other than-Tasks
when callingazure-functions-powershell-worker.build.ps1
, right?