Files
zeekay 1943f1c093 Hanzo Commerce
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans,
usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0.

Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
2026-09-23 21:52:16 -07:00

47 lines
1.4 KiB
Go

package ossfunding
import "testing"
func TestFromPURL(t *testing.T) {
cases := []struct {
purl string
wantKind Kind
wantHandle string
}{
{"pkg:golang/github.com/gin-gonic/[email protected]", KindGitHubSponsors, "gin-gonic"},
{"pkg:golang/github.com/google/[email protected]", KindGitHubSponsors, "google"},
{"pkg:golang/golang.org/x/[email protected]", KindGitHubSponsors, "golang"},
{"pkg:golang/gitlab.com/acme/widget@v2", KindGitHubSponsors, "acme"},
{"pkg:npm/[email protected]", KindUnresolved, ""},
{"pkg:pypi/[email protected]", KindUnresolved, ""},
{"", KindUnresolved, ""},
}
for _, tc := range cases {
t.Run(tc.purl, func(t *testing.T) {
got := FromPURL(tc.purl)
if got.Kind != tc.wantKind {
t.Fatalf("kind = %q, want %q", got.Kind, tc.wantKind)
}
if got.Handle != tc.wantHandle {
t.Fatalf("handle = %q, want %q", got.Handle, tc.wantHandle)
}
})
}
}
func TestTargetString(t *testing.T) {
if got := (Target{Kind: KindGitHubSponsors, Handle: "gin-gonic"}).String(); got != "github_sponsors:gin-gonic" {
t.Fatalf("String() = %q", got)
}
if got := Unresolved().String(); got != "unresolved" {
t.Fatalf("Unresolved String() = %q", got)
}
}
func TestPURLResolver(t *testing.T) {
r := PURLResolver{}
if got := r.Resolve("pkg:golang/github.com/gin-gonic/gin@v1"); got.Handle != "gin-gonic" {
t.Fatalf("resolver handle = %q", got.Handle)
}
}