@@ -126,6 +126,69 @@ Describe "CheckForUpdates Action Tests" {
126
126
}
127
127
}
128
128
129
-
130
129
# Call action
131
130
}
131
+
132
+ Describe " CheckForUpdates Action: CheckForUpdates.HelperFunctions.ps1" {
133
+ BeforeAll {
134
+ $actionName = " CheckForUpdates"
135
+ $scriptRoot = Join-Path $PSScriptRoot " ..\Actions\$actionName " - Resolve
136
+ Import-Module (Join-Path $scriptRoot " ..\Github-Helper.psm1" ) - DisableNameChecking - Force
137
+ . (Join-Path - Path $scriptRoot - ChildPath " CheckForUpdates.HelperFunctions.ps1" )
138
+ [Diagnostics.CodeAnalysis.SuppressMessageAttribute (' PSUseDeclaredVarsMoreThanAssignments' , ' actionScript' , Justification = ' False positive.' )]
139
+ $tmpSrcFile = Join-Path $PSScriptRoot " tempSrcFile.json"
140
+ [Diagnostics.CodeAnalysis.SuppressMessageAttribute (' PSUseDeclaredVarsMoreThanAssignments' , ' actionScript' , Justification = ' False positive.' )]
141
+ $tmpDstFile = Join-Path $PSScriptRoot " tempDestFile.json"
142
+ }
143
+
144
+ AfterEach {
145
+ # Clean up temporary files
146
+ if (Test-Path $tmpSrcFile ) {
147
+ Remove-Item - Path $tmpSrcFile - Force
148
+ }
149
+ if (Test-Path $tmpDstFile ) {
150
+ Remove-Item - Path $tmpDstFile - Force
151
+ }
152
+ }
153
+
154
+ It ' GetModifiedSettingsContent returns correct content when destination file is not empty' {
155
+ # Create settings files with the content
156
+ @ { " `$ schema" = " someSchema" ; " srcSetting" = " value1" } | ConvertTo-Json - Depth 10 | Out-File - FilePath $tmpSrcFile - Force
157
+ @ { " setting1" = " value2" } | ConvertTo-Json - Depth 10 | Out-File - FilePath $tmpDstFile - Force
158
+
159
+ $modifiedContentJson = GetModifiedSettingsContent - srcSettingsFile $tmpSrcFile - dstSettingsFile $tmpDstFile
160
+
161
+ $modifiedContent = $modifiedContentJson | ConvertFrom-Json
162
+ $modifiedContent | Should -Not - BeNullOrEmpty
163
+ $modifiedContent.PSObject.Properties.Name.Count | Should - Be 2 # setting1 and $schema
164
+ $modifiedContent ." setting1" | Should - Be " value2"
165
+ $modifiedContent ." `$ schema" | Should - Be " someSchema"
166
+ }
167
+
168
+ It ' GetModifiedSettingsContent returns correct content when destination file is empty' {
169
+ # Create only the source file
170
+ @ { " `$ schema" = " someSchema" ; " srcSetting" = " value1" } | ConvertTo-Json - Depth 10 | Out-File - FilePath $tmpSrcFile - Force
171
+ ' ' | Out-File - FilePath $tmpDstFile - Force
172
+ $modifiedContentJson = GetModifiedSettingsContent - srcSettingsFile $tmpSrcFile - dstSettingsFile $tmpDstFile
173
+
174
+ $modifiedContent = $modifiedContentJson | ConvertFrom-Json
175
+ $modifiedContent | Should -Not - BeNullOrEmpty
176
+ @ ($modifiedContent.PSObject.Properties.Name ).Count | Should - Be 2 # srcSetting and $schema
177
+ $modifiedContent ." `$ schema" | Should - Be " someSchema"
178
+ $modifiedContent ." srcSetting" | Should - Be " value1"
179
+ }
180
+
181
+ It ' GetModifiedSettingsContent returns correct content when destination file does not exist' {
182
+ # Create only the source file
183
+ @ { " `$ schema" = " someSchema" ; " srcSetting" = " value1" } | ConvertTo-Json - Depth 10 | Out-File - FilePath $tmpSrcFile - Force
184
+
185
+ Test-Path $tmpDstFile | Should - Be $false
186
+ $modifiedContentJson = GetModifiedSettingsContent - srcSettingsFile $tmpSrcFile - dstSettingsFile $tmpDstFile
187
+
188
+ $modifiedContent = $modifiedContentJson | ConvertFrom-Json
189
+ $modifiedContent | Should -Not - BeNullOrEmpty
190
+ $modifiedContent.PSObject.Properties.Name.Count | Should - Be 2 # srcSetting and $schema
191
+ $modifiedContent ." srcSetting" | Should - Be " value1"
192
+ $modifiedContent ." `$ schema" | Should - Be " someSchema"
193
+ }
194
+ }
0 commit comments