diff --git a/DSCResources/xDSCSEPVIE/xDSCSEPVIE.psm1 b/DSCResources/xDSCSEPVIE/xDSCSEPVIE.psm1 index 365c173..44c2227 100644 Binary files a/DSCResources/xDSCSEPVIE/xDSCSEPVIE.psm1 and b/DSCResources/xDSCSEPVIE/xDSCSEPVIE.psm1 differ diff --git a/LICENSE.MD b/LICENSE.MD new file mode 100644 index 0000000..2570b06 --- /dev/null +++ b/LICENSE.MD @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 Anthony Waye + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index eb3ed2f..b5ade54 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ +# Builds +|Master | Development | +|:------:|:------:|:-------:|:-------:| +[![Build status](https://ci.appveyor.com/api/projects/status/i6plr1mrpa1pl6xx/branch/master?svg=true)](https://ci.appveyor.com/project/theonlyway/xdscsepvie/branch/master)|[![Build status](https://ci.appveyor.com/api/projects/status/i6plr1mrpa1pl6xx?svg=true)](https://ci.appveyor.com/project/theonlyway/xdscsepvie)| + # xDSCSEPVIE # ## Overview ## diff --git a/Tests/xDSCSEPVIE.Tests.ps1 b/Tests/xDSCSEPVIE.Tests.ps1 new file mode 100644 index 0000000..74241d8 --- /dev/null +++ b/Tests/xDSCSEPVIE.Tests.ps1 @@ -0,0 +1,114 @@ +Import-Module -Name .\DSCResources\xDSCSEPVIE\xDSCSEPVIE.psm1 + +$Global:DSCModuleName = 'xDSCSEPVIE' +$Global:DSCResourceName = 'xDSCSEPVIE' + +InModuleScope -ModuleName xDSCSEPVIE -ScriptBlock { + $VIELocation = 'C:\Temp\doesntmatter.exe' + + $global:mockedVolume = [pscustomobject] @{ + FileSystemLabel = 'myLabel' + DriveLetter = 'C' + DriveType = 'Fixed' + } + $global:mockedCSV = @() + $global:mockedCSV += [pscustomobject] @{ + DriveLetter = 'C' + DateScanned = (Get-Date -Format dd/MM/yyyy) + } + $global:mockedCSV += [pscustomobject] @{ + DriveLetter = 'GG' + DateScanned = (Get-Date -Format dd/MM/yyyy) + } + + Describe -Name 'Testing if functions return correct objects' -Fixture { + Mock -CommandName Import-CSV -MockWith { + $global:mockedCSV + } + Mock -CommandName Get-Volume -MockWith { + $global:mockedVolume + } + Mock -CommandName Test-Path -MockWith { + return $true + } + It -name 'Get-TargetResource returns a hashtable' -test { + Get-TargetResource -VIELocation $VIELocation | Should Be 'System.Collections.Hashtable' + } + + It -name 'Test-TargetResource returns true or false' -test { + (Test-TargetResource -VIELocation $VIELocation -Ensure Present).GetType() -as [string] | Should Be 'bool' + } + } + + Describe -Name "Testing $($Global:DSCResourceName)\Get-TargetResource present/absent logic" -Fixture { + foreach ($drivetest in $global:mockedCSV ) + { + if ($drivetest.driveLetter -in $global:mockedVolume.driveLetter) + { + Mock -CommandName Import-CSV -MockWith { + $drivetest + } + Mock -CommandName Get-Volume -MockWith { + $global:mockedVolume + } + Mock -CommandName Test-Path -MockWith { + return $true + } + It -name "Get-TargetResource should return present for drive letter ($($drivetest.driveletter))" -test { + (Get-TargetResource -VIELocation $VIELocation).Values | Should Be 'Present' + } + } + else + { + Mock -CommandName Import-CSV -MockWith { + $drivetest + } + Mock -CommandName Get-Volume -MockWith { + $global:mockedVolume + } + Mock -CommandName Test-Path -MockWith { + return $true + } + It -name "Get-TargetResource should return absent for drive letter ($($drivetest.driveletter))" -test { + (Get-TargetResource -VIELocation $VIELocation).Values | Should Be 'absent' + } + } + } + } + + Describe -Name "Testing $($Global:DSCResourceName)\Get-TargetResource present/absent logic" -Fixture { + foreach ($drivetest in $global:mockedCSV ) + { + if ($drivetest.driveLetter -in $global:mockedVolume.driveLetter) + { + Mock -CommandName Import-CSV -MockWith { + $drivetest + } + Mock -CommandName Get-Volume -MockWith { + $global:mockedVolume + } + Mock -CommandName Test-Path -MockWith { + return $true + } + It -name "Test-TargetResource should return true for drive letter ($($drivetest.driveletter))" -test { + Test-TargetResource -VIELocation $VIELocation -Ensure Present | Should Be 'True' + } + } + else + { + Mock -CommandName Import-CSV -MockWith { + $drivetest + } + Mock -CommandName Get-Volume -MockWith { + $global:mockedVolume + } + Mock -CommandName Test-Path -MockWith { + return $true + } + It -name "Test-TargetResource should return false for drive letter ($($drivetest.driveletter))" -test { + Test-TargetResource -VIELocation $VIELocation -Ensure Absent | Should Be 'True' + } + } + } + } +} \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..bd4c6ae --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,81 @@ +# See http://www.appveyor.com/docs/appveyor-yml for many more options + +# Skip on updates to the readme. +# We can force this by adding [skip ci] or [ci skip] anywhere in commit message + +skip_commits: + message: /updated readme.*|update readme.*s/ + +#---------------------------------# +# environment configuration # +#---------------------------------# +version: '2.6.{build}' +os: WMF 5 +pull_requests: + do_not_increment_build_number: true +environment: + my_secvariable: + secure: exKd6wdRVbZTS5qJV/Lkvr/NcaVHK6paUkVAjTWyT4AAlcB7pMLOi9gZfscByrA7 +install: + - ps: | + $VerbosePreference = 'SilentlyContinue' + $env:psmodulepath = $env:psmodulepath + ';' + 'C:\projects' + Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force + Install-Module -Name Pester -Repository PSGallery -Force + +#---------------------------------# +# build configuration # +#---------------------------------# + +build: false + +#---------------------------------# +# test configuration # +#---------------------------------# + +test_script: + - ps: $res = Invoke-Pester -Path '.\Tests' -OutputFormat NUnitXml -OutputFile TestsResults.xml -PassThru + - ps: (New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\TestsResults.xml)) + - ps: if ($res.FailedCount -gt 0) { throw "$($res.FailedCount) tests failed."} + + +#---------------------------------# +# deployment configuration # +#---------------------------------# + +# scripts to run before deployment +deploy_script: + - ps: | + Write-Verbose -Message 'Creating project artifact' -Verbose + $stagingDirectory = (Resolve-Path -Path ..).Path + $manifest = Join-Path -Path $pwd -ChildPath '*.psd1' -Resolve + (Get-Content $manifest -Raw).Replace('2.6', $env:APPVEYOR_BUILD_VERSION) | Out-File $manifest + $zipFilePath = Join-Path -Path $stagingDirectory -ChildPath "$env:APPVEYOR_PROJECT_NAME-$env:APPVEYOR_BUILD_VERSION.zip" + Add-Type -AssemblyName System.IO.Compression.FileSystem + [System.IO.Compression.ZipFile]::CreateFromDirectory($pwd, $zipFilePath) + @( + # You can add other artifacts here + $zipFilePath + ) | ForEach-Object -Process { + Write-Verbose -Message "Pushing package $_ as Appveyor artifact" -Verbose + Push-AppveyorArtifact $_ + } + + if($Env:APPVEYOR_REPO_TAG -eq 'true') + { + if(Get-Command -Name Get-PackageProvider -ErrorAction SilentlyContinue) + { + Get-PackageProvider -Name NuGet -ForceBootstrap + $module = Join-Path -Path $pwd -ChildPath '\DSCResources\*\*.psm1' -Resolve + Import-Module $module + Publish-Module -Name $env:APPVEYOR_PROJECT_NAME -NuGetApiKey $env:my_secvariable + } + else + { + Write-Verbose -Message 'PSGallery not supported' -Verbose + } + } + else + { + Write-Verbose -Message 'Commit is not a tag, skipping deploy!' -Verbose + } diff --git a/xDSCSEPVIE.psd1 b/xDSCSEPVIE.psd1 index bf8018d..442fe66 100644 Binary files a/xDSCSEPVIE.psd1 and b/xDSCSEPVIE.psd1 differ