@@ -14,25 +14,28 @@ Describe 'FileSys resoure tests' {
1414 }
1515
1616 $resultJson = dsc config set -f " $PSScriptRoot /../examples/filesys_create.dsc.yaml" | ConvertFrom-Json
17+ $LASTEXITCODE | Should - Be 0
1718 $resultJson.hadErrors | Should - BeFalse
1819 $path = $resultJson.results.result.afterState.path
19- $name = $resultJson.results.result.afterState.name
20-
21- $path | Should - Be $env: TEMP
22- (Join-Path $path $name ) | Should - Exist
20+ $path | Should - Exist
2321 Get-Item $resultJson.results.result.afterState.path | Should - BeOfType ' System.IO.FileInfo'
2422 }
2523
2624 It ' Filesys resource can create directory' {
27- $resultJson = dsc config set -f " ../examples/filesys_dir_create.dsc.yaml" | ConvertFrom-Json
25+ if (Test-Path $testDir ) {
26+ Remove-Item - Path $testDir - Force - Recurse
27+ }
28+
29+ $resultJson = dsc config set -f " $PSScriptRoot /../examples/filesys_dir_create.dsc.yaml" | ConvertFrom-Json
30+ $LASTEXITCODE | Should - Be 0
2831 $resultJson.hadErrors | Should - BeFalse
2932 $resultJson.results.result.afterState.path | Should - Exist
3033 Get-Item $resultJson.results.result.afterState.path | Should - BeOfType ' System.IO.DirectoryInfo'
31-
3234 }
3335
3436 It ' Filesys resource can create file with content' {
35- $resultJson = dsc config set -f " ../examples/filesys_filecontent.dsc.yaml" | ConvertFrom-Json
37+ $resultJson = dsc config set -f " $PSScriptRoot /../examples/filesys_filecontent.dsc.yaml" | ConvertFrom-Json
38+ $LASTEXITCODE | Should - Be 0
3639 $resultJson.hadErrors | Should - BeFalse
3740
3841 $resultFilePath = $resultJson.results.result.afterState.path
@@ -45,45 +48,93 @@ Describe 'FileSys resoure tests' {
4548 New-Item - Path $testFile - ItemType File - Force | Out-Null
4649 }
4750
48- $resultJson = dsc config set -f " ../examples/filesys_delete.dsc.yaml" | ConvertFrom-Json
51+ $resultJson = dsc config set -f " $PSScriptRoot /../examples/filesys_delete.dsc.yaml" | ConvertFrom-Json
52+ $LASTEXITCODE | Should - Be 0
4953 $resultJson.hadErrors | Should - BeFalse
5054 $resultFilePath = $resultJson.results.result.afterState.path
5155 $resultFilePath | Should -Not - Exist
5256 }
5357
54- It ' Filesys resource can delete an empty directory' - Pending {
55- if (-not ( Test-Path $testDir ) ) {
56- New -Item - Path $testDir - ItemType Directory - Force | Out-Null
58+ It ' Filesys resource can delete an empty directory' {
59+ if (Test-Path $testDir ) {
60+ Remove -Item - Path $testDir - Force - Recurse
5761 }
5862
59- $resultJson = dsc config set -f " ../examples/filesys_dir_delete.dsc.yaml" | ConvertFrom-Json
63+ New-Item - Path $testDir - ItemType Directory - Force | Out-Null
64+
65+ $resultJson = dsc config set -f " $PSScriptRoot /../examples/filesys_dir_delete.dsc.yaml" | ConvertFrom-Json
66+ $LASTEXITCODE | Should - Be 0
6067 $resultJson.hadErrors | Should - BeFalse
6168 $resultDirPath = $resultJson.results.result.afterState.path
6269 $resultDirPath | Should -Not - Exist
6370 }
6471
65- It ' Filesys resource can delete a non-empty directory' - Pending {
66- if (-not (Test-Path $testDir )) {
67- New-Item - Path $testDir - ItemType Directory - Force | Out-Null
68- New-Item - Path (Join-Path $testDir $testFileName ) - ItemType File - Force | Out-Null
72+ It ' Filesys resource cannot delete a non-empty directory' - Pending {
73+ if (Test-Path $testDir ) {
74+ Remove-Item - Path $testDir - Force - Recurse
6975 }
7076
71- $resultJson = dsc config set -f " ../examples/filesys_dir_delete.dsc.yaml" | ConvertFrom-Json
77+ New-Item - Path $testDir - ItemType Directory - Force | Out-Null
78+ New-Item - Path (Join-Path $testDir $testFileName ) - ItemType File - Force | Out-Null
79+
80+ $resultJson = dsc config set -f " $PSScriptRoot /../examples/filesys_dir_delete.dsc.yaml" | ConvertFrom-Json
81+ $LASTEXITCODE | Should - Be 0
7282 $resultJson.hadErrors | Should - BeFalse
7383 $resultDirPath = $resultJson.results.result.afterState.path
7484 $resultDirPath | Should -Not - Exist
7585 }
7686
77- It ' Filesys resource can delete a directory recursively' - Pending {
78- if (-not (Test-Path $testDir )) {
79- $dirPath = New-Item - Path $testDir - ItemType Directory - Force | Out-Null
80- $subDirPath = New-Item - Path (Join-Path $dirPath ' test-subdir' ) - ItemType Directory - Force | Out-Null
81- New-Item - Path (Join-Path $subDirPath $testFileName ) - ItemType File - Force | Out-Null
87+ It ' Filesys resource can delete a directory recursively' {
88+ if (Test-Path $testDir ) {
89+ Remove-Item - Path $testDir - Force - Recurse
8290 }
8391
84- $resultJson = dsc config set -f " ../examples/filesys_dir_delete_recursive.dsc.yaml" | ConvertFrom-Json
92+ $dirPath = New-Item - Path $testDir - ItemType Directory - Force
93+ $subDirPath = New-Item - Path (Join-Path $dirPath ' test-subdir' ) - ItemType Directory - Force
94+ New-Item - Path (Join-Path $subDirPath $testFileName ) - ItemType File - Force | Out-Null
95+
96+ $resultJson = dsc config set -f " $PSScriptRoot /../examples/filesys_dir_delete_recurse.dsc.yaml" | ConvertFrom-Json
97+ $LASTEXITCODE | Should - Be 0
8598 $resultJson.hadErrors | Should - BeFalse
8699 $resultDirPath = $resultJson.results.result.afterState.path
87100 $resultDirPath | Should -Not - Exist
88101 }
102+
103+ It ' Can create file if parent directory does not exist' {
104+ if (Test-Path $testDir ) {
105+ Remove-Item - Path $testDir - Force - Recurse
106+ }
107+
108+ $resultJson = dsc config set -f " $PSScriptRoot /../examples/filesys_create_parent.dsc.yaml" | ConvertFrom-Json
109+ $LASTEXITCODE | Should - Be 0
110+ $resultJson.hadErrors | Should - BeFalse
111+ $resultJson.results.result.afterState.path | Should - Exist
112+ Get-Item $resultJson.results.result.afterState.path | Should - BeOfType ' System.IO.FileInfo'
113+ }
114+
115+ It ' Can create file with content if parent directory does not exist' {
116+ if (Test-Path $testDir ) {
117+ Remove-Item - Path $testDir - Force - Recurse
118+ }
119+
120+ $resultJson = dsc config set -f " $PSScriptRoot /../examples/filesys_filecontent_parent.dsc.yaml" | ConvertFrom-Json
121+ $LASTEXITCODE | Should - Be 0
122+ $resultJson.hadErrors | Should - BeFalse
123+
124+ $resultFilePath = $resultJson.results.result.afterState.path
125+ $resultFilePath | Should - Exist
126+ Get-Content $resultFilePath | Should - Be " Hello, World!"
127+ }
128+
129+ It ' Can create directory if parent directory does not exist' {
130+ if (Test-Path $testDir ) {
131+ Remove-Item - Path $testDir - Force - Recurse
132+ }
133+
134+ $resultJson = dsc config set -f " $PSScriptRoot /../examples/filesys_dir_create_parent.dsc.yaml" | ConvertFrom-Json
135+ $LASTEXITCODE | Should - Be 0
136+ $resultJson.hadErrors | Should - BeFalse
137+ $resultJson.results.result.afterState.path | Should - Exist
138+ Get-Item $resultJson.results.result.afterState.path | Should - BeOfType ' System.IO.DirectoryInfo'
139+ }
89140}
0 commit comments