From e0f6b1fa0b66482e8acf0b1a8e81ab85417d2a41 Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Tue, 25 Aug 2015 14:46:29 -0700 Subject: [PATCH 1/4] added New-Item Test Suite --- src/pester-tests/Test-New-Item.Tests.ps1 | 81 ++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/pester-tests/Test-New-Item.Tests.ps1 diff --git a/src/pester-tests/Test-New-Item.Tests.ps1 b/src/pester-tests/Test-New-Item.Tests.ps1 new file mode 100644 index 0000000000..c575312038 --- /dev/null +++ b/src/pester-tests/Test-New-Item.Tests.ps1 @@ -0,0 +1,81 @@ +Describe "Test-New-Item" { + $tmpDirectory = "/tmp" + $testfile = "testfile.txt" + $testfolder = "newDirectory" + + $FullyQualifiedFile = $tmpDirectory + "/" + $testfile + $FullyQualifiedFolder = $tmpDirectory +"/" + $testfolder + + AfterEach { + if (Test-Path $FullyQualifiedFile) + { + { Remove-Item $FullyQualifiedFile -Force} | Should Not Throw + } + + if (Test-Path $FullyQualifiedFolder) + { + { Remove-Item $FullyQualifiedFolder -Recurse -Force } | Should Not Throw + } + } + + It "should call the function without error" { + { New-Item -Name $testfile -Path $tmpDirectory -ItemType file } | Should Not Throw + } + + It "Should create a file without error" { + New-Item -Name $testfile -Path $tmpDirectory -ItemType file + + Test-Path $FullyQualifiedFile | Should Be $true + } + + It "Should create a folder without an error" { + New-Item -Name newDirectory -Path $tmpDirectory -ItemType directory + + Test-Path $FullyQualifiedFolder | Should Be $true + } + + It "Should create a file using the ni alias" { + ni -Name $testfile -Path $tmpDirectory -ItemType file + + Test-Path $FullyQualifiedFile | Should Be $true + } + + It "Should create a file using the Type alias instead of ItemType" { + New-Item -Name $testfile -Path $tmpDirectory -Type file + + Test-Path $FullyQualifiedFile | Should Be $true + } + + It "Should create a file with sample text inside the file using the Value switch" { + $expected = "This is test string" + New-Item -Name $testfile -Path $tmpDirectory -ItemType file -Value $expected + + Test-Path $FullyQualifiedFile | Should Be $true + + Get-Content $FullyQualifiedFile | Should Be $expected + } + + It "Should not create a file when the Name switch is not used and only a directory specified" { + #errorAction used because permissions issue in windows + New-Item -Path $tmpDirectory -ItemType file -ErrorAction SilentlyContinue + + Test-Path $FullyQualifiedFile | Should Be $false + + } + + It "Should create a file when the Name switch is not used but a fully qualified path is specified" { + New-Item -Path $FullyQualifiedFile -ItemType file + + Test-Path $FullyQualifiedFile | Should Be $true + } + + It "Should be able to create a multiple items in different directories" { + $FullyQualifiedFile2 = $tmpDirectory + "/" + "test2.txt" + New-Item -ItemType file -Path $FullyQualifiedFile, $FullyQualifiedFile2 + + Test-Path $FullyQualifiedFile | Should Be $true + Test-Path $FullyQualifiedFile2 | Should Be $true + + Remove-Item $FullyQualifiedFile2 + } +} From e19b2fab4b270965215ea9e5ff598e46f02ec9b3 Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Fri, 4 Sep 2015 15:05:18 -0700 Subject: [PATCH 2/4] added changes from code review testing credentials --- src/pester-tests/Test-New-Item.Tests.ps1 | 58 ++++++++++++++++++------ 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/src/pester-tests/Test-New-Item.Tests.ps1 b/src/pester-tests/Test-New-Item.Tests.ps1 index c575312038..a5fb088736 100644 --- a/src/pester-tests/Test-New-Item.Tests.ps1 +++ b/src/pester-tests/Test-New-Item.Tests.ps1 @@ -1,21 +1,31 @@ -Describe "Test-New-Item" { - $tmpDirectory = "/tmp" - $testfile = "testfile.txt" - $testfolder = "newDirectory" +function Clean-State +{ + if (Test-Path $FullyQualifiedFile) + { + Remove-Item $FullyQualifiedFile -Force + } - $FullyQualifiedFile = $tmpDirectory + "/" + $testfile - $FullyQualifiedFolder = $tmpDirectory +"/" + $testfolder + if (Test-Path $FullyQualifiedFolder) + { + Remove-Item $FullyQualifiedFolder -Recurse -Force + } +} + +Describe "Test-New-Item" { + $tmpDirectory = "/tmp" + $testfile = "testfile.txt" + $testfolder = "newDirectory" + $FullyQualifiedFile = $tmpDirectory + "/" + $testfile + $FullyQualifiedFolder = $tmpDirectory + "/" + $testfolder + + BeforeEach { + Clean-State + } AfterEach { - if (Test-Path $FullyQualifiedFile) - { - { Remove-Item $FullyQualifiedFile -Force} | Should Not Throw - } - - if (Test-Path $FullyQualifiedFolder) - { - { Remove-Item $FullyQualifiedFolder -Recurse -Force } | Should Not Throw - } + Clean-State + Test-Path $FullyQualifiedFile | Should Be $false + Test-Path $FullyQualifiedFolder | Should Be $false } It "should call the function without error" { @@ -78,4 +88,22 @@ Remove-Item $FullyQualifiedFile2 } + + It "Should be able to call the whatif switch without error" { + ( Out-Null -inputobject (New-Item -Name testfile.txt -Path /tmp -ItemType file -WhatIf)) + { $a } | Should Not Throw + } + + It "Should not create a new file when the whatif switch is used" { + # suppress the output of the whatif statement + $a = New-Item -Name $testfile -Path $tmpDirectory -ItemType file -WhatIf + + Out-Null -inputobject $a + + Test-Path $FullyQualifiedFile | Should Be $false + } + + It "Should produce an error when the credentials switch is thrown" { + { New-Item -Name $testfile -Path $tmpDirectory -ItemType file -Credential redmond/USER } | Should Throw "not implemented" + } } From cbace227a9dbbf7bd0003af42ac59f6ea4a962c4 Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Mon, 14 Sep 2015 16:30:33 -0700 Subject: [PATCH 3/4] incorporated changes to pester tests from code review --- src/pester-tests/Test-New-Item.Tests.ps1 | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/pester-tests/Test-New-Item.Tests.ps1 b/src/pester-tests/Test-New-Item.Tests.ps1 index a5fb088736..ae57030969 100644 --- a/src/pester-tests/Test-New-Item.Tests.ps1 +++ b/src/pester-tests/Test-New-Item.Tests.ps1 @@ -22,12 +22,6 @@ Describe "Test-New-Item" { Clean-State } - AfterEach { - Clean-State - Test-Path $FullyQualifiedFile | Should Be $false - Test-Path $FullyQualifiedFolder | Should Be $false - } - It "should call the function without error" { { New-Item -Name $testfile -Path $tmpDirectory -ItemType file } | Should Not Throw } @@ -90,20 +84,16 @@ Describe "Test-New-Item" { } It "Should be able to call the whatif switch without error" { - ( Out-Null -inputobject (New-Item -Name testfile.txt -Path /tmp -ItemType file -WhatIf)) - { $a } | Should Not Throw + { New-Item -Name testfile.txt -Path /tmp -ItemType file -WhatIf } | Should Not Throw } It "Should not create a new file when the whatif switch is used" { - # suppress the output of the whatif statement - $a = New-Item -Name $testfile -Path $tmpDirectory -ItemType file -WhatIf - - Out-Null -inputobject $a + New-Item -Name $testfile -Path $tmpDirectory -ItemType file -WhatIf Test-Path $FullyQualifiedFile | Should Be $false } It "Should produce an error when the credentials switch is thrown" { - { New-Item -Name $testfile -Path $tmpDirectory -ItemType file -Credential redmond/USER } | Should Throw "not implemented" + { New-Item -Name $testfile -Path $tmpDirectory -ItemType file -Credential domain/USER } | Should Throw "not implemented" } } From 2cab69401a84501d8e9e688141adba96a8eeee41 Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Mon, 14 Sep 2015 16:31:28 -0700 Subject: [PATCH 4/4] incorporating updates to monad --- src/monad | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/monad b/src/monad index 9aecfb12f6..378897d1d5 160000 --- a/src/monad +++ b/src/monad @@ -1 +1 @@ -Subproject commit 9aecfb12f69d91908812751e1b69d7c5c8098e07 +Subproject commit 378897d1d5cf19e63fb7faefd301eca6624daf38