Skip to content
quarry Artifact [449e78fef8]
Login

Artifact [449e78fef8]

Artifact 449e78fef809fa1c1bd5c57a08499b26c22e9257004aded48095a46da474fe22:


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)
	}
}