internal/storage: SQLite-БД для задач и трассировок (таски + статус-машина, трассы с группировкой по task_id)
All checks were successful
build-test / build (push) Successful in 30s
All checks were successful
build-test / build (push) Successful in 30s
This commit is contained in:
49
internal/storage/models_test.go
Normal file
49
internal/storage/models_test.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestIsValidTransition(t *testing.T) {
|
||||
tests := []struct {
|
||||
from, to Status
|
||||
want bool
|
||||
}{
|
||||
{StatusDraft, StatusCollecting, true},
|
||||
{StatusDraft, StatusCancelled, true},
|
||||
{StatusDraft, StatusRunning, false},
|
||||
{StatusDraft, StatusClosed, false},
|
||||
{StatusRunning, StatusSuccess, true},
|
||||
{StatusRunning, StatusFailed, true},
|
||||
{StatusRunning, StatusTimeout, true},
|
||||
{StatusSuccess, StatusClosed, true},
|
||||
{StatusSuccess, StatusDraft, false},
|
||||
{StatusFailed, StatusReady, true}, // retry
|
||||
{StatusFailed, StatusClosed, true},
|
||||
{StatusFailed, StatusRunning, false},
|
||||
{StatusTimeout, StatusReady, true}, // retry
|
||||
{StatusClosed, StatusDraft, false},
|
||||
{StatusClosed, StatusRunning, false},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
got := IsValidTransition(tc.from, tc.to)
|
||||
if got != tc.want {
|
||||
t.Errorf("IsValidTransition(%q → %q) = %v, want %v", tc.from, tc.to, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsTerminal(t *testing.T) {
|
||||
if !IsTerminal(StatusSuccess) {
|
||||
t.Error("StatusSuccess should be terminal")
|
||||
}
|
||||
if !IsTerminal(StatusCancelled) {
|
||||
t.Error("StatusCancelled should be terminal")
|
||||
}
|
||||
if IsTerminal(StatusDraft) {
|
||||
t.Error("StatusDraft should NOT be terminal")
|
||||
}
|
||||
if IsTerminal(StatusRunning) {
|
||||
t.Error("StatusRunning should NOT be terminal")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user