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

Function TestTaskStorage_BasicOperations

pkg/task/queue/task_storage_test.go:13–105  ·  view source on GitHub ↗

TestTaskStorage_BasicOperations tests basic add, get, and remove operations

(t *testing.T)

Source from the content-addressed store, hash-verified

11
12// TestTaskStorage_BasicOperations tests basic add, get, and remove operations
13func TestTaskStorage_BasicOperations(t *testing.T) {
14 ts := newTaskStorage()
15
16 // Test empty storage
17 if ts.Length() != 0 {
18 t.Errorf("Expected length 0, got %d", ts.Length())
19 }
20
21 if ts.GetFirst() != nil {
22 t.Error("Expected GetFirst() to return nil for empty storage")
23 }
24
25 if ts.GetLast() != nil {
26 t.Error("Expected GetLast() to return nil for empty storage")
27 }
28
29 // Create some tasks
30 task1 := task.NewTask("test1")
31 task2 := task.NewTask("test2")
32 task3 := task.NewTask("test3")
33
34 // Test AddLast
35 ts.AddLast(task1, task2)
36 if ts.Length() != 2 {
37 t.Errorf("Expected length 2, got %d", ts.Length())
38 }
39
40 if ts.GetFirst() != task1 {
41 t.Error("Expected first task to be task1")
42 }
43
44 if ts.GetLast() != task2 {
45 t.Error("Expected last task to be task2")
46 }
47
48 // Test Get by ID
49 if ts.Get(task1.GetId()) != task1 {
50 t.Error("Expected to get task1 by ID")
51 }
52
53 if ts.Get("nonexistent") != nil {
54 t.Error("Expected Get(nonexistent) to return nil")
55 }
56
57 // Test AddFirst
58 ts.AddFirst(task3)
59 if ts.Length() != 3 {
60 t.Errorf("Expected length 3, got %d", ts.Length())
61 }
62
63 if ts.GetFirst() != task3 {
64 t.Error("Expected first task to be task3 after AddFirst")
65 }
66
67 // Test RemoveFirst
68 removed := ts.RemoveFirst()
69 if removed != task3 {
70 t.Error("Expected RemoveFirst to return task3")

Callers

nothing calls this directly

Calls 13

GetIdMethod · 0.95
NewTaskFunction · 0.92
newTaskStorageFunction · 0.85
GetFirstMethod · 0.65
AddLastMethod · 0.65
GetMethod · 0.65
AddFirstMethod · 0.65
RemoveFirstMethod · 0.65
RemoveMethod · 0.65
LengthMethod · 0.45
ErrorMethod · 0.45
GetLastMethod · 0.45

Tested by

no test coverage detected