package api
import (
"errors"
"testing"
"time"
"craftdesign.group/quarry/internal/ops"
)
type runRecorder struct {
memMirrors
runs []string
}
func (r *runRecorder) MirrorPulls(string, int) ([]MirrorPull, error) { return nil, nil }
func (r *runRecorder) MirrorDiverged(string, string, time.Time) error { return nil }
func (r *runRecorder) RecordMirrorRun(repo string, _ time.Duration, _ bool, err error) (int, error) {
r.runs = append(r.runs, repo)
return 0, nil
}
// A mirror whose store never arrived (an import that failed) must still
// count as a run when the scheduler asks: recorded, it is due at its
// interval; unrecorded, it was asked for and journalled every tick.
func TestPullMirrorRecordsARunForAMissingStore(t *testing.T) {
rec := &runRecorder{memMirrors: memMirrors{}}
d := Deps{Repos: NewRepos(map[string]*Repo{}), Mirrors: rec}
_, err := d.PullMirror(Mirror{Repo: "ghost", URL: "https://x/y"})
if !errors.Is(err, ops.ErrNotFound) {
t.Fatalf("err = %v, want not found", err)
}
if len(rec.runs) != 1 || rec.runs[0] != "ghost" {
t.Fatalf("runs recorded = %v, want one for ghost", rec.runs)
}
}