49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
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")
|
|
}
|
|
} |