Skip to content

Instantly share code, notes, and snippets.

View johlju's full-sized avatar
👋
Reviewing, coding and reviewing again

Johan Ljunggren johlju

👋
Reviewing, coding and reviewing again
View GitHub Profile
@johlju
johlju / unittest.ps1
Last active April 23, 2020 05:01
Example Unit Test
InModuleScope $script:dscResourceName {
Describe 'ResourceName\Get-TargetResource' -Tag 'Get' {
BeforeAll {
# Mocks for all context blocks. Avoid if possible.
}
# Context block cannot always be used.
Context 'When the system is not in the desired state' {
BeforeAll {
# Mocks when the system is not in desired state
param
(
# Project path
[Parameter()]
[string]
$ProjectPath = (property ProjectPath $BuildRoot),
[Parameter()]
# Base directory of all output (default to 'output')
[string]
@johlju
johlju / testresult_job1.xml
Created January 29, 2020 07:15
JaCoCo output from Pester (from 3 jobs)
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE report PUBLIC "-//JACOCO//DTD Report 1.1//EN" "report.dtd">
<report name="Pester (01/29/2020 06:54:44)">
<sessioninfo id="this" start="1580280789517" dump="1580280884237" />
<package name="MSFT_xCluster">
<class name="MSFT_xCluster/MSFT_xCluster" sourcefilename="MSFT_xCluster.psm1">
<method name="&lt;script&gt;" desc="()" line="1">
<counter type="INSTRUCTION" missed="0" covered="3" />
<counter type="LINE" missed="0" covered="3" />
<counter type="METHOD" missed="0" covered="1" />
</method>
@johlju
johlju / SetDebugModeForceModuleImport.ps1
Created July 30, 2019 11:31
Set LCM DebugMode to ForceModuleImport
Configuration SetDebugModeForceModuleImport {
Node localhost
{
LocalConfigurationManager
{
DebugMode = 'ForceModuleImport'
}
}
}
@johlju
johlju / MSFT_ADUser.config.ps1
Created July 28, 2019 08:50
Example creating 500 Active Directory test users with DSC
$computersContainerDistinguishedName = (Get-ADDomain).ComputersContainer
if ($computersContainerDistinguishedName -match 'DC=.+')
{
$domainDistinguishedName = $matches[0]
}
$ConfigurationData = @{
AllNodes = @(
@{
NodeName = 'localhost'
@johlju
johlju / Get-ScriptLinesWithMinimumLength.ps1
Last active July 5, 2019 13:12
Get script module files with a line length longer than 120 characters
$scriptModulesFiles = Get-ChildItem -Path '.' -Recurse -Include '*.psm1'
$lines = [PSCustomObject] @()
$scriptModulesFiles | % {
$parseErrors = $null
$definitionAst = [System.Management.Automation.Language.Parser]::ParseFile($_.FullName, [ref] $null, [ref] $parseErrors)
if ($parseErrors)
{
@johlju
johlju / Closure.Tests.ps1
Created May 13, 2019 19:19
Mock using Closure
Describe "a" {
It "b" {
function a () {}
$closure = & {
$state = @{
Value = 0
}
{
@johlju
johlju / DscCommunity-Labels.ps1
Last active February 23, 2020 10:13
DscCommunity Labels
<#
.SYNOPSIS
Script to add and update labels according how they are defined in the
DSC Resource Kit.
#>
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'High')]
param ()
<#
TODO: Add all your repositories to the array.
@johlju
johlju / appveyor.yml
Last active March 7, 2018 06:35
Template appveyor.yml for default testing model for the DscResource.Tests framework
#---------------------------------#
# environment configuration #
#---------------------------------#
version: 1.0.{build}.0
install:
- git clone https://github.com/PowerShell/DscResource.Tests
- ps: Write-Verbose -Message "PowerShell version $($PSVersionTable.PSVersion)" -Verbose
- ps: Import-Module "$env:APPVEYOR_BUILD_FOLDER\DscResource.Tests\AppVeyor.psm1"
- ps: Invoke-AppveyorInstallTask
function Get-Something
{
param
(
[Parameter()]
[System.Boolean]
$MockError
)
}