From e0bde76dd07363c2b4ee6986b6585380761c0298 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Fri, 28 Sep 2018 18:54:20 +1200 Subject: [PATCH 1/3] Change IniSettingsFile unit tests to be non-destructive --- .MetaTestOptIn.json | 5 +- CHANGELOG.md | 7 + TestFile.txt | 25 ---- Tests/Unit/DSR_IniSettingsFile.Tests.ps1 | 176 ++++++++++++++++++++--- appveyor.yml | 4 +- 5 files changed, 166 insertions(+), 51 deletions(-) delete mode 100644 TestFile.txt diff --git a/.MetaTestOptIn.json b/.MetaTestOptIn.json index 6f385f8..a5f60a3 100644 --- a/.MetaTestOptIn.json +++ b/.MetaTestOptIn.json @@ -6,5 +6,8 @@ "Common Tests - Required Script Analyzer Rules", "Common Tests - Flagged Script Analyzer Rules", "Common Tests - New Error-Level Script Analyzer Rules", - "Common Tests - Custom Script Analyzer Rules" + "Common Tests - Custom Script Analyzer Rules", + "Common Tests - Validate Example Files To Be Published", + "Common Tests - Validate Markdown Links", + "Common Tests - Relative Path Length" ] diff --git a/CHANGELOG.md b/CHANGELOG.md index 33df562..ba514fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,13 @@ - Refactor Test/Set-TargetResource in ReplaceText to be able to add a key if it doesn't exist but should -Fixes [Issue#20](https://github.com/PlagueHO/FileContentDsc/issues/20). +- Opted into common tests: + - Common Tests - Validate Example Files To Be Published + - Common Tests - Validate Markdown Links + - Common Tests - Relative Path Length + - Common Tests - Relative Path Length +- Correct test context description in IniSettingsFile tests to include 'When'. +- Change IniSettingsFile unit tests to be non-destructive - fixes [Issue #22](https://github.com/PowerShell/FileContentDsc/issues/22). ## 1.0.0.0 diff --git a/TestFile.txt b/TestFile.txt deleted file mode 100644 index 2d9e0de..0000000 --- a/TestFile.txt +++ /dev/null @@ -1,25 +0,0 @@ -Setting1=Value1 -Setting.Two='Value2' -Setting.Two='Value3' -Setting.Two='TestText' -Setting3.Test=Value4 - -Setting.NotExist='TestText'Setting1=Value1 -Setting.Two='Value2' -Setting.Two='Value3' -Setting.Two='TestText' -Setting3.Test=Value4 - -Setting.NotExist='TestText'Setting1=Value1 -Setting.Two='Value2' -Setting.Two='Value3' -Setting.Two='TestText' -Setting3.Test=Value4 - -Setting.NotExist='TestText'Setting1=Value1 -Setting.Two='Value2' -Setting.Two='Value3' -Setting.Two='TestText' -Setting3.Test=Value4 - -Setting.NotExist='TestText' \ No newline at end of file diff --git a/Tests/Unit/DSR_IniSettingsFile.Tests.ps1 b/Tests/Unit/DSR_IniSettingsFile.Tests.ps1 index 969a7eb..066edda 100644 --- a/Tests/Unit/DSR_IniSettingsFile.Tests.ps1 +++ b/Tests/Unit/DSR_IniSettingsFile.Tests.ps1 @@ -43,7 +43,7 @@ try #region Function Get-TargetResource Describe 'DSR_IniSettingsFile\Get-TargetResource' { - Context 'File exists and entry can be found' { + Context 'When file exists and entry can be found' { # verifiable (should be called) mocks Mock ` -CommandName Assert-ParametersValid ` @@ -94,7 +94,7 @@ try } } - Context 'File exists and entry can not be found' { + Context 'When file exists and entry can not be found' { # verifiable (should be called) mocks Mock ` -CommandName Assert-ParametersValid ` @@ -149,13 +149,23 @@ try #region Function Set-TargetResource Describe 'DSR_IniSettingsFile\Set-TargetResource' { - Context 'File exists and text is passed' { + Context 'When file exists and text is passed' { # verifiable (should be called) mocks Mock ` -CommandName Assert-ParametersValid ` -ModuleName 'DSR_IniSettingsFile' ` -Verifiable + Mock ` + -CommandName Test-Path ` + -ParameterFilter { + ($Path -eq $script:testTextFile) + } ` + -MockWith { $true } ` + -Verifiable + + Mock -CommandName Out-File + Mock ` -CommandName Set-IniSettingFileValue ` -ParameterFilter { @@ -180,6 +190,15 @@ try Assert-VerifiableMock Assert-MockCalled -CommandName Assert-ParametersValid -Exactly 1 + Assert-MockCalled ` + -CommandName Test-Path ` + -ParameterFilter { + ($Path -eq $script:testTextFile) + } ` + -Exactly 1 + + Assert-MockCalled -CommandName Out-File -Exactly 0 + Assert-MockCalled ` -CommandName Set-IniSettingFileValue ` -ParameterFilter { @@ -192,13 +211,23 @@ try } } - Context 'File exists and secret is passed' { + Context 'When file exists and secret is passed' { # verifiable (should be called) mocks Mock ` -CommandName Assert-ParametersValid ` -ModuleName 'DSR_IniSettingsFile' ` -Verifiable + Mock ` + -CommandName Test-Path ` + -ParameterFilter { + ($Path -eq $script:testTextFile) + } ` + -MockWith { $true } ` + -Verifiable + + Mock -CommandName Out-File + Mock ` -CommandName Set-IniSettingFileValue ` -ParameterFilter { @@ -224,6 +253,15 @@ try Assert-VerifiableMock Assert-MockCalled -CommandName Assert-ParametersValid -Exactly 1 + Assert-MockCalled ` + -CommandName Test-Path ` + -ParameterFilter { + ($Path -eq $script:testTextFile) + } ` + -Exactly 1 + + Assert-MockCalled -CommandName Out-File -Exactly 0 + Assert-MockCalled ` -CommandName Set-IniSettingFileValue ` -ParameterFilter { @@ -236,7 +274,7 @@ try } } - Context 'File does not exist' { + Context 'When file does not exist' { # verifiable (should be called) mocks Mock ` -CommandName Assert-ParametersValid ` @@ -244,24 +282,28 @@ try -Verifiable Mock ` - -CommandName Set-IniSettingFileValue ` + -CommandName Test-Path ` -ParameterFilter { - ($path -eq $script:testTextFile) -and ` - ($section -eq $script:testSection) -and ` - ($key -eq $script:testKey) -and ` - ($value -eq $script:testText) + ($Path -eq $script:testTextFile) } ` + -MockWith { $false } ` -Verifiable Mock ` - -CommandName Test-Path ` - -ModuleName 'DSR_IniSettingsFile' ` - -MockWith { $false } ` + -CommandName Out-File ` + -ParameterFilter { + ($FilePath -eq $script:testTextFile) + } ` -Verifiable Mock ` - -CommandName Out-File ` - -ModuleName 'DSR_IniSettingsFile' ` + -CommandName Set-IniSettingFileValue ` + -ParameterFilter { + ($path -eq $script:testTextFile) -and ` + ($section -eq $script:testSection) -and ` + ($key -eq $script:testKey) -and ` + ($value -eq $script:testText) + } ` -Verifiable It 'Should not throw an exception' { @@ -278,6 +320,20 @@ try Assert-VerifiableMock Assert-MockCalled -CommandName Assert-ParametersValid -Exactly 1 + Assert-MockCalled ` + -CommandName Test-Path ` + -ParameterFilter { + ($Path -eq $script:testTextFile) + } ` + -Exactly 1 + + Assert-MockCalled ` + -CommandName Out-File ` + -ParameterFilter { + ($FilePath -eq $script:testTextFile) + } ` + -Exactly 1 + Assert-MockCalled ` -CommandName Set-IniSettingFileValue ` -ParameterFilter { @@ -294,7 +350,7 @@ try #region Function Test-TargetResource Describe 'DSR_ReplaceString\Test-TargetResource' { - Context 'File exists and text is passed and matches' { + Context 'When file exists and text is passed and matches' { # verifiable (should be called) mocks Mock ` -CommandName Assert-ParametersValid ` @@ -302,6 +358,14 @@ try -Verifiable Mock ` + -CommandName Test-Path ` + -ParameterFilter { + ($Path -eq $script:testTextFile) + } ` + -MockWith { $true } ` + -Verifiable + + Mock ` -CommandName Get-IniSettingFileValue ` -ParameterFilter { ($path -eq $script:testTextFile) -and ` @@ -331,6 +395,13 @@ try Assert-VerifiableMock Assert-MockCalled -CommandName Assert-ParametersValid -Exactly 1 + Assert-MockCalled ` + -CommandName Test-Path ` + -ParameterFilter { + ($Path -eq $script:testTextFile) + } ` + -Exactly 1 + Assert-MockCalled ` -CommandName Get-IniSettingFileValue ` -ParameterFilter { @@ -342,13 +413,21 @@ try } } - Context 'File exists and text is passed and does not match' { + Context 'When file exists and text is passed and does not match' { # verifiable (should be called) mocks Mock ` -CommandName Assert-ParametersValid ` -ModuleName 'DSR_IniSettingsFile' ` -Verifiable + Mock ` + -CommandName Test-Path ` + -ParameterFilter { + ($Path -eq $script:testTextFile) + } ` + -MockWith { $true } ` + -Verifiable + Mock ` -CommandName Get-IniSettingFileValue ` -ParameterFilter { @@ -379,6 +458,13 @@ try Assert-VerifiableMock Assert-MockCalled -CommandName Assert-ParametersValid -Exactly 1 + Assert-MockCalled ` + -CommandName Test-Path ` + -ParameterFilter { + ($Path -eq $script:testTextFile) + } ` + -Exactly 1 + Assert-MockCalled ` -CommandName Get-IniSettingFileValue ` -ParameterFilter { @@ -390,13 +476,21 @@ try } } - Context 'File exists and secret text is passed and matches' { + Context 'When file exists and secret text is passed and matches' { # verifiable (should be called) mocks Mock ` -CommandName Assert-ParametersValid ` -ModuleName 'DSR_IniSettingsFile' ` -Verifiable + Mock ` + -CommandName Test-Path ` + -ParameterFilter { + ($Path -eq $script:testTextFile) + } ` + -MockWith { $true } ` + -Verifiable + Mock ` -CommandName Get-IniSettingFileValue ` -ParameterFilter { @@ -428,6 +522,13 @@ try Assert-VerifiableMock Assert-MockCalled -CommandName Assert-ParametersValid -Exactly 1 + Assert-MockCalled ` + -CommandName Test-Path ` + -ParameterFilter { + ($Path -eq $script:testTextFile) + } ` + -Exactly 1 + Assert-MockCalled ` -CommandName Get-IniSettingFileValue ` -ParameterFilter { @@ -439,13 +540,21 @@ try } } - Context 'File exists and text is passed and does not match' { + Context 'When file exists and text is passed and does not match' { # verifiable (should be called) mocks Mock ` -CommandName Assert-ParametersValid ` -ModuleName 'DSR_IniSettingsFile' ` -Verifiable + Mock ` + -CommandName Test-Path ` + -ParameterFilter { + ($Path -eq $script:testTextFile) + } ` + -MockWith { $true } ` + -Verifiable + Mock ` -CommandName Get-IniSettingFileValue ` -ParameterFilter { @@ -477,6 +586,13 @@ try Assert-VerifiableMock Assert-MockCalled -CommandName Assert-ParametersValid -Exactly 1 + Assert-MockCalled ` + -CommandName Test-Path ` + -ParameterFilter { + ($Path -eq $script:testTextFile) + } ` + -Exactly 1 + Assert-MockCalled ` -CommandName Get-IniSettingFileValue ` -ParameterFilter { @@ -488,13 +604,21 @@ try } } - Context 'File does not exist' { + Context 'When file does not exist' { # verifiable (should be called) mocks Mock ` -CommandName Assert-ParametersValid ` -ModuleName 'DSR_IniSettingsFile' ` -Verifiable + Mock ` + -CommandName Test-Path ` + -ParameterFilter { + ($Path -eq $script:testTextFile) + } ` + -MockWith { $false } ` + -Verifiable + Mock ` -CommandName Test-Path ` -ModuleName 'DSR_IniSettingsFile' ` @@ -512,6 +636,14 @@ try It 'Should call the expected mocks' { Assert-VerifiableMock + Assert-MockCalled -CommandName Assert-ParametersValid -Exactly 1 + + Assert-MockCalled ` + -CommandName Test-Path ` + -ParameterFilter { + ($Path -eq $script:testTextFile) + } ` + -Exactly 1 } } } @@ -519,7 +651,7 @@ try #region Function Assert-ParametersValid Describe 'DSR_IniSettingsFile\Assert-ParametersValid' { - Context 'File exists' { + Context 'When file exists' { # verifiable (should be called) mocks Mock ` -CommandName Split-Path ` @@ -548,7 +680,7 @@ try } } - Context 'File parent does not exist' { + Context 'When file parent does not exist' { # verifiable (should be called) mocks Mock ` -CommandName Split-Path ` diff --git a/appveyor.yml b/appveyor.yml index 9977393..9af704d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,10 +1,8 @@ #---------------------------------# # environment configuration # #---------------------------------# -version: 1.0.0.{build} +version: 1.1.0.{build} install: - # Needed for publishing of examples, build worker defaults to core.autocrlf=input. - - git config --global core.autocrlf true - git clone https://github.com/PowerShell/DscResource.Tests - ps: | From d730d784fa2a88c0717f4cf9a6013bf8e64c085b Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Fri, 28 Sep 2018 19:00:20 +1200 Subject: [PATCH 2/3] Update License --- CHANGELOG.md | 1 + LICENSE | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba514fa..2626ba2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ - Common Tests - Relative Path Length - Correct test context description in IniSettingsFile tests to include 'When'. - Change IniSettingsFile unit tests to be non-destructive - fixes [Issue #22](https://github.com/PowerShell/FileContentDsc/issues/22). +- Update to new format LICENSE ## 1.0.0.0 diff --git a/LICENSE b/LICENSE index 53e7e87..d03e93a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ -The MIT License (MIT) +MIT License -Copyright (c) 2017 Daniel Scott-Raynsford. +Copyright (c) Daniel Scott-Raynsford. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -9,13 +9,13 @@ 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 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. +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE From 1061106615735ef66490506c353f0503b4e52027 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Fri, 28 Sep 2018 19:01:38 +1200 Subject: [PATCH 3/3] Added missing CHANGELOG entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2626ba2..0234374 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ - Common Tests - Relative Path Length - Correct test context description in IniSettingsFile tests to include 'When'. - Change IniSettingsFile unit tests to be non-destructive - fixes [Issue #22](https://github.com/PowerShell/FileContentDsc/issues/22). -- Update to new format LICENSE +- Update to new format LICENSE. ## 1.0.0.0