Skip to content

Commit

Permalink
🎉 Initial commit.
Browse files Browse the repository at this point in the history
Initial module structure.
  • Loading branch information
pspete committed May 13, 2019
1 parent 5203e11 commit 1ec9418
Show file tree
Hide file tree
Showing 12 changed files with 595 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

.vscode/launch.json
Empty file added CHANGELOG.md
Empty file.
46 changes: 46 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [email protected]. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
22 changes: 22 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Contributing

All contributions welcomed and are appreciated.

## PowerShell Styleguide

Use the standard *Verb*-*Noun* convention, and only use approved verbs.

All Functions must have Comment Based Help.

[K&R (One True Brace Style variant)](https://github.com/PoshCode/PowerShellPracticeAndStyle/issues/81) preferred.

## Contributing Code

- Fork the repo.
- Push your changes to your fork.
- Write a [good commit message][commit]
- Submit a pull request
- Keep pull requests limited to a single issue
- Discussion, or necessary changes may be needed before merging the contribution.

[commit]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
231 changes: 231 additions & 0 deletions Tests/pSynology.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
#Requires -Modules Pester, PSScriptAnalyzer
<#
.SYNOPSIS
Tests module for consistency, expected structures, settings, components & files.
.EXAMPLE
Invoke-Pester
.NOTES
A generic set of tests to apply to a module
#>

#Get Current Directory
$Here = Split-Path -Parent $MyInvocation.MyCommand.Path

#Assume ModuleName from Test File Name
$ModuleName = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -Replace ".Tests.ps1"

#Resolve Path to Module Directory
$ModulePath = Resolve-Path "$Here\..\$ModuleName"

#Define Path to Module Manifest
$ManifestPath = Join-Path "$ModulePath" "$ModuleName.psd1"

Get-Module -Name $ModuleName -All | Remove-Module -Force -ErrorAction Ignore
$Module = Import-Module -Name "$ManifestPath" -ArgumentList $true -Force -ErrorAction Stop -PassThru

Describe "Module" {

Context "Module Consistency Tests" {

It "has a valid manifest" {

{$null = Test-ModuleManifest -Path $ManifestPath -ErrorAction Stop -WarningAction SilentlyContinue} |
Should Not Throw

}

It "specifies valid root module" {

$Module.RootModule | Should Be "$ModuleName.psm1"

}

It "has a valid description" {

$Module.Description | Should Not BeNullOrEmpty

}

It "has a valid guid" {

$Module.Guid | Should Be '11c880d2-1430-4bd2-b6e8-f324741b460b'

}

It "has a valid copyright" {

$Module.Copyright | Should Not BeNullOrEmpty

}

Context "Files To Process" {

#validate formats
($Module.FormatsToProcess).foreach{

$FormatFilePath = (Join-Path $ModulePath $_)

#File Exists
It "$_ exists" {

$FormatFilePath | Should Exist

}

#file contains valid format data
It "$_ is valid" {

{Update-FormatData -AppendPath $FormatFilePath -ErrorAction Stop -WarningAction SilentlyContinue} |
Should Not Throw

}

}

#validate types
($Module.TypesToProcess).foreach{

$TypesFilePath = (Join-Path $ModulePath $_)

#file exists
It "$_ exists" {

$TypesFilePath | Should Exist

}

#file contains valid type data
It "$_ is valid" {

{Update-TypeData -AppendPath $TypesFilePath -ErrorAction Stop -WarningAction SilentlyContinue} |
Should Not Throw

}

}

}

#Get Public Function Names
$PublicFunctions = Get-ChildItem "$ModulePath\Functions" -Filter *.ps1 -Recurse |
Select-Object -ExpandProperty BaseName

Context "Exported Function Analysis" {

#Get Exported Function Names
$ExportedFunctions = $Module.ExportedFunctions.Values.name

It 'exports the expected number of functions' {

($PublicFunctions | Measure-Object | Select-Object -ExpandProperty Count) |

Should be ($ExportedFunctions | Measure-Object | Select-Object -ExpandProperty Count)

}

$ExportedFunctions.foreach{

Context "$_" {

It 'is a public function' {

$PublicFunctions -contains $_ | Should Be $true

}

It 'has a related pester tests file' {
Test-Path (Join-Path $here "$_.Tests.ps1") | Should Be $true
}

Context "Help" {

$help = Get-Help $_ -Full

It 'has synopsis' {

$help.synopsis | Should Not BeNullOrEmpty

}

It 'has description' {

$help.description | Should Not BeNullOrEmpty

}

It 'has example code' {

$help.examples.example.code | Should Not BeNullOrEmpty

}

$HelpParameters = $help.parameters.parameter | Where-Object name -NotIn @("WhatIf", "Confirm")

$HelpParameters.foreach{

It "has description of parameter $($_.name)" {

$_.description | Should Not BeNullOrEmpty
}

}

}

}

}

}

Context "Exported Alias Analysis" {

$ExportedAliases = $Module.ExportedAliases.Values.name

$ExportedAliases.foreach{

Context "$_" {

It "Resolves to Public Function" {

$PublicFunctions -contains $((Get-Alias $_).ResolvedCommand) | Should Be $true

}


}

}


}

}

Describe 'PSScriptAnalyzer' {

$Scripts = Get-ChildItem "$ModulePath" -Filter '*.ps1' -Exclude '*.ps1xml' -Recurse

$Rules = Get-ScriptAnalyzerRule

foreach ($Script in $scripts) {

Context "Checking: $($script.BaseName)" {

foreach ($rule in $rules) {

It "passes rule $rule" {

(Invoke-ScriptAnalyzer -Path $script.FullName -IncludeRule $rule.RuleName ).Count | Should Be 0

}

}

}

}

}

}
48 changes: 48 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# version format
version: 2.6.{build}

environment:
access_token:
secure: eWAovbJD8C/F5ObWegnOimwNFyeU1vXzW6lwbJzhHpSUgjT+CMexMcPUBMKrm+Wl
psgallery_key:
secure: FuPgJskczZMptxRgdUlBAy7OYmXBQl4zq86kXXSmBt6wKudnM2PK7W6cM7bj0te1
coveralls_key:
#secure: cWv4+OPfqRLSt7I4f+p3lEixKoYZzi42IDc7C4Kf+2WZW/dO+H+RBCM7m0Si2uuP

skip_tags: true

skip_commits:
files:
- .github\*
- .vscode\*
- README.md
- LICENSE.md
- CONTRIBUTING.md
- CODE_OF_CONDUCT.md
- ISSUE_TEMPLATE.md
- PULL_REQUEST_TEMPLATE.md
- appveyor.yml
- CHANGELOG.md
message: /update readme.*|update version.*|update appveyor.*/

only_commits:
files:
- build\
- pSynology\
- Tests\

#os: WMF 5
image: Visual Studio 2017

install:
# - ps: . .\build\install.ps1
- pwsh.exe -File .\build\install.ps1
build_script:
# - ps: . .\build\build.ps1
- pwsh.exe -File .\build\build.ps1
test_script:
# - ps: . .\build\test.ps1
- pwsh.exe -File .\build\test.ps1
deploy_script:
# - ps: . .\build\deploy.ps1
- pwsh.exe -File .\build\deploy.ps1
Loading

0 comments on commit 1ec9418

Please sign in to comment.