Skip to content
Permalink
Browse files

initial commit

  • Loading branch information
potatoqualitee committed Dec 18, 2017
1 parent 1bf86cd commit 5ea8a71e2829872a7ee4fba9095b3ed411170935
Showing with 293 additions and 0 deletions.
  1. +17 −0 .gitattributes
  2. +2 −0 .gitignore
  3. +127 −0 dbachecks.psd1
  4. +12 −0 dbachecks.psm1
  5. +11 −0 readme.md
  6. +124 −0 tests/InModule.Help.Tests.ps1
@@ -0,0 +1,17 @@
# Auto detect text files and perform LF normalization
* text=auto

# Custom for Visual Studio
*.cs diff=csharp

# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
@@ -0,0 +1,2 @@
*.psproj
dbachecks.psprojs
@@ -0,0 +1,127 @@
#
# Module manifest for module 'dbachecks'
#
# Generated by: You, you big playa!
#
# Generated on: 4/14/2017
#
@{

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

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

# ID used to uniquely identify this module
GUID = '578c5d98-50c8-43a8-bdbb-d7159028d7ac'

# Author of this module
Author = 'SQL Community Collaborative'

# Company or vendor of this module
CompanyName = 'SQL Community Collaborative'

# Copyright statement for this module
Copyright = '2017 dbatools'

# Description of the functionality provided by this module
Description = 'Automates testing for SQL Server stuff'

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

# 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 the .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, IA64) required by this module
ProcessorArchitecture = ''

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

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

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

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

# Format files (xml) to be loaded when importing this module
# "xml\dbachecks.Format.ps1xml"
# worry about this later
FormatsToProcess = @()

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

# Functions to export from this module
# This is the stuff in \enduser-functions
FunctionsToExport = @(
'Clear-AcmeSqlConnectionPool',
'Test-AcmeSqlPath'
)

# Cmdlets to export from this module
CmdletsToExport = '*'

# Variables to export from this module
VariablesToExport = '*'

# Aliases to export from this module
# Aliases are stored in dbachecks.psm1
AliasesToExport = '*'

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

# List of all files packaged with this module
FileList = ''

PrivateData = @{
# PSData is module packaging and gallery metadata embedded in PrivateData
# It's for rebuilding PowerShellGet (and PoshCode) NuGet-style packages
# We had to do this because it's the only place we're allowed to extend the manifest
# https://connect.microsoft.com/PowerShell/feedback/details/421837
PSData = @{
# The primary categorization of this module (from the TechNet Gallery tech tree).
Category = "Databases"

# Keyword tags to help users find this module via navigations and search.
Tags = @('sqlserver', 'sql', 'dba', 'databases', 'audits')

# The web address of an icon which can be used in galleries to represent this module
IconUri = "https://dbatools.io/logo.png"

# The web address of this module's project or support homepage.
ProjectUri = ""

# The web address of this module's license. Points to a page that's embeddable and linkable.
LicenseUri = "https://opensource.org/licenses/MIT"

# Release notes for this particular version of the module
ReleaseNotes = ""

# If true, the LicenseUrl points to an end-user license (not just a source license) which requires the user agreement before use.
# RequireLicenseAcceptance = ""

# Indicates this is a pre-release/testing version of the module.
IsPrerelease = 'True'
}
}
}
@@ -0,0 +1,12 @@
# All internal functions privately available within the toolset - for developers - smaller modules may not have any
# But basically, these are functions that are shared between the exported commands, that you don't nessarily want end users to use
foreach ($function in (Get-ChildItem "$PSScriptRoot\internal\*.ps1"))
{
$ExecutionContext.InvokeCommand.InvokeScript($false, ([scriptblock]::Create([io.file]::ReadAllText($function))), $null, $null)
}

# All exported functions - for end users
foreach ($function in (Get-ChildItem "$PSScriptRoot\functions\*.ps1"))
{
$ExecutionContext.InvokeCommand.InvokeScript($false, ([scriptblock]::Create([io.file]::ReadAllText($function))), $null, $null)
}
@@ -0,0 +1,11 @@
# dbachecks

Check stuff

## Getting started

Do this

## Party

Nice work!
@@ -0,0 +1,124 @@
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2016 v5.2.119
Created on: 4/12/2016 1:11 PM
Created by: June Blender
Organization: SAPIEN Technologies, Inc
Filename: *.Help.Tests.ps1
===========================================================================
.DESCRIPTION
To test help for the commands in a module, place this file in the module folder.
To test any module from any path, use https://github.com/juneb/PesterTDD/Module.Help.Tests.ps1
#>

$ModuleBase = Split-Path -Parent $MyInvocation.MyCommand.Path
. "$ModuleBase\InModule.Help.Exceptions.ps1"

# For tests in .\Tests subdirectory
if ((Split-Path $ModuleBase -Leaf) -eq 'Tests')
{
$ModuleBase = Split-Path $ModuleBase -Parent
}

# Handles modules in version directories
$leaf = Split-Path $ModuleBase -Leaf
$parent = Split-Path $ModuleBase -Parent
$parsedVersion = $null
if ([System.Version]::TryParse($leaf, [ref]$parsedVersion))
{
$ModuleName = Split-Path $parent -Leaf
}
else
{
$ModuleName = $leaf
}

# Removes all versions of the module from the session before importing
Get-Module $ModuleName | Remove-Module

# Because ModuleBase includes version number, this imports the required version
# of the module
$Module = Import-Module $ModuleBase\$ModuleName.psd1 -PassThru -ErrorAction Stop
$commands = Get-Command -Module $module -CommandType Cmdlet, Function, Workflow # Not alias


## When testing help, remember that help is cached at the beginning of each session.
## To test, restart session.

foreach ($command in $commands)
{
$commandName = $command.Name

# Skip all functions that are on the exclusions list
if ($global:FunctionHelpTestExceptions -contains $commandName) { continue }

# The module-qualified command fails on Microsoft.PowerShell.Archive cmdlets
$Help = Get-Help $commandName -ErrorAction SilentlyContinue

Describe "Test help for $commandName" {

# If help is not found, synopsis in auto-generated help is the syntax diagram
It "should not be auto-generated" {
$Help.Synopsis | Should Not BeLike '*`[`<CommonParameters`>`]*'
}

# Should be a description for every function
It "gets description for $commandName" {
$Help.Description | Should Not BeNullOrEmpty
}

# Should be at least one example
It "gets example code from $commandName" {
($Help.Examples.Example | Select-Object -First 1).Code | Should Not BeNullOrEmpty
}

# Should be at least one example description
It "gets example help from $commandName" {
($Help.Examples.Example.Remarks | Select-Object -First 1).Text | Should Not BeNullOrEmpty
}

Context "Test parameter help for $commandName" {

$Common = 'Debug', 'ErrorAction', 'ErrorVariable', 'InformationAction', 'InformationVariable', 'OutBuffer', 'OutVariable',
'PipelineVariable', 'Verbose', 'WarningAction', 'WarningVariable'

$parameters = $command.ParameterSets.Parameters | Sort-Object -Property Name -Unique | Where-Object Name -notin $common
$parameterNames = $parameters.Name
$HelpParameterNames = $Help.Parameters.Parameter.Name | Sort-Object -Unique

foreach ($parameter in $parameters)
{
$parameterName = $parameter.Name
$parameterHelp = $Help.parameters.parameter | Where-Object Name -EQ $parameterName

# Should be a description for every parameter
It "gets help for parameter: $parameterName : in $commandName" {
$parameterHelp.Description.Text | Should Not BeNullOrEmpty
}

# Required value in Help should match IsMandatory property of parameter
It "help for $parameterName parameter in $commandName has correct Mandatory value" {
$codeMandatory = $parameter.IsMandatory.toString()
$parameterHelp.Required | Should Be $codeMandatory
}

# Parameter type in Help should match code
It "help for $commandName has correct parameter type for $parameterName" {
$codeType = $parameter.ParameterType.Name
# To avoid calling Trim method on a null object.
$helpType = if ($parameterHelp.parameterValue) { $parameterHelp.parameterValue.Trim() }
$helpType | Should be $codeType
}
}

foreach ($helpParm in $HelpParameterNames)
{
# Shouldn't find extra parameters in help.
It "finds help parameter in code: $helpParm" {
$helpParm -in $parameterNames | Should Be $true
}
}
}
}
}

0 comments on commit 5ea8a71

Please sign in to comment.
You can’t perform that action at this time.