@@ -75,12 +75,14 @@ func TestFileStateTryRestore(t *testing.T) {
75
75
testCases := []struct {
76
76
description string
77
77
stateFileContent string
78
+ policyName string
78
79
expErr string
79
80
expectedState * stateMemory
80
81
}{
81
82
{
82
83
"Invalid JSON - empty file" ,
83
84
"\n " ,
85
+ "none" ,
84
86
"state file: could not unmarshal, corrupted state file" ,
85
87
& stateMemory {
86
88
assignments : ContainerCPUAssignments {},
@@ -90,6 +92,7 @@ func TestFileStateTryRestore(t *testing.T) {
90
92
{
91
93
"Invalid JSON - invalid content" ,
92
94
"{" ,
95
+ "none" ,
93
96
"state file: could not unmarshal, corrupted state file" ,
94
97
& stateMemory {
95
98
assignments : ContainerCPUAssignments {},
@@ -99,6 +102,7 @@ func TestFileStateTryRestore(t *testing.T) {
99
102
{
100
103
"Try restore defaultCPUSet only" ,
101
104
`{"policyName": "none", "defaultCpuSet": "4-6"}` ,
105
+ "none" ,
102
106
"" ,
103
107
& stateMemory {
104
108
assignments : ContainerCPUAssignments {},
@@ -108,6 +112,7 @@ func TestFileStateTryRestore(t *testing.T) {
108
112
{
109
113
"Try restore defaultCPUSet only - invalid name" ,
110
114
`{"policyName": "none", "defaultCpuSet" "4-6"}` ,
115
+ "none" ,
111
116
"" ,
112
117
& stateMemory {
113
118
assignments : ContainerCPUAssignments {},
@@ -123,6 +128,7 @@ func TestFileStateTryRestore(t *testing.T) {
123
128
"container2": "1-3"
124
129
}
125
130
}` ,
131
+ "none" ,
126
132
"" ,
127
133
& stateMemory {
128
134
assignments : ContainerCPUAssignments {
@@ -132,9 +138,24 @@ func TestFileStateTryRestore(t *testing.T) {
132
138
defaultCPUSet : cpuset .NewCPUSet (),
133
139
},
134
140
},
141
+ {
142
+ "Try restore invalid policy name" ,
143
+ `{
144
+ "policyName": "A",
145
+ "defaultCpuSet": "0-7",
146
+ "entries": {}
147
+ }` ,
148
+ "B" ,
149
+ "policy configured \" B\" != policy from state file \" A\" " ,
150
+ & stateMemory {
151
+ assignments : ContainerCPUAssignments {},
152
+ defaultCPUSet : cpuset .NewCPUSet (),
153
+ },
154
+ },
135
155
{
136
156
"Try restore invalid assignments" ,
137
157
`{"entries": }` ,
158
+ "none" ,
138
159
"state file: could not unmarshal, corrupted state file" ,
139
160
& stateMemory {
140
161
assignments : ContainerCPUAssignments {},
@@ -151,6 +172,7 @@ func TestFileStateTryRestore(t *testing.T) {
151
172
"container2": "1-3"
152
173
}
153
174
}` ,
175
+ "none" ,
154
176
"" ,
155
177
& stateMemory {
156
178
assignments : ContainerCPUAssignments {
@@ -166,6 +188,7 @@ func TestFileStateTryRestore(t *testing.T) {
166
188
"policyName": "none",
167
189
"defaultCpuSet": "2-sd"
168
190
}` ,
191
+ "none" ,
169
192
"state file: could not parse state file" ,
170
193
& stateMemory {
171
194
assignments : ContainerCPUAssignments {},
@@ -182,6 +205,7 @@ func TestFileStateTryRestore(t *testing.T) {
182
205
"container2": "1-3"
183
206
}
184
207
}` ,
208
+ "none" ,
185
209
"state file: could not parse state file" ,
186
210
& stateMemory {
187
211
assignments : ContainerCPUAssignments {},
@@ -191,6 +215,7 @@ func TestFileStateTryRestore(t *testing.T) {
191
215
{
192
216
"TryRestoreState creates empty state file" ,
193
217
"" ,
218
+ "none" ,
194
219
"" ,
195
220
& stateMemory {
196
221
assignments : ContainerCPUAssignments {},
@@ -214,7 +239,7 @@ func TestFileStateTryRestore(t *testing.T) {
214
239
defer os .Remove (sfilePath .Name ())
215
240
216
241
logData , fileState := stderrCapture (t , func () State {
217
- return NewFileState (sfilePath .Name (), "none" )
242
+ return NewFileState (sfilePath .Name (), tc . policyName )
218
243
})
219
244
220
245
if tc .expErr != "" {
0 commit comments