package external import "testing" func TestLocalPath(t *testing.T) { for _, tc := range []struct { name, url, want string wantErr bool }{ { name: "gitea raw, published document", url: "https://git.hypertheory-labs.dev/loom/bedrock/raw/branch/main/.loom/published/starting.md", want: "git.hypertheory-labs.dev/loom/bedrock/starting.md", }, { name: "github raw host", url: "https://raw.githubusercontent.com/octocat/Hello-World/main/README.md", want: "raw.githubusercontent.com/octocat/Hello-World/README.md", }, { name: "not enough path to name an owner and repository", url: "https://example.com/thing.md", wantErr: true, }, { name: "not absolute", url: "/loom/bedrock/starting.md", wantErr: true, }, } { t.Run(tc.name, func(t *testing.T) { got, err := localPath(tc.url) if tc.wantErr { if err == nil { t.Fatalf("localPath(%q) = %q, want an error", tc.url, got) } return } if err != nil { t.Fatalf("localPath(%q): %v", tc.url, err) } if got != tc.want { t.Errorf("localPath(%q) = %q, want %q", tc.url, got, tc.want) } }) } } func TestIsFacet(t *testing.T) { // A facet is something we wrote beside an adopted document. check must not // report our own writing as an unlocked external. facets := []string{ "host/loom/cart/cart.usages.md", "host/loom/externals/externals.gaps.md", "host/o/r/plan.notes.md", } documents := []string{ "host/loom/cart/cart.md", "host/loom/bedrock/recording-decisions.md", // a hyphen is not a facet "host/o/r/starting.md", } for _, p := range facets { if !isFacet(p) { t.Errorf("isFacet(%q) = false, want true", p) } } for _, p := range documents { if isFacet(p) { t.Errorf("isFacet(%q) = true, want false", p) } } }