@@ -14,25 +14,28 @@ Describe 'FileSys resoure tests' {
14
14
}
15
15
16
16
$resultJson = dsc config set -f " $PSScriptRoot /../examples/filesys_create.dsc.yaml" | ConvertFrom-Json
17
+ $LASTEXITCODE | Should - Be 0
17
18
$resultJson.hadErrors | Should - BeFalse
18
19
$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
23
21
Get-Item $resultJson.results.result.afterState.path | Should - BeOfType ' System.IO.FileInfo'
24
22
}
25
23
26
24
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
28
31
$resultJson.hadErrors | Should - BeFalse
29
32
$resultJson.results.result.afterState.path | Should - Exist
30
33
Get-Item $resultJson.results.result.afterState.path | Should - BeOfType ' System.IO.DirectoryInfo'
31
-
32
34
}
33
35
34
36
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
36
39
$resultJson.hadErrors | Should - BeFalse
37
40
38
41
$resultFilePath = $resultJson.results.result.afterState.path
@@ -45,45 +48,93 @@ Describe 'FileSys resoure tests' {
45
48
New-Item - Path $testFile - ItemType File - Force | Out-Null
46
49
}
47
50
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
49
53
$resultJson.hadErrors | Should - BeFalse
50
54
$resultFilePath = $resultJson.results.result.afterState.path
51
55
$resultFilePath | Should -Not - Exist
52
56
}
53
57
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
57
61
}
58
62
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
60
67
$resultJson.hadErrors | Should - BeFalse
61
68
$resultDirPath = $resultJson.results.result.afterState.path
62
69
$resultDirPath | Should -Not - Exist
63
70
}
64
71
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
69
75
}
70
76
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
72
82
$resultJson.hadErrors | Should - BeFalse
73
83
$resultDirPath = $resultJson.results.result.afterState.path
74
84
$resultDirPath | Should -Not - Exist
75
85
}
76
86
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
82
90
}
83
91
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
85
98
$resultJson.hadErrors | Should - BeFalse
86
99
$resultDirPath = $resultJson.results.result.afterState.path
87
100
$resultDirPath | Should -Not - Exist
88
101
}
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
+ }
89
140
}
0 commit comments