Files
imap-copier/internal/orchestrator/orchestrator_test.go
T

45 lines
1.1 KiB
Go

package orchestrator
import (
"testing"
"github.com/vasyansk/imap-copier/internal/store"
)
func TestGateOK(t *testing.T) {
ok := []store.Account{
{TestSrcStatus: "ok", TestDstStatus: "ok"},
{TestSrcStatus: "ok", TestDstStatus: "ok"},
}
if !gateOK(ok) {
t.Fatal("all ok must pass gate")
}
bad := []store.Account{{TestSrcStatus: "ok", TestDstStatus: "fail"}}
if gateOK(bad) {
t.Fatal("any non-ok must fail gate")
}
if gateOK(nil) {
t.Fatal("empty accounts must fail gate")
}
}
func TestSelectAccounts(t *testing.T) {
accs := []store.Account{{ID: 1}, {ID: 2}, {ID: 3}}
if got := selectAccounts(accs, nil); len(got) != 3 {
t.Fatalf("nil ids must return all, got %d", len(got))
}
if got := selectAccounts(accs, []int64{}); len(got) != 3 {
t.Fatalf("empty ids must return all, got %d", len(got))
}
got := selectAccounts(accs, []int64{3, 1})
if len(got) != 2 || got[0].ID != 1 || got[1].ID != 3 {
t.Fatalf("must keep matching ids in input order, got %+v", got)
}
if got := selectAccounts(accs, []int64{99}); len(got) != 0 {
t.Fatalf("unknown ids must yield empty, got %d", len(got))
}
}