package api
import (
"errors"
"strings"
"testing"
"craftdesign.group/quarry/internal/ops"
)
// A repository named the way the web spells it — owner/repo — is not
// found by the API, which keys by bare name. The refusal now says so
// and names the bare name to try (4bc7035f, G-1). Still not found, and
// still not a confirmation: the hint is about the API's spelling, not
// about whether the bare name exists.
func TestAnOwnerPrefixedNameIsToldTheBareName(t *testing.T) {
d := Deps{Repos: testRepos(nil)}
_, err := d.repo("jva/dantest-sandbox")
if !errors.Is(err, ops.ErrNotFound) {
t.Fatalf("FAIL: err = %v, want ErrNotFound", err)
}
if !strings.Contains(err.Error(), `"dantest-sandbox"`) || !strings.Contains(err.Error(), "bare name") {
t.Fatalf("FAIL: the refusal does not name the bare name to try: %v", err)
}
_, err = d.repo("dantest-sandbox")
if !errors.Is(err, ops.ErrNotFound) || strings.Contains(err.Error(), "bare name") {
t.Fatalf("FAIL: a bare name that is missing must get the plain refusal: %v", err)
}
t.Logf("ok: %v", err)
}
// `tip` is accepted by file.get as it is by doc.get; the two used to
// disagree at the validator, before either reached the resolver
// (4bc7035f, G-2).
func TestTipPassesFileGetValidation(t *testing.T) {
if err := ops.Validate(fileGetIn{Repo: "test", Hash: "tip", Path: "README.md"}); err != nil {
t.Fatalf("FAIL: file.get refuses tip at the validator: %v", err)
}
if err := ops.Validate(docGetIn{Repo: "test", Hash: "tip", Path: "README.md"}); err != nil {
t.Fatalf("FAIL: doc.get refuses tip: %v", err)
}
if err := ops.Validate(fileGetIn{Repo: "test", Hash: "ab", Path: "README.md"}); err == nil {
t.Fatal("FAIL: a two-character hash is neither a name nor a prefix and must still be refused")
}
t.Log("ok: tip validates on both routes; two characters do not")
}