Skip to content

Add Azure.Automation.Get module #1

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
Binary file not shown.
Binary file added Azure.Automation.Get/Azure.Automation.Get.psd1
Binary file not shown.
904 changes: 904 additions & 0 deletions Azure.Automation.Get/Azure.Automation.Get.psm1

Large diffs are not rendered by default.

Binary file not shown.
1,221 changes: 1,221 additions & 0 deletions Azure.Automation.Get/Tests/PSGetTestUtils.psm1

Large diffs are not rendered by default.

176 changes: 176 additions & 0 deletions Azure.Automation.Get/Tests/Pester.PublishRunbook.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
# This is a Pester test suite to validate the PowerShellGet cmdlets for Publish-Runbook
#
# Copyright (c) Microsoft Corporation, 2016

#if ( $PSVersionTable.PSVersion -lt '5.1' )
#{
# return
#}

Import-Module "$PSScriptRoot\PSGetTestUtils.psm1" -WarningAction SilentlyContinue

$RepositoryName = 'LocalGallery'
$SourceLocation = "$PSScriptRoot\PSGalleryTestRepo"
$RegisteredINTRepo = $false
$SystemModulesPath = Join-Path -Path $PSHOME -ChildPath 'Modules'
$ProgramFilesModulesPath = Microsoft.PowerShell.Management\Join-Path -Path $env:ProgramFiles -ChildPath "WindowsPowerShell\Modules"
$Script:RunbookFolder = "$PSScriptRoot\TestRunbooks"
$Script:TempSaveLocation = "$PSScriptRoot\TestSaveRepo"

Install-NuGetBinaries
Import-Module Azure.Automation.Get -Scope:Local -PassThru

if(-not (Test-Path -Path $SourceLocation -PathType Container))
{
$null = New-Item -Path $SourceLocation -ItemType Directory -Force
}

if(-not (Test-Path -Path $Script:TempSaveLocation -PathType Container))
{
$null = New-Item -Path $Script:TempSaveLocation -ItemType Directory -Force
}

$repo = Get-PSRepository -ErrorAction SilentlyContinue |
Where-Object {$_.SourceLocation.StartsWith($SourceLocation, [System.StringComparison]::OrdinalIgnoreCase)}
if($repo)
{
$RepositoryName = $repo.Name
}
else
{
Register-PSRepository -Name $RepositoryName -SourceLocation $SourceLocation -InstallationPolicy Trusted
$RegisteredINTRepo = $true
}

Describe "PublishValidRunbook" -Tags 'BVT'{

Context "When it's graphical runbook with manifest" {
Publish-Runbook -Path "$Script:RunbookFolder\StartAzureRMVM" -Repository $RepositoryName -Description "Azure graph runbook test" -Author "Yuting" -Version 1.0
It "Published the runbook"{
$result = Find-Runbook -Name "StartAzureRMVM" -Repository $RepositoryName | Should Not BeNullOrEmpty
}
It "Has Runbook tag and AzureAutomation Tags"{
$result = Find-Runbook -Name "StartAzureRMVM" -Repository $RepositoryName
$ResultTags = $result.Tags | Where-Object {($_ -eq 'AzureAutomation') -or
($_ -eq 'Runbook')}
$ResultTags.Count | Should BeExactly 2

}

}
Context "When it's graphical runbook without manifest" {
Publish-Runbook -Path "$Script:RunbookFolder\AzureAutomationTutorial" -Repository $RepositoryName -Description "AzureAutomationTutorial" -Author "Yuting" -Version 1.0
It "Published the runbook"{
$result = Find-Runbook -Name "AzureAutomationTutorial" -Repository $RepositoryName | Should Not BeNullOrEmpty
}
RemoveItem "$Script:RunbookFolder\AzureAutomationTutorial\*.psd1"
}

Context "When the module has versions"{
Publish-Runbook -Path "$Script:RunbookFolder\StopAzureRMVM\1.0" -Repository $RepositoryName -Description "StopAzureRMVM test folder" -Author "Yuting" -Version 1.0
It "Published the runbook"{
$result = Find-Runbook -Name "StopAzureRMVM" -Repository $RepositoryName | Should Not BeNullOrEmpty
}
Publish-Runbook -Path "$Script:RunbookFolder\StopAzureRMVM\1.1" -Repository $RepositoryName -Description "StopAzureRMVM test folder" -Author "Yuting"
It "Published the runbook with higher version"{
$result = Find-Runbook -Name "StopAzureRMVM" -Repository $RepositoryName -RequiredVersion 1.1 | Should Not BeNullOrEmpty
$runbooks = Find-Runbook -Name "StopAzureRMVM" -Repository $RepositoryName -AllVersions
$runbooks.Count | Should BeExactly 2
}
}

Context "When it's graphic workflow runbook"{
Publish-Runbook -Path "$Script:RunbookFolder\Find-EmptyResourceGroups" -Repository $RepositoryName -Description "Find-EmptyResourceGroups test workflow" -Author "Yuting" -Version 1.0
It "Published the runbook"{
$result = Find-Runbook -Name "Find-EmptyResourceGroups" -Repository $RepositoryName
$Tags = $result.Tags
$ResultTags = $result.Tags | Where-Object {($_ -eq 'GraphicalPSWFRunbook')}
$ResultTags | Should Not BeNullOrEmpty

}
}

Context "When the full path to runbook is specified"{
Publish-Runbook -Path "$Script:RunbookFolder\Hello-WorldGraphical.graphrunbook" -Repository $RepositoryName -Description "Test path to graphrunbook" -Author "Yuting" -Version 1.0
It "Published the runbook"{
$result = Find-Runbook -Name "Hello-WorldGraphical" -Repository $RepositoryName
$Tags = $result.Tags
$ResultTags = $result.Tags | Where-Object {($_ -eq 'GraphicalPSWFRunbook')}
$ResultTags | Should Not BeNullOrEmpty

}
}

AfterAll{
RemoveItem "$PSScriptRoot\PSGalleryTestRepo\*"
}
}


Describe "PublishInValidRunbook" -Tags 'BVT'{
Context "When the path is invalid" {
{ Publish-Runbook -Path "$Script:RunbookFolder\TestNonExistingPath" -Repository $RepositoryName -Description "Test non-existing path" -Author "Yuting" -Version 1.0 } | Should Throw
}
Context "When there is no .graphrunbook" {
{ Publish-Runbook -Path "$Script:RunbookFolder\TestInvalidRunbookFolder" -Repository $RepositoryName -Description "Test module folder without runbook file" -Author "Yuting" -Version 1.0 } | Should Throw
}
Context "When the graphrunbook is invalid" {
{ Publish-Runbook -Path "$Script:RunbookFolder\Invalid-GraphicalRB" -Repository $RepositoryName -Description "Invalid .graphrunbook file" -Author "Yuting" -Version 1.0 } | Should Throw
}
AfterAll{
RemoveItem "$PSScriptRoot\PSGalleryTestRepo\*"
}
}

Describe "FindRunbook" -Tags 'BVT'{
Context "Find an existing runbook" {
Publish-Runbook -Path "$Script:RunbookFolder\AzureAutomationTutorial" -Repository $RepositoryName -Description "AzureAutomationTutorial test workflow" -Author "Yuting" -Version 1.0
It "Will find the runbook"{
$runbook = Find-Runbook -Name "AzureAutomationTutorial"
$runbook | Should Not BeNullOrEmpty
}
}
Context "Find runbook that is workflow" {
Publish-Runbook -Path "$Script:RunbookFolder\Find-EmptyResourceGroups" -Repository $RepositoryName -Description "Find-EmptyResourceGroups test workflow" -Author "Yuting" -Version 1.0
It "can find the runbook with workflow tag"{
$runbook = Find-Runbook -Name "Find-EmptyResourceGroups" -Tag "Workflow" | Should Not BeNullOrEmpty
}
It "can find the runbook with Azure Automation tag"{
$runbook = Find-Runbook -Name "Find-EmptyResourceGroups" -Tag "AzureAutomation" | Should Not BeNullOrEmpty
}
}

AfterAll{
RemoveItem "$PSScriptRoot\PSGalleryTestRepo\*"
}
}

Describe "SaveRunbook" -Tags 'BVT'{
Context "Find a runbook and save it locally" {
Publish-Runbook -Path "$Script:RunbookFolder\AzureAutomationTutorial" -Repository $RepositoryName -Description "AzureAutomationTutorial test workflow" -Author "Yuting" -Version 1.0
It "Will find the runbook and save only the .graphrunbook"{
Save-Runbook -Name AzureAutomationTutorial -Path $Script:TempSaveLocation
Test-Path "$Script:TempSaveLocation\AzureAutomationTutorial.psd1" | Should Be $False
Get-Item "$Script:TempSaveLocation\AzureAutomationTutorial.graphrunbook" | Should Be $True
}
}

Context "Find a runbook base on the version and save it locally" {
Publish-Runbook -Path "$Script:RunbookFolder\StopAzureRMVM\1.0" -Repository $RepositoryName -Description "StopAzureRMVM test folder" -Author "Yuting"
Publish-Runbook -Path "$Script:RunbookFolder\StopAzureRMVM\1.1" -Repository $RepositoryName -Description "StopAzureRMVM test folder" -Author "Yuting"
It "Can find the higher version and save it"{
Save-Runbook -Name StopAzureRMVM -Path $Script:TempSaveLocation
Test-Path "$Script:TempSaveLocation\StopAzureRMVM.psd1" | Should Be $False
Get-Item "$Script:TempSaveLocation\StopAzureRMVM.graphrunbook" | Should Be $True
}
It "Can find the specified version and save it"{
Save-Runbook -Name StopAzureRMVM -Path $Script:TempSaveLocation -RequiredVersion 1.0
Get-Item "$Script:TempSaveLocation\StopAzureRMVM.graphrunbook" | Should Be $True
}
}

AfterAll{
RemoveItem "$PSScriptRoot\PSGalleryTestRepo\*"
RemoveItem "$Script:TempSaveLocation\*"
}
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#
# Module manifest for module 'PSGet_Find-EmptyResourceGroups'
#
# Generated by: Yuting
#
# Generated on: 7/21/2016
#

@{

# Script module or binary module file associated with this manifest.
# RootModule = ''

# Version number of this module.
ModuleVersion = '1.0'

# ID used to uniquely identify this module
GUID = 'bc5382b6-adeb-4e94-a07d-190b2c0f08c2'

# Author of this module
Author = 'Yuting'

# Company or vendor of this module
CompanyName = 'Unknown'

# Copyright statement for this module
Copyright = '(c) 2016 Yuting. All rights reserved.'

# Description of the functionality provided by this module
Description = 'Find-EmptyResourceGroups test workflow'

# Minimum version of the Windows PowerShell engine required by this module
# PowerShellVersion = ''

# Name of the Windows PowerShell host required by this module
# PowerShellHostName = ''

# Minimum version of the Windows PowerShell host required by this module
# PowerShellHostVersion = ''

# Minimum version of Microsoft .NET Framework required by this module
# DotNetFrameworkVersion = ''

# Minimum version of the common language runtime (CLR) required by this module
# CLRVersion = ''

# Processor architecture (None, X86, Amd64) required by this module
# ProcessorArchitecture = ''

# Modules that must be imported into the global environment prior to importing this module
# RequiredModules = @()

# Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = @()

# Script files (.ps1) that are run in the caller's environment prior to importing this module.
# ScriptsToProcess = @()

# Type files (.ps1xml) to be loaded when importing this module
# TypesToProcess = @()

# Format files (.ps1xml) to be loaded when importing this module
# FormatsToProcess = @()

# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
# NestedModules = @()

# Functions to export from this module
# FunctionsToExport = @()

# Cmdlets to export from this module
# CmdletsToExport = @()

# Variables to export from this module
# VariablesToExport = @()

# Aliases to export from this module
# AliasesToExport = @()

# DSC resources to export from this module
# DscResourcesToExport = @()

# List of all modules packaged with this module
# ModuleList = @()

# List of all files packaged with this module
FileList = 'Find-EmptyResourceGroups.psd1',
'Find-EmptyResourceGroups.graphrunbook'

# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{

PSData = @{

# Tags applied to this module. These help with module discovery in online galleries.
Tags = 'AzureAutomation','Runbook','GraphicalPSWFRunbook','Workflow'

# A URL to the license for this module.
# LicenseUri = ''

# A URL to the main website for this project.
# ProjectUri = ''

# A URL to an icon representing this module.
# IconUri = ''

# ReleaseNotes of this module
# ReleaseNotes = ''

# External dependent modules of this module
# ExternalModuleDependencies = ''

} # End of PSData hashtable

} # End of PrivateData hashtable

# HelpInfo URI of this module
# HelpInfoURI = ''

# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
# DefaultCommandPrefix = ''

}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading