courgette/internal/runner/deferred_task_test.go

49 lines
1.3 KiB
Go

package runner
import (
logger "courgette/internal/logging"
"testing"
)
func init() {
logger.ConfigureLogger()
}
func TestQueueAddsTaskToTaskQueue(t *testing.T) {
manager := NewDeferredTaskManager()
manager.Queue("scope", func() {})
if len(manager.deferredTasks["scope"]) != 1 {
t.Errorf("Expected a queue of 1 to exist, got %d items instead.", len(manager.deferredTasks["scope"]))
}
}
func TestGetTasksByScopeReturnsTasksAssociatedWithScope(t *testing.T) {
manager := NewDeferredTaskManager()
manager.Queue("scope", func() {})
if len(manager.GetTasksByScope("scope")) != 1 {
t.Errorf("Expected a queue of 1 to exist, got %d items instead.", len(manager.GetTasksByScope("scope")))
}
}
func TestGetTasksByScopeReturnsEmptySliceIfUnknownScope(t *testing.T) {
manager := NewDeferredTaskManager()
if len(manager.GetTasksByScope("scope")) != 0 {
t.Errorf("Expected a queue of 0 to exist, got %d items instead.", len(manager.GetTasksByScope("scope")))
}
}
func TestGetAllTasksReturnsAllTasksRegardlessOfScope(t *testing.T) {
manager := NewDeferredTaskManager()
manager.Queue("scope-1", func() {})
manager.Queue("scope-2", func() {})
if len(manager.GetAllTasks()) != 2 {
t.Errorf("Expected a queue of 2 to exist, got %d items instead.", len(manager.GetAllTasks()))
}
}