@@ -8,62 +8,67 @@ BeforeAll {
88}
99
1010Describe ' StateManager Module' {
11+ BeforeEach {
12+ $testStateDir = Join-Path $TestDrive ' state'
13+ InModuleScope StateManager {
14+ $script :StateDir = $using :testStateDir
15+ $script :HistoryDir = Join-Path $using :testStateDir ' history'
16+ }
17+ }
18+
1119 Context ' New-RunState' {
1220 It ' Should create a new run state file' {
13- $stateDir = Join-Path $TestDrive ' state'
1421 $state = New-RunState - RunId ' test-001' - Solution ' VMFleet' `
15- - Phases @ (' Install' , ' Deploy' , ' Test' ) - StateDirectory $stateDir
22+ - Phases @ (' Install' , ' Deploy' , ' Test' )
1623
1724 $state | Should -Not - BeNullOrEmpty
1825 $state.run_id | Should - Be ' test-001'
1926 $state.solution | Should - Be ' VMFleet'
2027 $state.phases.Count | Should - Be 3
2128
22- Test-Path (Join-Path $stateDir ' test-001.json' ) | Should - BeTrue
29+ $stateDir = InModuleScope StateManager { $script :StateDir }
30+ Test-Path (Join-Path $stateDir ' run-state.json' ) | Should - BeTrue
2331 }
2432 }
2533
2634 Context ' Update-RunPhase' {
2735 It ' Should update phase status' {
28- $stateDir = Join-Path $TestDrive ' state2'
2936 New-RunState - RunId ' test-002' - Solution ' VMFleet' `
30- - Phases @ (' Install' , ' Deploy' ) - StateDirectory $stateDir
37+ - Phases @ (' Install' , ' Deploy' )
3138
32- Update-RunPhase - RunId ' test-002 ' - Phase ' Install' - Status ' Running' - StateDirectory $stateDir
33- $state = Get-RunState - StateDirectory $stateDir
39+ Update-RunPhase - Phase ' Install' - Status ' Running'
40+ $state = Get-RunState
3441
35- ( $state.phases | Where-Object { $_ .name -eq ' Install' }) .status | Should - Be ' Running'
42+ $state.phases. Install.status | Should - Be ' Running'
3643 }
3744
3845 It ' Should set start_time when status is Running' {
39- $stateDir = Join-Path $TestDrive ' state3'
4046 New-RunState - RunId ' test-003' - Solution ' VMFleet' `
41- - Phases @ (' Install' ) - StateDirectory $stateDir
47+ - Phases @ (' Install' )
4248
43- Update-RunPhase - RunId ' test-003 ' - Phase ' Install' - Status ' Running ' - StateDirectory $stateDir
44- $state = Get-RunState - StateDirectory $stateDir
49+ Update-RunPhase - Phase ' Install' - Status ' running '
50+ $state = Get-RunState
4551
46- ( $state.phases | Where-Object { $_ .name -eq ' Install' }).start_time | Should -Not - BeNullOrEmpty
52+ $state.phases. Install.started_at | Should -Not - BeNullOrEmpty
4753 }
4854 }
4955
5056 Context ' Test-PhaseCompleted' {
5157 It ' Should return true for completed phases' {
52- $stateDir = Join-Path $TestDrive ' state4'
5358 New-RunState - RunId ' test-004' - Solution ' VMFleet' `
54- - Phases @ (' Install' ) - StateDirectory $stateDir
59+ - Phases @ (' Install' )
5560
56- Update-RunPhase - RunId ' test-004 ' - Phase ' Install' - Status ' Completed ' - StateDirectory $stateDir
61+ Update-RunPhase - Phase ' Install' - Status ' completed '
5762
58- Test-PhaseCompleted - RunId ' test-004 ' - Phase ' Install' - StateDirectory $stateDir | Should - BeTrue
63+ Test-PhaseCompleted - Phase ' Install' | Should - BeTrue
5964 }
6065
6166 It ' Should return false for pending phases' {
62- $stateDir = Join-Path $TestDrive ' state5'
6367 New-RunState - RunId ' test-005' - Solution ' VMFleet' `
64- - Phases @ (' Install' ) - StateDirectory $stateDir
68+ - Phases @ (' Install' )
6569
66- Test-PhaseCompleted - RunId ' test-005 ' - Phase ' Install' - StateDirectory $stateDir | Should - BeFalse
70+ Test-PhaseCompleted - Phase ' Install' | Should - BeFalse
6771 }
6872 }
6973}
74+
0 commit comments