@@ -31,16 +31,7 @@ import (
31
31
const testCheckpoint = "pod_status_manager_state"
32
32
33
33
func newTestStateCheckpoint (t * testing.T ) * stateCheckpoint {
34
- // create temp dir
35
- testingDir , err := os .MkdirTemp ("" , "pod_resource_allocation_state_test" )
36
- if err != nil {
37
- t .Fatal (err )
38
- }
39
- t .Cleanup (func () {
40
- if err := os .RemoveAll (testingDir ); err != nil {
41
- t .Fatal (err )
42
- }
43
- })
34
+ testingDir := getTestDir (t )
44
35
cache := NewStateMemory ()
45
36
checkpointManager , err := checkpointmanager .NewCheckpointManager (testingDir )
46
37
require .NoError (t , err , "failed to create checkpoint manager" )
@@ -55,9 +46,7 @@ func newTestStateCheckpoint(t *testing.T) *stateCheckpoint {
55
46
56
47
func getTestDir (t * testing.T ) string {
57
48
testingDir , err := os .MkdirTemp ("" , "pod_resource_allocation_state_test" )
58
- if err != nil {
59
- t .Fatal (err )
60
- }
49
+ require .NoError (t , err , "failed to create temp dir" )
61
50
t .Cleanup (func () {
62
51
if err := os .RemoveAll (testingDir ); err != nil {
63
52
t .Fatal (err )
@@ -146,16 +135,6 @@ func Test_stateCheckpoint_formatUpgraded(t *testing.T) {
146
135
// prepare old checkpoint, ResizeStatusEntries is unset,
147
136
// pretend that the old checkpoint is unaware for the field ResizeStatusEntries
148
137
const checkpointContent = `{"data":"{\"allocationEntries\":{\"pod1\":{\"container1\":{\"requests\":{\"cpu\":\"1Ki\",\"memory\":\"1Ki\"}}}}}","checksum":1555601526}`
149
- checkpoint := & Checkpoint {}
150
- err := checkpoint .UnmarshalCheckpoint ([]byte (checkpointContent ))
151
- require .NoError (t , err , "failed to unmarshal checkpoint" )
152
-
153
- err = sc .checkpointManager .CreateCheckpoint (sc .checkpointName , checkpoint )
154
- require .NoError (t , err , "failed to create old checkpoint" )
155
-
156
- err = sc .restoreState ()
157
- require .NoError (t , err , "failed to restore state" )
158
-
159
138
expectedPodResourceAllocationInfo := & PodResourceAllocationInfo {
160
139
AllocationEntries : map [string ]map [string ]v1.ResourceRequirements {
161
140
"pod1" : {
@@ -169,6 +148,16 @@ func Test_stateCheckpoint_formatUpgraded(t *testing.T) {
169
148
},
170
149
ResizeStatusEntries : map [string ]v1.PodResizeStatus {},
171
150
}
151
+ checkpoint := & Checkpoint {}
152
+ err := checkpoint .UnmarshalCheckpoint ([]byte (checkpointContent ))
153
+ require .NoError (t , err , "failed to unmarshal checkpoint" )
154
+
155
+ err = sc .checkpointManager .CreateCheckpoint (sc .checkpointName , checkpoint )
156
+ require .NoError (t , err , "failed to create old checkpoint" )
157
+
158
+ err = sc .restoreState ()
159
+ require .NoError (t , err , "failed to restore state" )
160
+
172
161
actualPodResourceAllocationInfo := & PodResourceAllocationInfo {}
173
162
actualPodResourceAllocationInfo .AllocationEntries = sc .cache .GetPodResourceAllocation ()
174
163
actualPodResourceAllocationInfo .ResizeStatusEntries = sc .cache .GetResizeStatus ()
0 commit comments