package zitcli
import (
"context"
"testing"
"craftdesign.group/quarry/internal/obs"
)
// A spawn names its request, else its background activity, else the
// function that asked; the last reads as a name and a file to open.
func TestSpawnCauseFallsBackToTheCallingFunction(t *testing.T) {
req := obs.WithAddress(context.Background(), "GET", "/r/fossil/timeline")
if got := spawnCause(req); got != "GET /r/fossil/timeline" {
t.Errorf("FAIL: a request's spawn reads %q", got)
}
if got := spawnCause(obs.WithReason(context.Background(), obs.ReasonTree)); got != "tree index" {
t.Errorf("FAIL: a named background spawn reads %q", got)
}
cases := map[[2]string]string{
{"main.indexTree", "/src/cmd/quarry/registrar.go"}: "indexTree (quarry/registrar.go)",
{"main.(*registrar).warm.func1", "/src/cmd/quarry/registrar.go"}: "registrar.warm (quarry/registrar.go)",
{"craftdesign.group/quarry/internal/api.Deps.fileHistory", "/src/internal/api/register.go"}: "Deps.fileHistory (api/register.go)",
}
for in, want := range cases {
if got := frameName(in[0], in[1]); got != want {
t.Errorf("FAIL: frameName(%q) = %q, want %q", in[0], got, want)
}
}
// Called from inside this package, the walk passes every zitcli frame
// and names whoever is outside it: here, the test runner.
if got := caller(); got == "" || got[:len("tRunner")] != "tRunner" {
t.Errorf("FAIL: caller() from a zitcli frame reads %q", got)
}
}