MCPcopy Index your code
hub / github.com/flant/shell-operator / TestTaskStorage_ProcessResult

Function TestTaskStorage_ProcessResult

pkg/task/queue/task_storage_test.go:185–234  ·  view source on GitHub ↗

TestTaskStorage_ProcessResult tests the ProcessResult operation

(t *testing.T)

Source from the content-addressed store, hash-verified

183
184// TestTaskStorage_ProcessResult tests the ProcessResult operation
185func TestTaskStorage_ProcessResult(t *testing.T) {
186 ts := newTaskStorage()
187
188 task1 := task.NewTask("test1")
189 task2 := task.NewTask("test2")
190 headTask := task.NewTask("head")
191 tailTask := task.NewTask("tail")
192 afterTask := task.NewTask("after")
193
194 ts.AddLast(task1, task2)
195
196 // Create a TaskResult for successful processing
197 result := &TaskResult{
198 Status: Success,
199 }
200 result.AddHeadTasks(headTask)
201 result.AddTailTasks(tailTask)
202 result.AddAfterTasks(afterTask)
203
204 // Process the result for task1
205 ts.ProcessResult(*result, task1)
206
207 snapshot := ts.GetSnapshot()
208 if len(snapshot) != 4 {
209 t.Errorf("Expected 4 tasks after ProcessResult, got %d", len(snapshot))
210 }
211
212 // Order should be: headTask, afterTask, task2, tailTask
213 if snapshot[0] != headTask || snapshot[1] != afterTask || snapshot[2] != task2 || snapshot[3] != tailTask {
214 t.Error("ProcessResult failed: incorrect task order")
215 }
216
217 // Test with Fail status (task should not be removed)
218 ts = newTaskStorage()
219 ts.AddLast(task1)
220
221 failResult := &TaskResult{Status: Fail}
222 failResult.AddHeadTasks(task.NewTask("fail-head"))
223
224 ts.ProcessResult(*failResult, task1)
225
226 snapshot = ts.GetSnapshot()
227 if len(snapshot) != 2 {
228 t.Errorf("Expected 2 tasks after Fail ProcessResult, got %d", len(snapshot))
229 }
230
231 if snapshot[0].GetType() != "fail-head" || snapshot[1] != task1 {
232 t.Error("ProcessResult with Fail status failed")
233 }
234}
235
236// TestTaskStorage_SnapshotAndIteration tests GetSnapshot and Iterate operations
237func TestTaskStorage_SnapshotAndIteration(t *testing.T) {

Callers

nothing calls this directly

Calls 10

AddHeadTasksMethod · 0.95
AddTailTasksMethod · 0.95
AddAfterTasksMethod · 0.95
NewTaskFunction · 0.92
newTaskStorageFunction · 0.85
ProcessResultMethod · 0.80
AddLastMethod · 0.65
GetTypeMethod · 0.65
GetSnapshotMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected