├── .gitattributes ├── Garuda ├── Chakra │ ├── chakra.ps1 │ ├── resultServer.ps1 │ └── results.ps1 ├── Garuda.psd1 ├── Garuda.psm1 ├── Private │ ├── Get-TestParameter.ps1 │ ├── Get-TestParameterJson.ps1 │ └── New-DscConfigurationScript.ps1 ├── Public │ ├── Get-GarudaTestGroup.ps1 │ ├── Get-GarudaTestGroupParameter.ps1 │ ├── Get-GarudaTestGroupResult.ps1 │ ├── New-GarudaTestGroup.ps1 │ ├── Publish-GarudaTestPackage.ps1 │ └── Update-GarudaTestParameter.ps1 └── TestLib │ ├── Number.Tests.ps1 │ ├── Strings.Tests.ps1 │ ├── Tests.Parameters.Json │ └── testGroup.json ├── LICENSE ├── README.md ├── docs └── index.md ├── images ├── Garuda.png ├── logo.png └── logo.vsdx └── tests ├── Private └── Garuda.Private.Test.ps1 └── Public └── Garuda.Public.Test.ps1 /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /Garuda/Chakra/chakra.ps1: -------------------------------------------------------------------------------- 1 | # Import Pester module 2 | Import-Module -Name Pester -Force 3 | 4 | # load test parameters 5 | $testPath = 'C:\testLib' 6 | $testParameters = Get-Content -Path "$testPath\testParameters.json" -Raw | ConvertFrom-Json 7 | 8 | $tests = $testParameters.PSObject.Properties.Name.Where({$_ -ne 'GroupName'}) 9 | $testGroup = $testParameters.GroupName 10 | 11 | $testResults = [Ordered]@{ 12 | TestGroup = $testParameters.GroupName 13 | Timestamp = (Get-Date -Format 'MM-dd-yyyyHHmmss') 14 | } 15 | 16 | foreach ($test in $tests) 17 | { 18 | $testScript = "${testPath}\${test}.tests.ps1" 19 | 20 | # retireve parameters for test 21 | $tmpParameters = $testParameters.$test 22 | $parameters = @{} 23 | foreach ($param in $tmpParameters.PSObject.Properties.Name) 24 | { 25 | $parameters.Add($param, $tmpParameters.$param) 26 | } 27 | 28 | # invoke test script 29 | $tmpResults = Invoke-Pester @{ 30 | Path = $testScript 31 | Parameters = $parameters 32 | } -PassThru 33 | 34 | # add to the results object 35 | $testResults.Add($test, $tmpResults) 36 | } 37 | 38 | # Export the results to JSON; rename current to time-stamped json and save as current.json 39 | $resultPath = "$env:ProgramData\Chakra" 40 | if (-not (Test-Path -Path $resultPath)) 41 | { 42 | $null = New-Item -Path $resultPath -ItemType Directory -Force 43 | } 44 | 45 | 46 | if (Test-Path -Path "${resultPath}\${testGroup}.current.json") 47 | { 48 | # load the current json and read its timestamp 49 | $tmpResultObject = Get-Content -Path "${resultPath}\${testGroup}.current.json" -Raw | ConvertFrom-Json 50 | $tmpTimeStamp = $tmpResultObject.Timestamp 51 | 52 | # rename current.JSON to .json 53 | Rename-Item -Path "${resultPath}\${testGroup}.current.json" -NewName "${resultPath}\${testGroup}.${tmpTimeStamp}.json" 54 | } 55 | 56 | # save the current results to current.json 57 | $testResults | ConvertTo-Json -Depth 100 | Out-File -FilePath "${resultPath}\${testGroup}.current.json" -Force -------------------------------------------------------------------------------- /Garuda/Chakra/resultServer.ps1: -------------------------------------------------------------------------------- 1 | $chakraPath = 'C:\testlib\chakra' 2 | 3 | Import-Module Polaris -Force 4 | 5 | # load routes 6 | . "$chakraPath\results.ps1" 7 | 8 | Start-Polaris -Port 8080 -HostName $env:computername -------------------------------------------------------------------------------- /Garuda/Chakra/results.ps1: -------------------------------------------------------------------------------- 1 | New-PolarisGetRoute -Path "/results/:groupName?" -Scriptblock { 2 | $chakraResultPath = "$env:ProgramData\Chakra" 3 | 4 | $Response.SetContentType('application/json') 5 | 6 | if ($Request.Parameters.groupName) 7 | { 8 | $groupName = $Request.Parameters.groupName 9 | $resultPath = "${chakraResultPath}\${groupName}.current.json" 10 | $resultJson = Get-Content -Path $resultPath 11 | } 12 | else 13 | { 14 | $tmpResultJson = @() 15 | $allCurrentResultFiles = Get-ChildItem -Path $chakraResultPath *.current.json 16 | 17 | foreach ($resultFile in $allCurrentResultFiles) 18 | { 19 | $result = Get-Content -Path $resultFile.FullName -Raw | ConvertFrom-Json 20 | $tmpResultJson += $result 21 | } 22 | 23 | $resultJson = $tmpResultJson | ConvertTo-Json 24 | } 25 | 26 | $Response.Send($resultJson) 27 | } -------------------------------------------------------------------------------- /Garuda/Garuda.psd1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/Garuda/f1168fd4ccaa5a3f5b474863c28c06f337b81819/Garuda/Garuda.psd1 -------------------------------------------------------------------------------- /Garuda/Garuda.psm1: -------------------------------------------------------------------------------- 1 | # Load Dependent modules 2 | # $privatePath = Join-Path -Path $PSScriptRoot -ChildPath 'Private' 3 | 4 | #Get public and private function definition files 5 | $Public = @( Get-ChildItem -Path $PSScriptRoot\Public\ -Filter *.ps1 -Recurse -ErrorAction SilentlyContinue ) 6 | $Private = @( Get-ChildItem -Path $PSScriptRoot\Private\*.ps1 -ErrorAction SilentlyContinue ) 7 | 8 | #Dot source the files 9 | Foreach($import in @($Public + $Private)) 10 | { 11 | Try 12 | { 13 | . $import.fullname 14 | } 15 | Catch 16 | { 17 | Write-Error -Message "Failed to import function $($import.fullname): $_" 18 | } 19 | } 20 | 21 | Export-ModuleMember -Function $Public.Basename 22 | -------------------------------------------------------------------------------- /Garuda/Private/Get-TestParameter.ps1: -------------------------------------------------------------------------------- 1 | function Get-TestParameter 2 | { 3 | [CmdletBinding()] 4 | param 5 | ( 6 | [Parameter(Mandatory = $true)] 7 | [String] 8 | $ScriptPath 9 | ) 10 | 11 | $scriptContent = Get-Content $ScriptPath -Raw 12 | 13 | $tokens = $null 14 | $errors = $null 15 | 16 | $ast = [Management.Automation.Language.Parser]::ParseInput($scriptContent, [ref]$tokens, [ref]$errors) 17 | $parameters = $ast.FindAll({ $args[0] -is [System.Management.Automation.Language.ParameterAst] }, $true) 18 | 19 | $paramterMetaData = @() 20 | foreach ($parameter in $parameters) 21 | { 22 | $parameterHash = @{ 23 | Name = $parameter.Name.VariablePath.UserPath 24 | Type = $parameter.StaticType.Name 25 | DefaultValue = $parameter.DefaultValue.Value 26 | HelpMessage = $parameter.Attributes.NamedArguments.Where({$_.ArgumentName -eq 'HelpMessage'}).Argument.Value | Select -First 1 27 | ParameterSet = @($parameter.Attributes.NamedArguments.Where({$_.ArgumentName -eq 'ParameterSetName'}).Argument.Value) 28 | IsMandatory = [bool]($parameter.Attributes.NamedArguments.Where({$_.ArgumentName -eq 'Mandatory'}).Argument.Extent.text) 29 | } 30 | 31 | $paramterMetaData += $parameterHash 32 | } 33 | 34 | return $paramterMetaData 35 | } 36 | -------------------------------------------------------------------------------- /Garuda/Private/Get-TestParameterJson.ps1: -------------------------------------------------------------------------------- 1 | function Get-TestParameterJson 2 | { 3 | [CmdletBinding()] 4 | param 5 | ( 6 | [Parameter(Mandatory = $true)] 7 | [String] 8 | $TestLibPath 9 | ) 10 | 11 | $testParameterJsonPath = "${testLibPath}\Tests.Parameters.Json" 12 | 13 | if (Test-Path -Path $testLibPath) 14 | { 15 | $testParametersHash = [Ordered]@{} 16 | $allTestScripts = Get-ChildItem -Path $testLibPath *.tests.ps1 17 | foreach ($testScript in $allTestScripts) 18 | { 19 | $scriptName = $testScript.BaseName -replace '.Tests' 20 | $scriptParameters = Get-TestParameter -ScriptPath $testScript.FullName 21 | $testParametersHash.Add($scriptName, $scriptParameters) 22 | } 23 | $testParametersHash | ConvertTo-Json -Depth 100 | Out-File -FilePath $TestParameterJsonPath -Force 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Garuda/Private/New-DscConfigurationScript.ps1: -------------------------------------------------------------------------------- 1 | function New-DscConfigurationScript 2 | { 3 | [CmdletBinding()] 4 | param 5 | ( 6 | [Parameter(Mandatory = $true)] 7 | [String[]] 8 | $ComputerName, 9 | 10 | [Parameter(Mandatory = $true)] 11 | [String] 12 | $ParameterManifestPath, 13 | 14 | [Parameter(Mandatory = $true)] 15 | [String] 16 | $ModuleRepositoryPath, 17 | 18 | [Parameter(Mandatory = $true)] 19 | [String] 20 | $ModuleRepositoryName, 21 | 22 | [Parameter(Mandatory = $true)] 23 | [String] 24 | $SharePath, 25 | 26 | [Parameter(Mandatory = $true)] 27 | [String] 28 | $TestGroupName 29 | ) 30 | 31 | [System.Text.StringBuilder] $sb = new-object System.Text.StringBuilder 32 | $testLibPath = "$(Split-Path -Path $PSScriptRoot -Parent)\TestLib" 33 | $testParametersJson = Get-Content -Path "$testLibPath\Tests.Parameters.json" -Raw | ConvertFrom-Json 34 | 35 | #Add configuration block - Start 36 | $null = $sb.AppendFormat('{0} "{1}"', 'Configuration', 'GarudaConfiguration') 37 | $null = $sb.AppendLine() 38 | $null = $sb.AppendLine('{') 39 | 40 | $null = $sb.AppendLine('param') 41 | $null = $sb.AppendLine('(') 42 | 43 | # iterate and add all pscredential parameters if available 44 | $testParameters = Get-Content -Path $ParameterManifestPath -Raw | ConvertFrom-Json 45 | $tests = $testParameters.PSObject.Properties.Name 46 | 47 | $allCredParams = @() 48 | $allCredHash = @{} 49 | foreach ($test in $tests) 50 | { 51 | foreach ($param in $testParameters.$test.PSObject.Properties.Name) 52 | { 53 | $parameterType = "[$($testParametersJson.$test.Where({$_.Name -eq $param}).Type)]" 54 | if ($parameterType -eq '[psCredential]') 55 | { 56 | if ($allCredParams -notcontains $param) 57 | { 58 | $allCredParams += $param 59 | $allCredHash.Add($param, $testParameters.$test.$param) 60 | } 61 | } 62 | } 63 | } 64 | 65 | $addedParams = @() 66 | 67 | foreach ($param in $allCredParams) 68 | { 69 | if ($addedParams -notcontains $param) 70 | { 71 | $addedParams += $param 72 | $parameterName = $param 73 | 74 | $null = $sb.AppendLine('[Parameter(Mandatory = $true)]') 75 | $null = $sb.AppendLine($parameterType) 76 | $null = $sb.AppendFormat('${0}', $parameterName) 77 | 78 | if ($addedParams.Count -lt $allCredParams.count) 79 | { 80 | $null = $sb.Append(',') 81 | $null = $sb.AppendLine() 82 | $null = $sb.AppendLine() 83 | } 84 | else 85 | { 86 | $null = $sb.AppendLine() 87 | } 88 | } 89 | } 90 | 91 | $null = $sb.AppendLine(')') 92 | $null = $sb.AppendLine() 93 | 94 | #Add Import-DscResource commands 95 | $null = $sb.AppendLine('Import-DscResource -ModuleName PowerShellGet -ModuleVersion 2.1.4') 96 | $null = $sb.AppendLine('Import-DscResource -ModuleName GraniResource -ModuleVersion 3.7.11.0') 97 | $null = $sb.AppendLine('Import-DscResource -ModuleName ComputerManagementDsc -ModuleVersion 6.4.0.0') 98 | $null = $sb.AppendLine('Import-DscResource -ModuleName PSDesiredStateConfiguration') 99 | $null = $sb.AppendLine() 100 | 101 | # Add nodes 102 | $null = $sb.AppendLine('Node $AllNodes.NodeName {') 103 | 104 | # Add PowerShell Repository 105 | $null = $sb.AppendFormat("PSRepository {0}",$ModuleRepositoryName) 106 | $null = $sb.AppendLine() 107 | $null = $sb.AppendLine('{') 108 | $null = $sb.AppendFormat("Name = '{0}'",$ModuleRepositoryName) 109 | $null = $sb.AppendLine() 110 | $null = $sb.AppendFormat("PublishLocation = '{0}'",$ModuleRepositoryPath) 111 | $null = $sb.AppendLine() 112 | $null = $sb.AppendFormat("SourceLocation = '{0}'",$ModuleRepositoryPath) 113 | $null = $sb.AppendLine() 114 | $null = $sb.AppendLine("InstallationPolicy = 'Trusted'") 115 | $null = $sb.AppendLine('}') 116 | $null = $sb.AppendLine() 117 | 118 | # Add Pester module 119 | $null = $sb.AppendFormat("PSModule {0}",'Pester') 120 | $null = $sb.AppendLine() 121 | $null = $sb.AppendLine('{') 122 | $null = $sb.AppendFormat("Name = '{0}'",'Pester') 123 | $null = $sb.AppendLine() 124 | $null = $sb.AppendFormat("Repository = '{0}'",$ModuleRepositoryName) 125 | $null = $sb.AppendLine() 126 | $null = $sb.AppendFormat("SkipPublisherCheck = {0}",'$true') 127 | $null = $sb.AppendLine() 128 | $null = $sb.AppendFormat("Force = {0}",'$true') 129 | $null = $sb.AppendLine() 130 | $null = $sb.AppendLine('}') 131 | $null = $sb.AppendLine() 132 | 133 | # Add Polaris module 134 | $null = $sb.AppendFormat("PSModule {0}",'Polaris') 135 | $null = $sb.AppendLine() 136 | $null = $sb.AppendLine('{') 137 | $null = $sb.AppendFormat("Name = '{0}'",'Polaris') 138 | $null = $sb.AppendLine() 139 | $null = $sb.AppendFormat("Repository = '{0}'",$ModuleRepositoryName) 140 | $null = $sb.AppendLine() 141 | $null = $sb.AppendFormat("SkipPublisherCheck = {0}",'$true') 142 | $null = $sb.AppendLine() 143 | $null = $sb.AppendFormat("Force = {0}",'$true') 144 | $null = $sb.AppendLine() 145 | $null = $sb.AppendLine('}') 146 | $null = $sb.AppendLine() 147 | 148 | # Copy the test library, configuration file, and 149 | $null = $sb.AppendFormat("File {0}",'TestLibrary') 150 | $null = $sb.AppendLine() 151 | $null = $sb.AppendLine('{') 152 | $null = $sb.AppendFormat("SourcePath = '{0}'", "$SharePath\TestLib") 153 | $null = $sb.AppendLine() 154 | $null = $sb.AppendFormat("DestinationPath = '{0}'", "C:\TestLib") 155 | $null = $sb.AppendLine() 156 | $null = $sb.AppendFormat("Recurse = {0}", '$true') 157 | $null = $sb.AppendLine() 158 | $null = $sb.AppendFormat("Type = '{0}'", 'Directory') 159 | $null = $sb.AppendLine() 160 | $null = $sb.AppendFormat("Force = {0}", '$true') 161 | $null = $sb.AppendLine() 162 | $null = $sb.AppendLine('}') 163 | 164 | # Add Credential Vault entries 165 | foreach ($cred in $allCredParams) 166 | { 167 | $null = $sb.AppendFormat("cCredentialManager {0}", $cred) 168 | $null = $sb.AppendLine() 169 | $null = $sb.AppendLine('{') 170 | $null = $sb.AppendFormat("InstanceIdentifier = '{0}'",$cred) 171 | $null = $sb.AppendLine() 172 | $null = $sb.AppendFormat("Target = '{0}'",$cred) 173 | $null = $sb.AppendLine() 174 | $null = $sb.AppendFormat('Credential = ${0}',$cred) 175 | $null = $sb.AppendLine() 176 | $null = $sb.AppendLine("Ensure = 'Present'") 177 | $null = $sb.AppendLine('}') 178 | $null = $sb.AppendLine() 179 | } 180 | 181 | #Add Scheduled Task to invoke Chakra Engine 182 | $null = $sb.AppendFormat("ScheduledTask '{0}'",$TestGroupName) 183 | $null = $sb.AppendLine() 184 | $null = $sb.AppendLine('{') 185 | $null = $sb.AppendFormat("TaskName = '{0}'", $TestGroupName) 186 | $null = $sb.AppendLine() 187 | $null = $sb.AppendFormat("ActionExecutable = '{0}'", 'C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe') 188 | $null = $sb.AppendLine() 189 | $null = $sb.AppendFormat("ActionArguments = '{0}'", "-File `"C:\TestLib\Chakra\chakra.ps1`"") 190 | $null = $sb.AppendLine() 191 | $null = $sb.AppendFormat("ScheduleType = '{0}'", 'Daily') 192 | $null = $sb.AppendLine() 193 | $null = $sb.AppendFormat("RepetitionDuration = '{0}'", 'Indefinitely') 194 | $null = $sb.AppendLine() 195 | $null = $sb.AppendLine('}') 196 | 197 | # Close Node block 198 | $null = $sb.AppendLine('}') 199 | 200 | #Close Configuration Block 201 | $null = $sb.AppendLine('}') 202 | 203 | # Add Configuration Data 204 | $null = $sb.AppendLine() 205 | $null = $sb.AppendLine('$configData = @{') 206 | $null = $sb.AppendLine('AllNodes = @(') 207 | $null = $sb.AppendLine('@{') 208 | $null = $sb.AppendLine("NodeName = '*'") 209 | $null = $sb.AppendFormat('PSDscAllowPlainTextPassword = {0}','$true') 210 | $null = $sb.AppendLine() 211 | $null = $sb.AppendLine('},') 212 | 213 | $nodeCount = 1 214 | foreach ($node in $ComputerName) 215 | { 216 | $null = $sb.AppendLine('@{') 217 | $null = $sb.AppendFormat('NodeName = "{0}"', $node) 218 | $null = $sb.AppendLine() 219 | if ($nodeCount -lt $ComputerName.Count) 220 | { 221 | $null = $sb.AppendLine('},') 222 | $nodeCount += 1 223 | } 224 | else 225 | { 226 | $null = $sb.AppendLine('}') 227 | } 228 | } 229 | $null = $sb.AppendLine(')') 230 | $null = $sb.AppendLine('}') 231 | 232 | # Add the credentials 233 | $credentialString = '' 234 | foreach ($cred in $allCredHash.keys) 235 | { 236 | $null = $sb.AppendLine() 237 | $null = $sb.AppendFormat("`${0}pwd = ConvertTo-SecureString '{1}' -AsPlainText -Force",$cred,$allCredHash.$cred.Password) 238 | $null = $sb.AppendLine() 239 | $null = $sb.AppendFormat('${0} = New-Object System.Management.Automation.PSCredential ("{1}", ${2}pwd)',$cred, $allCredHash.$cred.UserName,$cred) 240 | $null = $sb.AppendLine() 241 | 242 | $credentialString += "-{0} `${1} " -f $cred, $cred 243 | } 244 | 245 | # Add configuraton compile command 246 | $null = $sb.AppendLine() 247 | $null = $sb.AppendFormat('GarudaConfiguration -ConfigurationData $configData -OutputPath "$env:Temp\GarudaConfiguration" ') 248 | if ($credentialString) 249 | { 250 | $null = $sb.AppendLine($credentialString) 251 | } 252 | else 253 | { 254 | $null = $sb.AppendLine() 255 | } 256 | 257 | return $sb.ToString() 258 | } 259 | -------------------------------------------------------------------------------- /Garuda/Public/Get-GarudaTestGroup.ps1: -------------------------------------------------------------------------------- 1 | function Get-GarudaTestGroup 2 | { 3 | [CmdletBinding(DefaultParameterSetName = 'Group')] 4 | param 5 | ( 6 | [Parameter(ParameterSetName = 'Group')] 7 | [Parameter(Mandatory = $true,ParameterSetName = 'Copy')] 8 | [String] 9 | $GroupName, 10 | 11 | [Parameter(Mandatory = $true,ParameterSetName = 'Copy')] 12 | [String] 13 | $ParameterManifestPath 14 | ) 15 | 16 | $testLibPath = "$(Split-Path -Path $PSScriptRoot -Parent)\TestLib" 17 | $testGroupJson = "$testLibPath\testGroup.json" 18 | if (Test-Path -Path $testGroupJson) 19 | { 20 | $testGroups = Get-Content -Path $testGroupJson -Raw | ConvertFrom-Json 21 | 22 | if ($PSCmdlet.ParameterSetName -eq 'Copy') 23 | { 24 | $testGroupParameterJson = Get-GarudaTestGroupParameter -GroupName $GroupName | ConvertTo-Json -Depth 99 25 | $testGroupParameterJson | Out-File -FilePath $ParameterManifestPath -Force 26 | } 27 | else 28 | { 29 | if ($GroupName) 30 | { 31 | return $testGroups.Where({$_.Name -eq $GroupName}) 32 | } 33 | else 34 | { 35 | return $testGroups 36 | } 37 | } 38 | } 39 | else 40 | { 41 | Write-Warning -Message "$testGroupJson does not exist." 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Garuda/Public/Get-GarudaTestGroupParameter.ps1: -------------------------------------------------------------------------------- 1 | function Get-GarudaTestGroupParameter 2 | { 3 | [CmdletBinding(DefaultParameterSetName = 'TestGroup')] 4 | param 5 | ( 6 | [Parameter(ParameterSetName = 'TestGroup',Mandatory = $true)] 7 | [Parameter(ParameterSetName = 'Tests')] 8 | [string] 9 | $GroupName, 10 | 11 | [Parameter(ParameterSetName = 'TestGroup',Mandatory = $true)] 12 | [Parameter(ParameterSetName = 'Tests',Mandatory = $true)] 13 | [string] 14 | $SaveAs 15 | ) 16 | 17 | DynamicParam 18 | { 19 | $testLibPath = "$(Split-Path -Path $PSScriptRoot -Parent)\TestLib" 20 | $testCollection = Get-ChildItem -Recurse $testLibPath *.Tests.PS1 | 21 | Select-Object -ExpandProperty BaseName | ForEach-Object { $_.replace('.Tests','') } 22 | 23 | $attribute = New-Object System.Management.Automation.ParameterAttribute 24 | $attribute.Position = 3 25 | $attribute.Mandatory = $false 26 | $attribute.ParameterSetName = 'Tests' 27 | $attribute.HelpMessage = "Select the tests for which the configuration data needs to be generated" 28 | 29 | $attributeCollection = new-object System.Collections.ObjectModel.Collection[System.Attribute] 30 | $attributeCollection.Add($attribute) 31 | 32 | $validateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($testCollection) 33 | $attributeCollection.Add($validateSetAttribute) 34 | 35 | #add our paramater specifying the attribute collection 36 | $param = New-Object System.Management.Automation.RuntimeDefinedParameter('Tests', [String[]], $attributeCollection) 37 | 38 | #expose the name of our parameter 39 | $paramDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary 40 | $paramDictionary.Add('Tests', $param) 41 | return $paramDictionary 42 | } 43 | 44 | process { 45 | switch ($PSCmdlet.ParameterSetName) 46 | { 47 | "TestGroup" { 48 | # Get all tests for the group 49 | $testGroupJsonPath = "$testLibPath\testGroup.json" 50 | if (Test-Path -Path $testGroupJsonPath) 51 | { 52 | $testGroupJson = Get-Content -Path $testGroupJsonPath -Raw | ConvertFrom-Json 53 | if ($testGroupJson.where({$_.Name -eq $GroupName})) 54 | { 55 | $selectedTests = $testGroupJson.where({$_.Name -eq $GroupName}).Tests 56 | } 57 | } 58 | } 59 | 60 | "Tests" { 61 | $selectedTests = $PSBoundParameters['tests'] 62 | } 63 | } 64 | 65 | $testParameters = [Ordered]@{ 66 | GroupName = $GroupName 67 | } 68 | 69 | $testParametersJson = Get-Content -Path "$testLibPath\Tests.Parameters.Json" -Raw | ConvertFrom-Json 70 | foreach ($test in $selectedTests) 71 | { 72 | # Get the test parameters and create the object 73 | $parameters = [Ordered]@{} 74 | $requiredParameters = $testParametersJson.$test 75 | foreach ($parameter in $requiredParameters) 76 | { 77 | if ($parameter.Type -eq 'String[]' -or $parameter.Type -eq 'int32[]') 78 | { 79 | if ($null -ne $param.DefaultValue) 80 | { 81 | $defaultValue = @($parameter.DefaultValue) 82 | } 83 | else 84 | { 85 | $defaultValue = @() 86 | } 87 | } 88 | elseif ($parameter.Type -eq 'psCredential') 89 | { 90 | $defaultValue = [Ordered]@{ 91 | UserName = '' 92 | Password = '' 93 | } 94 | } 95 | else 96 | { 97 | if ($null -ne $parameter.DefaultValue) 98 | { 99 | $defaultValue = $parameter.DefaultValue 100 | } 101 | else 102 | { 103 | $defaultValue = '' 104 | } 105 | } 106 | $parameters.Add($parameter.Name,$defaultValue) 107 | } 108 | $testParameters.Add($test, $parameters) 109 | } 110 | 111 | $testParameters | ConvertTo-Json | Out-File -FilePath $SaveAs -Force 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /Garuda/Public/Get-GarudaTestGroupResult.ps1: -------------------------------------------------------------------------------- 1 | function Get-GarudaTestGroupResult 2 | { 3 | [CmdletBinding()] 4 | param 5 | ( 6 | [Parameter(Mandatory = $true)] 7 | [String] 8 | $ComputerName, 9 | 10 | [Parameter()] 11 | [String] 12 | $TestGroupName 13 | ) 14 | 15 | $url = "http://${ComputerName}:8080/results/" 16 | 17 | if ($TestGroupName) 18 | { 19 | $url += "$TestGroupName" 20 | } 21 | 22 | $results = Invoke-RestMethod -Uri $url -UseBasicParsing -Verbose 23 | return $results 24 | } -------------------------------------------------------------------------------- /Garuda/Public/New-GarudaTestGroup.ps1: -------------------------------------------------------------------------------- 1 | function New-GarudaTestGroup 2 | { 3 | [CmdletBinding()] 4 | param 5 | ( 6 | [Parameter(Mandatory = $true)] 7 | [string] 8 | $GroupName, 9 | 10 | [Parameter(Mandatory = $true)] 11 | [string] 12 | $GroupDescription 13 | ) 14 | 15 | DynamicParam 16 | { 17 | $testLibPath = "$(Split-Path -Path $PSScriptRoot -Parent)\TestLib" 18 | $testCollection = Get-ChildItem -Recurse $testLibPath *.Tests.PS1 | 19 | Select-Object -ExpandProperty BaseName | ForEach-Object { $_.replace('.Tests','') } 20 | 21 | $attribute = New-Object System.Management.Automation.ParameterAttribute 22 | $attribute.Position = 3 23 | $attribute.Mandatory = $true 24 | $attribute.HelpMessage = "Select the tests that you want to be in the Chakra group" 25 | 26 | $attributeCollection = new-object System.Collections.ObjectModel.Collection[System.Attribute] 27 | $attributeCollection.Add($attribute) 28 | 29 | $validateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($testCollection) 30 | $attributeCollection.Add($validateSetAttribute) 31 | 32 | #add our paramater specifying the attribute collection 33 | $param = New-Object System.Management.Automation.RuntimeDefinedParameter('Tests', [String[]], $attributeCollection) 34 | 35 | #expose the name of our parameter 36 | $paramDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary 37 | $paramDictionary.Add('Tests', $param) 38 | return $paramDictionary 39 | } 40 | 41 | Process { 42 | $existingGroups = Get-GarudaTestGroup 43 | if ($existingGroups.Name -notcontains $GroupName) 44 | { 45 | $testGroupObject = [PSCustomObject]@{ 46 | Name = $GroupName 47 | Description = $GroupDescription 48 | Tests = $PSBoundParameters['tests'] 49 | } 50 | 51 | $testGroupJsonPath = "$testLibPath\testGroup.json" 52 | if (Test-Path -Path $testGroupJsonPath) 53 | { 54 | $groupJsonObj = Get-Content -Path $testGroupJsonPath -raw | ConvertFrom-Json 55 | $groupJsonObj += $testGroupObject 56 | } 57 | else 58 | { 59 | $groupJsonObj = @( 60 | $testGroupObject 61 | ) 62 | } 63 | 64 | ConvertTo-Json -InputObject $groupJsonObj | Out-File -FilePath $testGroupJsonPath -Force 65 | return $groupJsonObj 66 | } 67 | else 68 | { 69 | throw 'A test group with specified name already exists.' 70 | } 71 | 72 | # Generate the test group parameters 73 | # $testGroupParameterJsonPath = "$testLibPath\$GroupName.parameters.json" 74 | # $testGroupParameter = Get-GarudaTestGroupParameter -GroupName $GroupName 75 | 76 | #ConvertTo-Json -InputObject $testGroupParameter | Out-File -FilePath $testGroupParameterJsonPath -Force 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Garuda/Public/Publish-GarudaTestPackage.ps1: -------------------------------------------------------------------------------- 1 | function Publish-GarudaTestPackage 2 | { 3 | [CmdletBinding()] 4 | param 5 | ( 6 | [Parameter(Mandatory = $true)] 7 | [String[]] 8 | $ComputerName, 9 | 10 | [Parameter(Mandatory = $true)] 11 | [String] 12 | $SharePath, 13 | 14 | [Parameter(Mandatory = $true)] 15 | [String] 16 | $TestGroupName, 17 | 18 | [Parameter(Mandatory = $true)] 19 | [String] 20 | $ParameterManifestPath, 21 | 22 | [Parameter(Mandatory = $true)] 23 | [String] 24 | $ModuleRepositoryPath, 25 | 26 | [Parameter(Mandatory = $true)] 27 | [String] 28 | $ModuleRepositoryName, 29 | 30 | [Parameter()] 31 | [Switch] 32 | $DoNotEnact 33 | ) 34 | 35 | Process { 36 | $testLibPath = "$(Split-Path -Path $PSScriptRoot -Parent)\TestLib" 37 | 38 | # Copy the tests scripts 39 | $tests = (Get-GarudaTestGroup -GroupName $TestGroupName).Tests 40 | if (-not (Test-Path -Path "$SharePath\TestLib")) 41 | { 42 | $null = New-Item -Path "$SharePath\TestLib" -ItemType Directory -Force 43 | } 44 | 45 | # Copy Chakra script 46 | Copy-Item -Path "$(Split-Path -Path $PSScriptRoot -Parent)\Chakra" -Recurse -Destination "$SharePath\TestLib" -Force 47 | 48 | foreach ($test in $tests) 49 | { 50 | Copy-Item -Path "$testLibPath\${test}.Tests.ps1" -Destination "$SharePath\TestLib" -Force 51 | } 52 | 53 | # Copy the test parameter manifest 54 | Copy-Item -Path $ParameterManifestPath -Destination "$SharePath\TestLib\testParameters.json" -Force 55 | 56 | # Generate Config.ps1 57 | # Contains configuration data and all resource configuration 58 | $configurationScript = New-DscConfigurationScript -ComputerName $ComputerName -ParameterManifestPath $ParameterManifestPath -ModuleRepositoryPath $ModuleRepositoryPath -ModuleRepositoryName $ModuleRepositoryName -SharePath $SharePath -TestGroupName $TestGroupName 59 | 60 | if ($DoNotEnact) 61 | { 62 | # return configuration script text 63 | return $configurationScript 64 | } 65 | else 66 | { 67 | # compile and enact the configuration script 68 | # save the file to a temporary location 69 | Out-File -InputObject $configurationScript -FilePath "$env:Temp\config.ps1" -Force 70 | . "$env:Temp\config.ps1" 71 | 72 | Start-DscConfiguration -Path "$env:Temp\GarudaConfiguration" -Verbose -Wait -Force 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Garuda/Public/Update-GarudaTestParameter.ps1: -------------------------------------------------------------------------------- 1 | function Update-GarudaTestParameter 2 | { 3 | [CmdletBinding()] 4 | param 5 | ( 6 | 7 | ) 8 | 9 | $testLibPath = "$(Split-Path -Path $PSScriptRoot -Parent)\TestLib" 10 | Get-TestParameterJson -TestLibPath $testLibPath 11 | } 12 | -------------------------------------------------------------------------------- /Garuda/TestLib/Number.Tests.ps1: -------------------------------------------------------------------------------- 1 | [CmdletBinding()] 2 | param 3 | ( 4 | [Parameter(Mandatory = $true)] 5 | [Int32] 6 | $Number1, 7 | 8 | [Parameter(Mandatory = $true)] 9 | [Int32] 10 | $Number2 11 | ) 12 | 13 | Describe 'This is the first number check' -Tags Sum { 14 | Context 'This is a negative sum context' { 15 | It 'The sum should be less than 20' { 16 | $Number1 + $Number2 | Should -BeLessThan 20 17 | } 18 | 19 | It 'The sum should be greater than 10' { 20 | $Number1 + $Number2 | Should -BeGreaterThan 10 21 | } 22 | } 23 | } 24 | 25 | Describe 'This is the second number check' -Tags Subtract { 26 | Context 'This is a negative subtract context' { 27 | It 'Number 2 should be greater than Number 1' { 28 | $Number2 | Should -BeGreaterThan $Number1 29 | } 30 | 31 | It 'The difference should be less than 5' { 32 | $Number2 - $Number1 | Should -BeLessThan 5 33 | } 34 | 35 | It 'The differnce should be greater than 2' { 36 | $Number2 - $Number1 | Should -BeGreaterThan 2 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Garuda/TestLib/Strings.Tests.ps1: -------------------------------------------------------------------------------- 1 | [CmdletBinding()] 2 | param 3 | ( 4 | [Parameter(Mandatory = $true)] 5 | [String] 6 | $String1, 7 | 8 | [Parameter(Mandatory = $true)] 9 | [String] 10 | $String2 11 | ) 12 | 13 | Describe 'String Checks' -Tags StringIntegrity { 14 | Context 'String checks context' { 15 | It 'String 1 and String 2 should be different' { 16 | $String1 | Should -Not -Be $String2 17 | } 18 | 19 | It 'String 1 should be smaller in length than String 2' { 20 | $String1.Length | Should -BeLessThan $String2.Length 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Garuda/TestLib/Tests.Parameters.Json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/Garuda/f1168fd4ccaa5a3f5b474863c28c06f337b81819/Garuda/TestLib/Tests.Parameters.Json -------------------------------------------------------------------------------- /Garuda/TestLib/testGroup.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/Garuda/f1168fd4ccaa5a3f5b474863c28c06f337b81819/Garuda/TestLib/testGroup.json -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Ravikanth C 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Garuda 2 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | # Garuda 2 | -------------------------------------------------------------------------------- /images/Garuda.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/Garuda/f1168fd4ccaa5a3f5b474863c28c06f337b81819/images/Garuda.png -------------------------------------------------------------------------------- /images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/Garuda/f1168fd4ccaa5a3f5b474863c28c06f337b81819/images/logo.png -------------------------------------------------------------------------------- /images/logo.vsdx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/Garuda/f1168fd4ccaa5a3f5b474863c28c06f337b81819/images/logo.vsdx -------------------------------------------------------------------------------- /tests/Private/Garuda.Private.Test.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/Garuda/f1168fd4ccaa5a3f5b474863c28c06f337b81819/tests/Private/Garuda.Private.Test.ps1 -------------------------------------------------------------------------------- /tests/Public/Garuda.Public.Test.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rchaganti/Garuda/f1168fd4ccaa5a3f5b474863c28c06f337b81819/tests/Public/Garuda.Public.Test.ps1 --------------------------------------------------------------------------------