Skip to content
quarry Artifact [043991fc80]
Login

Artifact [043991fc80]

Artifact 043991fc804b7af12ea9a51bf4dfd1a382c85bc475e0864ab41f0699ee7126c4:


package web

import (
	"net/http"
	"net/http/httptest"
	"testing"

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

// A document opens rendered, as fossil's /file does: txt=1 and any
// request for lines keep the source, and a file that is not a document
// is not redirected.
func TestADocumentFileOpensRendered(t *testing.T) {
	h := HandlerWith(ops.NewRegistry(), nil, nil, nil)
	get := func(path string) (int, string) {
		w := httptest.NewRecorder()
		h.ServeHTTP(w, httptest.NewRequest("GET", path, nil))
		return w.Code, w.Header().Get("Location")
	}
	if code, loc := get("/r/kb/file/abc123/skill/ctx/SKILL.md"); code != http.StatusFound || loc != "/r/kb/doc/abc123/skill/ctx/SKILL.md" {
		t.Errorf("FAIL: a Markdown file answered %d -> %q", code, loc)
	}
	for _, p := range []string{
		"/r/kb/file/abc123/skill/ctx/SKILL.md?txt=1",
		"/r/kb/file/abc123/skill/ctx/SKILL.md?ln=10",
		"/r/kb/file/abc123/main.go",
		"/r/kb/file/abc123/notes.txt",
	} {
		if code, loc := get(p); code == http.StatusFound {
			t.Errorf("FAIL: %s was redirected to %q", p, loc)
		}
	}
}