diff --git a/.MetaTestOptIn.json b/.MetaTestOptIn.json new file mode 100644 index 00000000..053c1a29 --- /dev/null +++ b/.MetaTestOptIn.json @@ -0,0 +1,4 @@ +[ + "Common Tests - Validate Markdown Files", + "Common Tests - Validate Example Files" +] diff --git a/.appveyor/appveyor.psm1 b/.appveyor/appveyor.psm1 deleted file mode 100644 index 07987b15..00000000 --- a/.appveyor/appveyor.psm1 +++ /dev/null @@ -1,127 +0,0 @@ -function Start-AppveyorInstallTask -{ - Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force - Install-Module -Name Pester -Force - Start-Process -Wait -FilePath "git" -ArgumentList @( - "clone", - "-q", - "https://github.com/PowerShell/DscResource.Tests", - (Join-Path -Path $env:APPVEYOR_BUILD_FOLDER ` - -ChildPath "Modules\xNetworking\DscResource.Tests") - ) - Start-Process -Wait -FilePath "git" -ArgumentList @( - "clone", - "-q", - "https://github.com/PowerShell/DscResources", - (Join-Path -Path $env:APPVEYOR_BUILD_FOLDER -ChildPath "DscResources") - ) - $testHelperPath = Join-Path -Path $env:APPVEYOR_BUILD_FOLDER ` - -ChildPath "Modules\xNetworking\DscResource.Tests\TestHelper.psm1" - Import-Module -Name $testHelperPath -Force -} - -function Start-AppveyorTestScriptTask -{ - $testResultsFile = ".\TestsResults.xml" - $testHarnessPath = Join-Path -Path $env:APPVEYOR_BUILD_FOLDER ` - -ChildPath "\Tests\xNetworking.TestHarness.psm1" - $dscTestsPath = Join-Path -Path $env:APPVEYOR_BUILD_FOLDER ` - -ChildPath "Modules\xNetworking\DscResource.Tests" - Import-Module -Name $testHarnessPath - - $result = Invoke-xNetworkingTest -TestResultsFile $testResultsFile ` - -DscTestsPath $dscTestsPath - - $webClient = New-Object -TypeName "System.Net.WebClient" - - $testResultsFilePath = Resolve-Path -Path $testResultsFile - $webClient.UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", - $testResultsFilePath) - - if ($result.FailedCount -gt 0) - { - throw "$($result.FailedCount) tests failed." - } -} - -function Start-AppveyorAfterTestTask -{ - # Move the DSC resource tests folder out so it isn't included in the ZIP module that is made - $dscTestsPath = Join-Path -Path $env:APPVEYOR_BUILD_FOLDER ` - -ChildPath "Modules\xNetworking\DscResource.Tests" - Move-Item -Path $dscTestsPath -Destination $env:APPVEYOR_BUILD_FOLDER - - # Import the module again from its new location - $testHelperPath = Join-Path -Path $env:APPVEYOR_BUILD_FOLDER ` - -ChildPath "DscResource.Tests\TestHelper.psm1" - Import-Module -Name $testHelperPath -Force - - $mainModulePath = Join-Path -Path $env:APPVEYOR_BUILD_FOLDER -ChildPath "modules\xNetworking" - - # Write the PowerShell help files - $docoPath = Join-Path -Path $env:APPVEYOR_BUILD_FOLDER ` - -ChildPath "modules\xNetworking\en-US" - New-Item -Path $docoPath -ItemType Directory - $docoHelperPath = Join-Path -Path $env:APPVEYOR_BUILD_FOLDER ` - -ChildPath "DscResources\DscResource.DocumentationHelper" - Import-Module -Name $docoHelperPath - Write-DscResourcePowerShellHelp -OutputPath $docoPath -ModulePath $mainModulePath -Verbose - - # Import so we can create zip files - Add-Type -assemblyname System.IO.Compression.FileSystem - - # Generate the wiki content for the release and zip/publish it to appveyor - $wikiContentPath = Join-Path -Path $env:APPVEYOR_BUILD_FOLDER -ChildPath "wikicontent" - New-Item -Path $wikiContentPath -ItemType Directory - Write-DscResourceWikiSite -OutputPath $wikiContentPath -ModulePath $mainModulePath -Verbose - - $zipFileName = "xNetworking_$($env:APPVEYOR_BUILD_VERSION)_wikicontent.zip" - [System.IO.Compression.ZipFile]::CreateFromDirectory($wikiContentPath, - "$env:APPVEYOR_BUILD_FOLDER\$zipFileName") - Get-ChildItem -Path "$env:APPVEYOR_BUILD_FOLDER\$zipFileName" | ForEach-Object -Process { - Push-AppveyorArtifact $_.FullName -FileName $_.Name - } - - # Remove the readme files that are used to generate documentation so they aren't shipped - $readmePaths = "$env:APPVEYOR_BUILD_FOLDER\Modules\**\readme.md" - Get-ChildItem -Path $readmePaths -Recurse | Remove-Item -Confirm:$false - - # Add the appropriate build number to the manifest and zip/publish everything to appveyor - $manifest = Join-Path -Path $env:APPVEYOR_BUILD_FOLDER -ChildPath "modules\xNetworking\xNetworking.psd1" - (Get-Content $manifest -Raw).Replace("3.2.0.0", $env:APPVEYOR_BUILD_VERSION) | Out-File $manifest - $zipFileName = "xNetworking_$($env:APPVEYOR_BUILD_VERSION).zip" - [System.IO.Compression.ZipFile]::CreateFromDirectory($mainModulePath, "$env:APPVEYOR_BUILD_FOLDER\$zipFileName") - New-DscChecksum -Path $env:APPVEYOR_BUILD_FOLDER -Outpath $env:APPVEYOR_BUILD_FOLDER - Get-ChildItem -Path "$env:APPVEYOR_BUILD_FOLDER\$zipFileName" | ForEach-Object -Process { - Push-AppveyorArtifact $_.FullName -FileName $_.Name - } - Get-ChildItem -Path "$env:APPVEYOR_BUILD_FOLDER\$zipFileName.checksum" | ForEach-Object -Process { - Push-AppveyorArtifact $_.FullName -FileName $_.Name - } - - Set-Location -Path $mainModulePath - $nuspecParams = @{ - packageName = "xNetworking" - version = $env:APPVEYOR_BUILD_VERSION - author = "Microsoft" - owners = "Microsoft" - licenseUrl = "https://github.com/PowerShell/DscResources/blob/master/LICENSE" - projectUrl = "https://github.com/$($env:APPVEYOR_REPO_NAME)" - packageDescription = "xNetworking" - tags = "DesiredStateConfiguration DSC DSCResourceKit" - destinationPath = "." - } - New-Nuspec @nuspecParams - - Start-Process -FilePath "nuget" -Wait -ArgumentList @( - "pack", - ".\xNetworking.nuspec", - "-outputdirectory $env:APPVEYOR_BUILD_FOLDER" - ) - $nuGetPackageName = "xNetworking." + $env:APPVEYOR_BUILD_VERSION + ".nupkg" - Get-ChildItem "$env:APPVEYOR_BUILD_FOLDER\$nuGetPackageName" | ForEach-Object -Process { - Push-AppveyorArtifact $_.FullName -FileName $_.Name - } -} - -Export-ModuleMember -Function * diff --git a/.codecov.yml b/.codecov.yml new file mode 100644 index 00000000..411198f0 --- /dev/null +++ b/.codecov.yml @@ -0,0 +1,26 @@ +codecov: + notify: + require_ci_to_pass: no + # dev should be the baseline for reporting + branch: dev + +comment: + layout: "reach, diff" + behavior: default + +coverage: + range: 50..80 + round: down + precision: 0 + + status: + project: + default: + # Set the overall project code coverage requirement to 70% + target: 70 + patch: + default: + # Set the pull request requirement to not regress overall coverage by more than 5% + # and let codecov.io set the goal for the code changed in the patch. + target: auto + threshold: 5 diff --git a/.gitignore b/.gitignore index 457e0aea..6aa84213 100644 --- a/.gitignore +++ b/.gitignore @@ -4,8 +4,11 @@ .vs .psproj .sln +DscResource.Tests +DscResource.Tests/* Modules/xNetworking/DscResource.Tests Modules/xNetworking/DscResource.Tests/* node_modules node_modules/* markdownissues.txt +TestResults.xml diff --git a/.markdownlint.json b/.markdownlint.json deleted file mode 100644 index f59d82e5..00000000 --- a/.markdownlint.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "default": true, - "MD029": { - "style": "ordered" - }, - "MD034": false, - "no-hard-tabs": true -} diff --git a/.vscode/RunAllTests.ps1 b/.vscode/RunAllTests.ps1 index 159bb5d9..3e986a2d 100644 --- a/.vscode/RunAllTests.ps1 +++ b/.vscode/RunAllTests.ps1 @@ -1,4 +1,11 @@ -Import-Module (Join-Path $PSScriptRoot "..\Tests\xNetworking.TestHarness.psm1" -Resolve) +[string] $repoRoot = Split-Path -Path (Split-Path -Path $Script:MyInvocation.MyCommand.Path) +if ( (-not (Test-Path -Path (Join-Path -Path $repoRoot -ChildPath 'DSCResource.Tests'))) -or ` + (-not (Test-Path -Path (Join-Path -Path $repoRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) ) +{ + & git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $repoRoot -ChildPath '\DSCResource.Tests\')) +} + +Import-Module (Join-Path $PSScriptRoot "..\Tests\TestHarness.psm1" -Resolve) $dscTestsPath = Join-Path -Path $PSScriptRoot ` - -ChildPath "..\Modules\xNetworking\DscResource.Tests\Meta.Tests.ps1" -Invoke-xNetworkingTest -DscTestsPath $dscTestsPath + -ChildPath "..\Modules\xNetworking\DscResource.Tests\Meta.Tests.ps1" +Invoke-TestHarness -DscTestsPath $dscTestsPath diff --git a/CHANGELOG.md b/CHANGELOG.md index 1656ec87..2bfc08a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +- Converted to use AppVeyor.psm1 in DSCResource.Tests repository. +- Converted to use Example and Markdown tests in DSCResource.Tests repository. +- Added CodeCov.io support. + ## 3.2.0.0 - Fixed typo in the example's Action property from "Blocked" (which isn't a valid diff --git a/README.md b/README.md index a7187b2c..21f389e7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # xNetworking [![Build status](https://ci.appveyor.com/api/projects/status/obmudad7gy8usbx2/branch/master?svg=true)](https://ci.appveyor.com/project/PowerShell/xnetworking/branch/master) +[![codecov](https://codecov.io/gh/PowerShell/xNetworking/branch/master/graph/badge.svg)](https://codecov.io/gh/PowerShell/xNetworking) The **xNetworking** module contains the following resources: diff --git a/Tests/Helper/xNetworking.Helper.Tests.ps1 b/Tests/Helper/xNetworking.Helper.Tests.ps1 deleted file mode 100644 index f47318e9..00000000 --- a/Tests/Helper/xNetworking.Helper.Tests.ps1 +++ /dev/null @@ -1,105 +0,0 @@ -[CmdletBinding()] -param -( - -) - -$ErrorActionPreference = 'stop' -Set-StrictMode -Version latest - -$RepoRoot = (Resolve-Path $PSScriptRoot\..\..).Path - -Describe 'xNetworking whole of module tests' { - - Context -Name "Validate example files" { - - It "Should compile MOFs for all examples correctly" { - - ## For Appveyor builds copy the module to the system modules directory so it falls - ## in to a PSModulePath folder and is picked up correctly. - if ($env:APPVEYOR -eq $true) - { - Copy-item -Path "$env:APPVEYOR_BUILD_FOLDER\Modules\xNetworking" ` - -Destination 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\xNetworking' ` - -Recurse - } - - $examplesWithErrors = 0 - Get-ChildItem -Path "$RepoRoot\Modules\xNetworking\Examples" -Filter "*.ps1" -Recurse | ForEach-Object -Process { - $path = $_.FullName - try - { - . $path - - $command = Get-Command Example - $params = @{} - $command.Parameters.Keys | Where-Object { $_ -like "*Account" -or $_ -eq "Passphrase" } | ForEach-Object -Process { - $params.Add($_, $mockCredential) - } - Example @params -OutputPath "TestDrive:\" -ErrorAction Continue -WarningAction SilentlyContinue | Out-Null - } - catch - { - $examplesWithErrors ++ - Write-Warning -Message "Unable to compile MOF for example '$path'" - Write-Warning $_.Exception.Message - } - } - $examplesWithErrors | Should Be 0 - - if ($env:APPVEYOR -eq $true) - { - Remove-item -Path 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\xNetworking' ` - -Recurse -Force -Confirm:$false - # Restore the load of the module to ensure future tests have access to it - Import-Module -Name "$RepoRoot\Modules\xNetworking\xNetworking.psd1" -Global -Force - } - } - - It "Should not have errors in any markdown files" { - $runGulp = $false - try - { - Start-Process -FilePath "npm" -ArgumentList "install" -WorkingDirectory $RepoRoot -Wait -PassThru -NoNewWindow - $runGulp = $true - } - catch [System.Exception] - { - Write-Warning -Message ("Unable to run npm to install dependencies needed to " + ` - "test markdown files. Please be sure that you have " + ` - "installed nodejs.") - } - - if ($runGulp -eq $true) - { - $mdErrors = 0 - try - { - Start-Process -FilePath "gulp" -ArgumentList "test-mdsyntax --silent" -Wait -WorkingDirectory $RepoRoot -PassThru -NoNewWindow - Start-Sleep -Seconds 3 - $mdIssuesPath = Join-Path -Path $RepoRoot -ChildPath "markdownissues.txt" - - if ((Test-Path -Path $mdIssuesPath) -eq $true) - { - Get-Content -Path $mdIssuesPath | ForEach-Object -Process { - if ([string]::IsNullOrEmpty($_) -eq $false) - { - Write-Warning -Message $_ - $mdErrors ++ - } - } - } - } - catch [System.Exception] - { - Write-Warning -Message ("Unable to run gulp to test markdown files. Please " + ` - "be sure that you have installed nodejs and have " + ` - "run 'npm install -g gulp' in order to have this " + ` - "text execute.") - } - Remove-Item -Path $mdIssuesPath -Force -ErrorAction SilentlyContinue - $mdErrors | Should Be 0 - } - } - } -} diff --git a/Tests/xNetworking.TestHarness.psm1 b/Tests/TestHarness.psm1 similarity index 50% rename from Tests/xNetworking.TestHarness.psm1 rename to Tests/TestHarness.psm1 index 30b38a62..d9046d61 100644 --- a/Tests/xNetworking.TestHarness.psm1 +++ b/Tests/TestHarness.psm1 @@ -1,16 +1,18 @@ -function Invoke-xNetworkingTest +function Invoke-TestHarness { [CmdletBinding()] param ( - [System.String] $TestResultsFile, + [System.String] + $TestResultsFile, - [System.String] $DscTestsPath + [System.String] + $DscTestsPath ) Write-Verbose -Message 'Commencing all xNetworking tests' - $repoDir = Join-Path -Path $PSScriptRoot -ChildPath "..\" -Resolve + $repoDir = Join-Path -Path $PSScriptRoot -ChildPath '..\' -Resolve $testCoverageFiles = @() Get-ChildItem -Path "$repoDir\modules\xNetworking\DSCResources\**\*.psm1" -Recurse | ForEach-Object { @@ -28,39 +30,18 @@ function Invoke-xNetworkingTest Import-Module -Name "$repoDir\modules\xNetworking\xNetworking.psd1" $testsToRun = @() - # Helper tests - - $helperTests = (Get-ChildItem -Path (Join-Path -Path $repoDir -ChildPath '\Tests\Helper\')).Name - - $helperTests | ForEach-Object { - $testsToRun += @(@{ - 'Path' = "$repoDir\Tests\Helper\$_" - }) - } - # Run Unit Tests - $unitTests = (Get-ChildItem (Join-Path -Path $repoDir -ChildPath '\Tests\Unit\')).Name - - $unitTests | ForEach-Object { - $testsToRun += @(@{ - 'Path' = "$repoDir\Tests\Unit\$_" - }) - } + $unitTestsPath = Join-Path -Path $repoDir -ChildPath 'Tests\Unit' + $testsToRun += @( (Get-ChildItem -Path $unitTestsPath).FullName ) # Integration Tests - $integrationTests = (Get-ChildItem -Path (Join-Path -Path $repoDir -ChildPath '\Tests\Integration\') -Filter '*.Tests.ps1').Name - - $integrationTests | ForEach-Object { - $testsToRun += @(@{ - 'Path' = "$repoDir\Tests\Integration\$_" - }) - } + $integrationTestsPath = Join-Path -Path $repoDir -ChildPath 'Tests\Integration' + $testsToRun += @( (Get-ChildItem -Path $integrationTestsPath -Filter '*.Tests.ps1').FullName ) # DSC Common Tests - if ($PSBoundParameters.ContainsKey('DscTestsPath') -eq $true) { - $testsToRun += @{ - 'Path' = $DscTestsPath - } + if ($PSBoundParameters.ContainsKey('DscTestsPath') -eq $true) + { + $testsToRun += @( $DscTestsPath ) } $results = Invoke-Pester -Script $testsToRun ` @@ -68,5 +49,4 @@ function Invoke-xNetworkingTest -PassThru @testResultSettings return $results - } diff --git a/appveyor.yml b/appveyor.yml index 39b88ead..5a419436 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,13 +3,13 @@ #---------------------------------# version: 3.1.{build}.0 install: - - appveyor DownloadFile https://dist.nuget.org/win-x86-commandline/latest/nuget.exe - - npm install -g gulp - - npm install - + - git clone https://github.com/PowerShell/DscResource.Tests + - ps: | - Import-Module "$env:APPVEYOR_BUILD_FOLDER\.appveyor\appveyor.psm1" - Start-AppveyorInstallTask + $moduleName = 'xNetworking' + $mainModuleFolder = "Modules\$moduleName" + Import-Module "$env:APPVEYOR_BUILD_FOLDER\DscResource.Tests\AppVeyor.psm1" + Invoke-AppveyorInstallTask #---------------------------------# # build configuration # @@ -23,7 +23,10 @@ build: false test_script: - ps: | - Start-AppveyorTestScriptTask + Invoke-AppveyorTestScriptTask ` + -Type 'Harness' ` + -MainModulePath $mainModuleFolder ` + -CodeCovIo #---------------------------------# # deployment configuration # @@ -32,4 +35,7 @@ test_script: # scripts to run before deployment deploy_script: - ps: | - Start-AppveyorAfterTestTask + Invoke-AppveyorAfterTestTask ` + -Type 'Wiki' ` + -MainModulePath $mainModuleFolder ` + -ResourceModuleName $moduleName diff --git a/gulpfile.js b/gulpfile.js deleted file mode 100644 index decee836..00000000 --- a/gulpfile.js +++ /dev/null @@ -1,24 +0,0 @@ -var gulp = require("gulp"); -var concat = require("gulp-concat"); -var through2 = require("through2"); -var markdownlint = require("markdownlint"); - -gulp.task("test-mdsyntax", function task() { - return gulp.src(["./Modules/xNetworking/DSCResources/**/*.md","./README.md","./CHANGELOG.md"], { "read": false }) - .pipe(through2.obj(function obj(file, enc, next) { - markdownlint( - { - "files": [ file.path ], - "config": require("./.markdownlint.json") - }, - function callback(err, result) { - var resultString = (result || "").toString(); - if (resultString) { - file.contents = new Buffer(resultString); - } - next(err, file); - }); - })) - .pipe(concat("markdownissues.txt", { newLine: "\r\n" })) - .pipe(gulp.dest(".")); -}); diff --git a/package.json b/package.json deleted file mode 100644 index 3ef44441..00000000 --- a/package.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "name": "xnetworking", - "version": "1.4.0", - "description": "The xNetworking PowerShell module provides DSC resources that can be used to modify network interfaces", - "main": "gulpfile.js", - "dependencies": { - "gulp": "^3.9.1", - "through2": "^2.0.1", - "markdownlint": "^0.2.0" - }, - "devDependencies": { - "gulp-concat": "^2.6.0", - "gulp-debug": "^3.0.0" - }, - "scripts": { - "test": "powershell -File .vscode\\RunAllTests.ps1" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/PowerShell/xNetworking.git" - }, - "author": "Microsoft Corporation", - "license": "MIT", - "bugs": { - "url": "https://github.com/PowerShell/xNetworking/issues" - }, - "homepage": "https://github.com/PowerShell/xNetworking#readme" -}