Skip to content
quarry Artifact [a64125e5c1]
Login

Artifact [a64125e5c1]

Artifact a64125e5c1f38a42c7c677f5f0abb9761166d2c14fccdc43121cb4ed36b677f6:


package api

import (
	"context"
	"testing"

	"craftdesign.group/quarry/internal/ops"
)

func versionWith(t *testing.T, pending func() []string) versionOut {
	t.Helper()
	r := ops.NewRegistry()
	if err := RegisterAll(r, Deps{Version: "v", Repos: testRepos(nil), Pending: pending}); err != nil {
		t.Fatal(err)
	}
	got, err := r.Invoke(context.Background(), "meta.version", versionIn{})
	if err != nil {
		t.Fatal(err)
	}
	return got.(versionOut)
}

// While repositories are still registering, the version answer says
// so and names them; once none remain, it says ready. This is the one
// exposed fact that tells STARTING from BROKEN — the journal always
// could, and nothing a probe could reach did (b81ae623).
func TestVersionSaysWhetherTheForgeIsReady(t *testing.T) {
	out := versionWith(t, func() []string { return []string{"pkgsrc", "tcl"} })
	if out.Ready || len(out.Starting) != 2 {
		t.Fatalf("FAIL: mid-registration reads ready=%v starting=%v", out.Ready, out.Starting)
	}
	t.Logf("ok: starting %v, ready=false", out.Starting)
	out = versionWith(t, func() []string { return nil })
	if !out.Ready || len(out.Starting) != 0 {
		t.Fatalf("FAIL: with nothing pending reads ready=%v starting=%v", out.Ready, out.Starting)
	}
	out = versionWith(t, nil)
	if !out.Ready {
		t.Fatal("FAIL: a forge with no pending list at all must read ready, or a probe waits forever")
	}
	t.Log("ok: ready once nothing is pending, and when there is no pending list")
}