1
+ # Copyright (c) Microsoft Corporation.
2
+ # Licensed under the MIT License.
3
+
4
+ Describe ' FileSys resoure tests' {
5
+ BeforeAll {
6
+ $testDir = Join-Path $env: TEMP ' test-dir-resource'
7
+ $testFile = Join-Path $testDir ' test-file-resource.txt'
8
+ $testFileName = ' test-file-resource.txt'
9
+ }
10
+
11
+ It ' Filesys resource can create file' {
12
+ if (Test-Path $testFile ) {
13
+ Remove-Item - Path $testFile - Force
14
+ }
15
+
16
+ $resultJson = dsc config set -f " $PSScriptRoot /../examples/filesys_create.dsc.yaml" | ConvertFrom-Json
17
+ $resultJson.hadErrors | Should - BeFalse
18
+ $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
23
+ Get-Item $resultJson.results.result.afterState.path | Should - BeOfType ' System.IO.FileInfo'
24
+ }
25
+
26
+ It ' Filesys resource can create directory' {
27
+ $resultJson = dsc config set -f " ../examples/filesys_dir_create.dsc.yaml" | ConvertFrom-Json
28
+ $resultJson.hadErrors | Should - BeFalse
29
+ $resultJson.results.result.afterState.path | Should - Exist
30
+ Get-Item $resultJson.results.result.afterState.path | Should - BeOfType ' System.IO.DirectoryInfo'
31
+
32
+ }
33
+
34
+ It ' Filesys resource can create file with content' {
35
+ $resultJson = dsc config set -f " ../examples/filesys_filecontent.dsc.yaml" | ConvertFrom-Json
36
+ $resultJson.hadErrors | Should - BeFalse
37
+
38
+ $resultFilePath = $resultJson.results.result.afterState.path
39
+ $resultFilePath | Should - Exist
40
+ Get-Content $resultFilePath | Should - Be " Hello, World!"
41
+ }
42
+
43
+ It ' Filesys resource can delete a file' {
44
+ if (-not (Test-Path $testFile )) {
45
+ New-Item - Path $testFile - ItemType File - Force | Out-Null
46
+ }
47
+
48
+ $resultJson = dsc config set -f " ../examples/filesys_delete.dsc.yaml" | ConvertFrom-Json
49
+ $resultJson.hadErrors | Should - BeFalse
50
+ $resultFilePath = $resultJson.results.result.afterState.path
51
+ $resultFilePath | Should -Not - Exist
52
+ }
53
+
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
57
+ }
58
+
59
+ $resultJson = dsc config set -f " ../examples/filesys_dir_delete.dsc.yaml" | ConvertFrom-Json
60
+ $resultJson.hadErrors | Should - BeFalse
61
+ $resultDirPath = $resultJson.results.result.afterState.path
62
+ $resultDirPath | Should -Not - Exist
63
+ }
64
+
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
69
+ }
70
+
71
+ $resultJson = dsc config set -f " ../examples/filesys_dir_delete.dsc.yaml" | ConvertFrom-Json
72
+ $resultJson.hadErrors | Should - BeFalse
73
+ $resultDirPath = $resultJson.results.result.afterState.path
74
+ $resultDirPath | Should -Not - Exist
75
+ }
76
+
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
82
+ }
83
+
84
+ $resultJson = dsc config set -f " ../examples/filesys_dir_delete_recursive.dsc.yaml" | ConvertFrom-Json
85
+ $resultJson.hadErrors | Should - BeFalse
86
+ $resultDirPath = $resultJson.results.result.afterState.path
87
+ $resultDirPath | Should -Not - Exist
88
+ }
89
+ }
0 commit comments