Skip to content
quarry Artifact [04666fb43b]
Login

Artifact [04666fb43b]

Artifact 04666fb43bb59d5cb8e37915eae74dfed1b4883569026339202511184ae23d19:


package zitcli

import (
	"context"
	"errors"
	"testing"
)

// zit 0.9.0 exits 8 when content is withheld by policy (purged,
// shunned, outside a cone). Each read verb reads that as the file being
// unavailable, not as a broken store, and cat does not remember the
// absence: purge undo can bring the content back.
func TestAbsentByPolicyIsUnavailableNotAFault(t *testing.T) {
	fakeZit(t, `echo "content withheld by policy" >&2; exit 8`)
	c := New(t.TempDir())
	ctx := context.Background()
	full := "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
	if _, err := c.Cat(ctx, "f.txt", full); !errors.Is(err, ErrNoEntry) {
		t.Fatalf("FAIL: cat exit 8 = %v, want ErrNoEntry", err)
	}
	if _, ok := c.blobs.get("miss\x00" + full + "\x00f.txt"); ok {
		t.Fatal("FAIL: a policy absence was cached as permanent")
	}
	if _, err := c.NumStat(ctx, full); !errors.Is(err, ErrNoEntry) {
		t.Fatalf("FAIL: diff --numstat exit 8 = %v, want ErrNoEntry", err)
	}
	if _, _, ok, err := c.Annotate(ctx, full, "f.txt", 0); err != nil || ok {
		t.Fatalf("FAIL: annotate exit 8 = ok %v err %v, want not-annotatable, no error", ok, err)
	}
	t.Log("ok: exit 8 reads as unavailable on cat, diff and annotate")
}