Giter Club home page Giter Club logo

poshspec's Introduction

PoshSpec

An infrastructure testing DSL running in Pester. The goal is to expand the Pester DSL to assist in the development of infrastructure validation scripts.

Install from the Gallery

PS> Install-Module -Name poshspec

Example

Describe 'Services' {    
    Service w32time Status { Should Be Running }
    Service bits Status { Should Be Stopped }
}

Describe 'Files' {
    File C:\inetpub\wwwroot\iisstart.htm { Should Exist }
    File C:\inetpub\wwwroot\iisstart.htm { Should Contain 'text-align:center' }
}

Describe 'Registry' {
    Registry HKLM:\SOFTWARE\Microsoft\Rpc\ClientProtocols { Should Exist }
    Registry HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\ "SyncDomainWithMembership" { Should Be 1  }
    Registry 'HKLM:\SOFTWARE\Callahan Auto\' { Should Not Exist }
}

Describe 'Http' {
    TcpPort localhost 80 PingSucceeded { Should Be $true }
    TcpPort localhost 80 TcpTestSucceeded { Should Be $true }
    Http http://localhost StatusCode { Should Be 200 }
    Http http://localhost RawContent { Should Match 'X-Powered-By: ASP.NET' }
    Http http://localhost RawContent { Should Not Match 'X-Powered-By: Cobal' }
}
Describe 'Hotfix' {
    Hotfix KB3116900 { Should Not BeNullOrEmpty}
    Hotfix KB1112233 { Should BeNullOrEmpty}
}
Describe 'CimObject' {
    CimObject Win32_OperatingSystem SystemDirectory { Should Be C:\WINDOWS\system32 }
    CimObject root/StandardCimv2/MSFT_NetOffloadGlobalSetting ReceiveSideScaling { Should Be Enabled }
}

Functions

Here is a list of implemented functions.

File [-Path] <string> [-Should] <scriptblock>

Verify the existence of a file and optionally validate its contents with a regex pattern.

Hotfix [-Id] <string> [-Should] <scriptblock>

Verify a particular Hotfix/Update is installed

Http [-Uri] <string> [[-Property] <string> {BaseResponse | Content | Headers | RawContent | RawContentLength | RawContentStream | StatusCode | StatusDescription}] [-Should] <scriptblock>

Verify a Uri returns a 200 StatusCode and optionally validate RawContent.

Registry [-Path] <string> [[-Property] <string>] [-Should] <scriptblock>

Verify a registry key exists and optionally validate the value of a given property.

Service [-Name] <String> [-Property] <String> [-Should] <ScriptBlock>

Verify a service is in a given state. Default is "Running".

TcpPort [-Address] <string> [-Port] <string> [[-Property] <string> {AllNameResolutionResults | BasicNameResolution | ComputerName | Detailed | DNSOnlyRecords | InterfaceAlias | InterfaceDescription | InterfaceIndex | IsAdmin | LLMNRNetbiosRecords | MatchingIPsecRules | NameResolutionSucceeded | NetAdapter | NetRoute | NetworkIsolationContext | PingReplyDetails | PingSucceeded | RemoteAddress | RemotePort | SourceAddress | TcpClientSocket | TcpTestSucceeded | TraceRoute}] [-Should] <scriptblock>

Verify that a specific TCP port is listening.

CimObject [-ClassName] <string> [-Property] <string> [-Should] <scriptblock>

Verify that a CimObject exists and optionally validate the value of a given property. The function will try to parse out Namespace and Class if the Class parameter is provied in the form of namespace\class.

Creating New Test Functions

Every test must implement a few bits of logic.

It must have two properties: [string]$Target and [scriptblock]$Should. It can optionally implement [string]$Property and [string]$Qualifier. If your function has any more than those 4 parameters, it will likely break unless you take special measures to deal with them.

  • Target is the name or unique identifier of object you are testing.
  • Should is the assertion using Pester Should syntax.
  • Property could be used to test a Property of the Target.
  • Qualifier could be used to filter the Target or Property.

It must call Get-TestParam with at least the following properties.

  • TestName is the type of test. i.e. File, Service
  • TestExpression is a scriptblock that will be executed to get an object to test.
  • @PSBoundParameters Splat the PSBoundParameters automatic variable.

Optionally, you may pass a FriendlyName parameter. This is used when generating the Pester It Name as a way to prettify the output when the Target is a particularly long string.

It must pass the output of Get-TestParam to Invoke-PoshspecExpression

It's easiest way to do this is with splatting.

poshspec's People

Contributors

cdhunt avatar devblackops avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.