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

Function TestTaskStorage_AddBeforeAfter

pkg/task/queue/task_storage_test.go:108–148  ·  view source on GitHub ↗

TestTaskStorage_AddBeforeAfter tests AddBefore and AddAfter operations

(t *testing.T)

Source from the content-addressed store, hash-verified

106
107// TestTaskStorage_AddBeforeAfter tests AddBefore and AddAfter operations
108func TestTaskStorage_AddBeforeAfter(t *testing.T) {
109 ts := newTaskStorage()
110
111 task1 := task.NewTask("test1")
112 task2 := task.NewTask("test2")
113 task3 := task.NewTask("test3")
114 task4 := task.NewTask("test4")
115
116 // Add initial tasks
117 ts.AddLast(task1, task2)
118
119 // Test AddAfter
120 ts.AddAfter(task1.GetId(), task3)
121 snapshot := ts.GetSnapshot()
122 if len(snapshot) != 3 {
123 t.Errorf("Expected 3 tasks, got %d", len(snapshot))
124 }
125
126 if snapshot[0] != task1 || snapshot[1] != task3 || snapshot[2] != task2 {
127 t.Error("AddAfter failed: incorrect order")
128 }
129
130 // Test AddBefore
131 ts.AddBefore(task2.GetId(), task4)
132 snapshot = ts.GetSnapshot()
133 if len(snapshot) != 4 {
134 t.Errorf("Expected 4 tasks, got %d", len(snapshot))
135 }
136
137 if snapshot[0] != task1 || snapshot[1] != task3 || snapshot[2] != task4 || snapshot[3] != task2 {
138 t.Error("AddBefore failed: incorrect order")
139 }
140
141 // Test AddAfter/AddBefore with non-existent ID
142 ts.AddAfter("nonexistent", task.NewTask("should-not-be-added"))
143 ts.AddBefore("nonexistent", task.NewTask("should-not-be-added"))
144
145 if ts.Length() != 4 {
146 t.Errorf("Expected length 4 (no tasks should be added for non-existent IDs), got %d", ts.Length())
147 }
148}
149
150// TestTaskStorage_DeleteFunc tests the DeleteFunc operation
151func TestTaskStorage_DeleteFunc(t *testing.T) {

Callers

nothing calls this directly

Calls 9

GetIdMethod · 0.95
NewTaskFunction · 0.92
newTaskStorageFunction · 0.85
AddLastMethod · 0.65
AddAfterMethod · 0.45
GetSnapshotMethod · 0.45
ErrorMethod · 0.45
AddBeforeMethod · 0.45
LengthMethod · 0.45

Tested by

no test coverage detected