mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
Bare `skillshare install` already restores everything .metadata.json records but the disk lacks, yet the dashboard could only re-clone missing tracked repos through a separate rehydrate path. Expose the CLI's install-from-config flow instead (GET /api/install/missing, POST /api/install/from-config) so both surfaces share one detection and one installer, and drop the old missingTrackedRepos plumbing from update responses. The install summary now counts tracked repos and their skills apart from standalone skills, since "Installed 1 skill" hid a whole repo. New tracked repos are named `_<owner>-<repo>` so two `skills` repos no longer collide; existing installs keep their names. `check` passes the stale status through so the dashboard can offer to prune skills deleted upstream.
1841 lines
53 KiB
Go
1841 lines
53 KiB
Go
package install
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
// Windows drive-letter and backslash-relative paths must be treated as local
|
|
// sources instead of falling through to git URL parsing (issue #269).
|
|
func TestParseSource_WindowsLocalPath(t *testing.T) {
|
|
for _, input := range []string{
|
|
`D:\folder`,
|
|
`C:\Users\me\skills\my-skill`,
|
|
"C:/Users/me/skills/my-skill",
|
|
`.\my-skill`,
|
|
`..\my-skill`,
|
|
} {
|
|
if !isLocalPath(input) {
|
|
t.Errorf("isLocalPath(%q) = false, want true", input)
|
|
}
|
|
source, err := ParseSource(input)
|
|
if err != nil {
|
|
t.Errorf("ParseSource(%q) error: %v", input, err)
|
|
continue
|
|
}
|
|
if source.Type != SourceTypeLocalPath {
|
|
t.Errorf("ParseSource(%q) type = %v, want SourceTypeLocalPath", input, source.Type)
|
|
}
|
|
}
|
|
|
|
// Plain owner/repo shorthand must keep expanding to GitHub.
|
|
if isLocalPath("owner/repo") {
|
|
t.Error("isLocalPath(owner/repo) = true, want false")
|
|
}
|
|
}
|
|
|
|
func TestParseSource_LocalPath(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
wantType SourceType
|
|
wantName string
|
|
}{
|
|
{
|
|
name: "absolute path",
|
|
input: "/path/to/my-skill",
|
|
wantType: SourceTypeLocalPath,
|
|
wantName: "my-skill",
|
|
},
|
|
{
|
|
name: "tilde path",
|
|
input: "~/skills/my-skill",
|
|
wantType: SourceTypeLocalPath,
|
|
wantName: "my-skill",
|
|
},
|
|
{
|
|
name: "relative path with dot",
|
|
input: "./local-skill",
|
|
wantType: SourceTypeLocalPath,
|
|
wantName: "local-skill",
|
|
},
|
|
{
|
|
name: "parent directory path",
|
|
input: "../other-skill",
|
|
wantType: SourceTypeLocalPath,
|
|
wantName: "other-skill",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
source, err := ParseSource(tt.input)
|
|
if err != nil {
|
|
t.Fatalf("ParseSource() error = %v", err)
|
|
}
|
|
if source.Type != tt.wantType {
|
|
t.Errorf("Type = %v, want %v", source.Type, tt.wantType)
|
|
}
|
|
if source.Name != tt.wantName {
|
|
t.Errorf("Name = %v, want %v", source.Name, tt.wantName)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseSource_GitHubShorthand(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
wantCloneURL string
|
|
wantSubdir string
|
|
wantName string
|
|
wantExplicit bool
|
|
wantBranch string
|
|
}{
|
|
{
|
|
name: "basic github shorthand",
|
|
input: "github.com/user/repo",
|
|
wantCloneURL: "https://github.com/user/repo.git",
|
|
wantSubdir: "",
|
|
wantName: "repo",
|
|
wantExplicit: false,
|
|
},
|
|
{
|
|
name: "github shorthand with .git",
|
|
input: "github.com/user/repo.git",
|
|
wantCloneURL: "https://github.com/user/repo.git",
|
|
wantSubdir: "",
|
|
wantName: "repo",
|
|
wantExplicit: false,
|
|
},
|
|
{
|
|
name: "github with subdirectory",
|
|
input: "github.com/user/repo/path/to/skill",
|
|
wantCloneURL: "https://github.com/user/repo.git",
|
|
wantSubdir: "path/to/skill",
|
|
wantName: "skill",
|
|
wantExplicit: false,
|
|
},
|
|
{
|
|
name: "github with https prefix",
|
|
input: "https://github.com/user/repo",
|
|
wantCloneURL: "https://github.com/user/repo.git",
|
|
wantSubdir: "",
|
|
wantName: "repo",
|
|
wantExplicit: false,
|
|
},
|
|
{
|
|
name: "github https with .git",
|
|
input: "https://github.com/user/repo.git",
|
|
wantCloneURL: "https://github.com/user/repo.git",
|
|
wantSubdir: "",
|
|
wantName: "repo",
|
|
wantExplicit: false,
|
|
},
|
|
{
|
|
name: "github web URL with tree/main",
|
|
input: "https://github.com/user/repo/tree/main/path/to/skill",
|
|
wantCloneURL: "https://github.com/user/repo.git",
|
|
wantSubdir: "path/to/skill",
|
|
wantName: "skill",
|
|
wantExplicit: false,
|
|
wantBranch: "main",
|
|
},
|
|
{
|
|
name: "github web URL with tree/master",
|
|
input: "github.com/user/repo/tree/master/skills/my-skill",
|
|
wantCloneURL: "https://github.com/user/repo.git",
|
|
wantSubdir: "skills/my-skill",
|
|
wantName: "my-skill",
|
|
wantExplicit: false,
|
|
wantBranch: "master",
|
|
},
|
|
{
|
|
name: "github web URL with blob (file view)",
|
|
input: "https://github.com/user/repo/blob/main/path/to/skill",
|
|
wantCloneURL: "https://github.com/user/repo.git",
|
|
wantSubdir: "path/to/skill",
|
|
wantName: "skill",
|
|
wantExplicit: false,
|
|
wantBranch: "main",
|
|
},
|
|
{
|
|
name: "github web URL tree/branch only (no subdir)",
|
|
input: "https://github.com/user/repo/tree/main",
|
|
wantCloneURL: "https://github.com/user/repo.git",
|
|
wantSubdir: "",
|
|
wantName: "repo",
|
|
wantExplicit: false,
|
|
wantBranch: "main",
|
|
},
|
|
{
|
|
name: "github dot subdir normalized to root",
|
|
input: "github.com/user/repo/.",
|
|
wantCloneURL: "https://github.com/user/repo.git",
|
|
wantSubdir: "",
|
|
wantName: "repo",
|
|
wantExplicit: false,
|
|
},
|
|
// issue #124: blob URLs pointing directly at SKILL.md should resolve
|
|
// to the containing skill directory instead of a literal "SKILL.md" name.
|
|
{
|
|
name: "github blob URL at root SKILL.md",
|
|
input: "https://github.com/iOfficeAI/OfficeCLI/blob/main/SKILL.md",
|
|
wantCloneURL: "https://github.com/iOfficeAI/OfficeCLI.git",
|
|
wantSubdir: "",
|
|
wantName: "OfficeCLI",
|
|
wantExplicit: true,
|
|
wantBranch: "main",
|
|
},
|
|
{
|
|
name: "github blob URL at nested SKILL.md",
|
|
input: "https://github.com/user/repo/blob/main/skills/foo/SKILL.md",
|
|
wantCloneURL: "https://github.com/user/repo.git",
|
|
wantSubdir: "skills/foo",
|
|
wantName: "foo",
|
|
wantExplicit: true,
|
|
wantBranch: "main",
|
|
},
|
|
{
|
|
name: "github blob URL at SKILL.md lowercase (case-insensitive)",
|
|
input: "https://github.com/user/repo/blob/main/skill.md",
|
|
wantCloneURL: "https://github.com/user/repo.git",
|
|
wantSubdir: "",
|
|
wantName: "repo",
|
|
wantExplicit: true,
|
|
wantBranch: "main",
|
|
},
|
|
{
|
|
name: "github web URL pinned to a tag",
|
|
input: "https://github.com/user/repo/tree/v1.2.0/skills/foo",
|
|
wantCloneURL: "https://github.com/user/repo.git",
|
|
wantSubdir: "skills/foo",
|
|
wantName: "foo",
|
|
wantBranch: "v1.2.0",
|
|
},
|
|
{
|
|
name: "github web URL pinned to a commit SHA",
|
|
input: "github.com/user/repo/tree/8f14e45fceea167a5a36dedd4bea2543ce848564/skills/foo",
|
|
wantCloneURL: "https://github.com/user/repo.git",
|
|
wantSubdir: "skills/foo",
|
|
wantName: "foo",
|
|
wantBranch: "8f14e45fceea167a5a36dedd4bea2543ce848564",
|
|
},
|
|
{
|
|
name: "github web URL at HEAD uses the default branch",
|
|
input: "https://github.com/user/repo/tree/HEAD",
|
|
wantCloneURL: "https://github.com/user/repo.git",
|
|
wantSubdir: "",
|
|
wantName: "repo",
|
|
wantBranch: "",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
source, err := ParseSource(tt.input)
|
|
if err != nil {
|
|
t.Fatalf("ParseSource() error = %v", err)
|
|
}
|
|
if source.Type != SourceTypeGitHub {
|
|
t.Errorf("Type = %v, want %v", source.Type, SourceTypeGitHub)
|
|
}
|
|
if source.CloneURL != tt.wantCloneURL {
|
|
t.Errorf("CloneURL = %v, want %v", source.CloneURL, tt.wantCloneURL)
|
|
}
|
|
if source.Subdir != tt.wantSubdir {
|
|
t.Errorf("Subdir = %v, want %v", source.Subdir, tt.wantSubdir)
|
|
}
|
|
if source.Name != tt.wantName {
|
|
t.Errorf("Name = %v, want %v", source.Name, tt.wantName)
|
|
}
|
|
if source.Branch != tt.wantBranch {
|
|
t.Errorf("Branch = %q, want %q", source.Branch, tt.wantBranch)
|
|
}
|
|
if source.TargetsExplicitSkill() != tt.wantExplicit {
|
|
t.Errorf("TargetsExplicitSkill() = %v, want %v", source.TargetsExplicitSkill(), tt.wantExplicit)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseSource_GitSSH(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
wantCloneURL string
|
|
wantSubdir string
|
|
wantName string
|
|
}{
|
|
{
|
|
name: "github ssh",
|
|
input: "git@github.com:user/repo.git",
|
|
wantCloneURL: "git@github.com:user/repo.git",
|
|
wantName: "repo",
|
|
},
|
|
{
|
|
name: "gitlab ssh",
|
|
input: "git@gitlab.com:user/repo.git",
|
|
wantCloneURL: "git@gitlab.com:user/repo.git",
|
|
wantName: "repo",
|
|
},
|
|
{
|
|
name: "custom ssh username",
|
|
input: "acme@acme.ghe.com:MyOrg/my-skills.git",
|
|
wantCloneURL: "acme@acme.ghe.com:MyOrg/my-skills.git",
|
|
wantName: "my-skills",
|
|
},
|
|
{
|
|
name: "custom ssh username without .git",
|
|
input: "acme@acme.ghe.com:MyOrg/my-skills",
|
|
wantCloneURL: "acme@acme.ghe.com:MyOrg/my-skills.git",
|
|
wantName: "my-skills",
|
|
},
|
|
{
|
|
name: "gitlab ssh nested subgroup",
|
|
input: "git@gitlab.example.com:org/subgroup/my-skills.git",
|
|
wantCloneURL: "git@gitlab.example.com:org/subgroup/my-skills.git",
|
|
wantName: "my-skills",
|
|
},
|
|
{
|
|
name: "ssh without .git",
|
|
input: "git@github.com:user/my-skill",
|
|
wantCloneURL: "git@github.com:user/my-skill.git",
|
|
wantName: "my-skill",
|
|
},
|
|
{
|
|
name: "ssh with subpath using //",
|
|
input: "git@github.com:owner/repo.git//path/to/skill",
|
|
wantCloneURL: "git@github.com:owner/repo.git",
|
|
wantSubdir: "path/to/skill",
|
|
wantName: "skill",
|
|
},
|
|
{
|
|
name: "ssh with subpath no .git",
|
|
input: "git@github.com:owner/repo//skills/react",
|
|
wantCloneURL: "git@github.com:owner/repo.git",
|
|
wantSubdir: "skills/react",
|
|
wantName: "react",
|
|
},
|
|
{
|
|
name: "ssh gitlab with subpath",
|
|
input: "git@gitlab.com:team/monorepo.git//frontend/ui-skill",
|
|
wantCloneURL: "git@gitlab.com:team/monorepo.git",
|
|
wantSubdir: "frontend/ui-skill",
|
|
wantName: "ui-skill",
|
|
},
|
|
{
|
|
name: "ssh with single-level subpath",
|
|
input: "git@github.com:owner/skills.git//pdf",
|
|
wantCloneURL: "git@github.com:owner/skills.git",
|
|
wantSubdir: "pdf",
|
|
wantName: "pdf",
|
|
},
|
|
{
|
|
name: "custom ssh username with subpath",
|
|
input: "acme@acme.ghe.com:MyOrg/my-skills.git//agents/reviewer",
|
|
wantCloneURL: "acme@acme.ghe.com:MyOrg/my-skills.git",
|
|
wantSubdir: "agents/reviewer",
|
|
wantName: "reviewer",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
source, err := ParseSource(tt.input)
|
|
if err != nil {
|
|
t.Fatalf("ParseSource() error = %v", err)
|
|
}
|
|
if source.Type != SourceTypeGitSSH {
|
|
t.Errorf("Type = %v, want %v", source.Type, SourceTypeGitSSH)
|
|
}
|
|
if source.CloneURL != tt.wantCloneURL {
|
|
t.Errorf("CloneURL = %v, want %v", source.CloneURL, tt.wantCloneURL)
|
|
}
|
|
if source.Subdir != tt.wantSubdir {
|
|
t.Errorf("Subdir = %v, want %v", source.Subdir, tt.wantSubdir)
|
|
}
|
|
if source.Name != tt.wantName {
|
|
t.Errorf("Name = %v, want %v", source.Name, tt.wantName)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestSSHIdentity(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
wantUser string
|
|
wantHost string
|
|
wantOK bool
|
|
}{
|
|
{
|
|
name: "scp style",
|
|
input: "acme@acme.ghe.com:Org/skills.git//hubs/team.json",
|
|
wantUser: "acme",
|
|
wantHost: "acme.ghe.com",
|
|
wantOK: true,
|
|
},
|
|
{
|
|
name: "ssh scheme",
|
|
input: "ssh://git@ghe.corp.com/Org/skills.git//skillshare-hub.json",
|
|
wantUser: "git",
|
|
wantHost: "ghe.corp.com",
|
|
wantOK: true,
|
|
},
|
|
{
|
|
name: "https",
|
|
input: "https://ghe.corp.com/Org/skills",
|
|
wantOK: false,
|
|
},
|
|
{
|
|
name: "ssh scheme without user",
|
|
input: "ssh://ghe.corp.com/Org/skills.git",
|
|
wantOK: false,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
user, host, ok := SSHIdentity(tt.input)
|
|
if ok != tt.wantOK {
|
|
t.Fatalf("ok = %v, want %v", ok, tt.wantOK)
|
|
}
|
|
if ok {
|
|
if user != tt.wantUser {
|
|
t.Errorf("user = %q, want %q", user, tt.wantUser)
|
|
}
|
|
if host != tt.wantHost {
|
|
t.Errorf("host = %q, want %q", host, tt.wantHost)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseSource_GitHTTPS(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
wantCloneURL string
|
|
wantSubdir string
|
|
wantName string
|
|
wantBranch string
|
|
wantExplicit bool
|
|
}{
|
|
{
|
|
name: "gitlab https",
|
|
input: "https://gitlab.com/user/repo",
|
|
wantCloneURL: "https://gitlab.com/user/repo.git",
|
|
wantName: "repo",
|
|
wantExplicit: false,
|
|
},
|
|
{
|
|
name: "bitbucket https",
|
|
input: "https://bitbucket.org/user/repo.git",
|
|
wantCloneURL: "https://bitbucket.org/user/repo.git",
|
|
wantName: "repo",
|
|
wantExplicit: false,
|
|
},
|
|
{
|
|
name: "gitlab https dot subdir normalized to root",
|
|
input: "https://gitlab.com/user/repo/.",
|
|
wantCloneURL: "https://gitlab.com/user/repo.git",
|
|
wantName: "repo",
|
|
wantExplicit: false,
|
|
},
|
|
{
|
|
name: "bitbucket web URL with src/main",
|
|
input: "https://bitbucket.org/team/skills/src/main/learn-and-update",
|
|
wantCloneURL: "https://bitbucket.org/team/skills.git",
|
|
wantSubdir: "learn-and-update",
|
|
wantName: "learn-and-update",
|
|
wantBranch: "main",
|
|
wantExplicit: false,
|
|
},
|
|
{
|
|
name: "bitbucket web URL with src/main trailing slash",
|
|
input: "https://bitbucket.org/team/skills/src/main/learn-and-update/",
|
|
wantCloneURL: "https://bitbucket.org/team/skills.git",
|
|
wantSubdir: "learn-and-update",
|
|
wantName: "learn-and-update",
|
|
wantBranch: "main",
|
|
wantExplicit: false,
|
|
},
|
|
{
|
|
name: "bitbucket web URL src/branch only (no subdir)",
|
|
input: "https://bitbucket.org/team/skills/src/main",
|
|
wantCloneURL: "https://bitbucket.org/team/skills.git",
|
|
wantName: "skills",
|
|
wantBranch: "main",
|
|
wantExplicit: false,
|
|
},
|
|
{
|
|
name: "bitbucket web URL nested subdir",
|
|
input: "https://bitbucket.org/team/skills/src/develop/frontend/react",
|
|
wantCloneURL: "https://bitbucket.org/team/skills.git",
|
|
wantSubdir: "frontend/react",
|
|
wantName: "react",
|
|
wantBranch: "develop",
|
|
wantExplicit: false,
|
|
},
|
|
{
|
|
name: "gitlab web URL with -/tree/main",
|
|
input: "https://gitlab.com/user/repo/-/tree/main/path/to/skill",
|
|
wantCloneURL: "https://gitlab.com/user/repo.git",
|
|
wantSubdir: "path/to/skill",
|
|
wantName: "skill",
|
|
wantBranch: "main",
|
|
wantExplicit: false,
|
|
},
|
|
{
|
|
name: "gitlab web URL with -/blob/main",
|
|
input: "https://gitlab.com/user/repo/-/blob/main/path/to/skill",
|
|
wantCloneURL: "https://gitlab.com/user/repo.git",
|
|
wantSubdir: "path/to/skill",
|
|
wantName: "skill",
|
|
wantBranch: "main",
|
|
wantExplicit: false,
|
|
},
|
|
{
|
|
name: "gitlab web URL -/tree/branch only",
|
|
input: "https://gitlab.com/user/repo/-/tree/main",
|
|
wantCloneURL: "https://gitlab.com/user/repo.git",
|
|
wantName: "repo",
|
|
wantBranch: "main",
|
|
wantExplicit: false,
|
|
},
|
|
// issue #124: blob URLs pointing directly at SKILL.md should resolve
|
|
// to the containing skill directory instead of a literal "SKILL.md" name.
|
|
{
|
|
name: "gitlab blob URL at root SKILL.md",
|
|
input: "https://gitlab.com/user/repo/-/blob/main/SKILL.md",
|
|
wantCloneURL: "https://gitlab.com/user/repo.git",
|
|
wantSubdir: "",
|
|
wantName: "repo",
|
|
wantBranch: "main",
|
|
wantExplicit: true,
|
|
},
|
|
{
|
|
name: "gitlab blob URL at nested SKILL.md",
|
|
input: "https://gitlab.com/user/repo/-/blob/main/skills/foo/SKILL.md",
|
|
wantCloneURL: "https://gitlab.com/user/repo.git",
|
|
wantSubdir: "skills/foo",
|
|
wantName: "foo",
|
|
wantBranch: "main",
|
|
wantExplicit: true,
|
|
},
|
|
{
|
|
name: "gitlab web URL pinned to a tag",
|
|
input: "https://gitlab.com/user/repo/-/tree/v1.2.0/skills/foo",
|
|
wantCloneURL: "https://gitlab.com/user/repo.git",
|
|
wantSubdir: "skills/foo",
|
|
wantName: "foo",
|
|
wantBranch: "v1.2.0",
|
|
},
|
|
{
|
|
name: "bitbucket web URL pinned to a commit SHA",
|
|
input: "https://bitbucket.org/team/repo/src/0123abc/skills/foo",
|
|
wantCloneURL: "https://bitbucket.org/team/repo.git",
|
|
wantSubdir: "skills/foo",
|
|
wantName: "foo",
|
|
wantBranch: "0123abc",
|
|
},
|
|
{
|
|
name: "bitbucket src URL at nested SKILL.md",
|
|
input: "https://bitbucket.org/team/repo/src/main/skills/foo/SKILL.md",
|
|
wantCloneURL: "https://bitbucket.org/team/repo.git",
|
|
wantSubdir: "skills/foo",
|
|
wantName: "foo",
|
|
wantBranch: "main",
|
|
wantExplicit: true,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
source, err := ParseSource(tt.input)
|
|
if err != nil {
|
|
t.Fatalf("ParseSource() error = %v", err)
|
|
}
|
|
if source.Type != SourceTypeGitHTTPS {
|
|
t.Errorf("Type = %v, want %v", source.Type, SourceTypeGitHTTPS)
|
|
}
|
|
if source.CloneURL != tt.wantCloneURL {
|
|
t.Errorf("CloneURL = %v, want %v", source.CloneURL, tt.wantCloneURL)
|
|
}
|
|
if source.Subdir != tt.wantSubdir {
|
|
t.Errorf("Subdir = %v, want %v", source.Subdir, tt.wantSubdir)
|
|
}
|
|
if source.Name != tt.wantName {
|
|
t.Errorf("Name = %v, want %v", source.Name, tt.wantName)
|
|
}
|
|
if source.Branch != tt.wantBranch {
|
|
t.Errorf("Branch = %v, want %v", source.Branch, tt.wantBranch)
|
|
}
|
|
if source.TargetsExplicitSkill() != tt.wantExplicit {
|
|
t.Errorf("TargetsExplicitSkill() = %v, want %v", source.TargetsExplicitSkill(), tt.wantExplicit)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseSource_FileURL(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
wantCloneURL string
|
|
wantSubdir string
|
|
wantName string
|
|
}{
|
|
{
|
|
name: "file url",
|
|
input: "file:///path/to/repo",
|
|
wantCloneURL: "file:///path/to/repo",
|
|
wantName: "repo",
|
|
},
|
|
{
|
|
// On Windows filepath.Clean would otherwise emit `file://\C:\...`.
|
|
name: "file url with a drive path keeps URL separators",
|
|
input: "file:///C:/path/to/repo",
|
|
wantCloneURL: "file:///C:/path/to/repo",
|
|
wantName: "repo",
|
|
},
|
|
{
|
|
name: "file url with dot suffix normalized to root",
|
|
input: "file:///path/to/repo/.",
|
|
wantCloneURL: "file:///path/to/repo",
|
|
wantName: "repo",
|
|
},
|
|
{
|
|
name: "file url with // single-level subdir",
|
|
input: "file:///path/to/repo//skills",
|
|
wantCloneURL: "file:///path/to/repo",
|
|
wantSubdir: "skills",
|
|
wantName: "skills",
|
|
},
|
|
{
|
|
name: "file url with // nested subdir",
|
|
input: "file:///path/to/repo//skills/alpha",
|
|
wantCloneURL: "file:///path/to/repo",
|
|
wantSubdir: "skills/alpha",
|
|
wantName: "alpha",
|
|
},
|
|
{
|
|
name: "file url with // subdir trailing slash",
|
|
input: "file:///path/to/repo//skills/alpha/",
|
|
wantCloneURL: "file:///path/to/repo",
|
|
wantSubdir: "skills/alpha",
|
|
wantName: "alpha",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
source, err := ParseSource(tt.input)
|
|
if err != nil {
|
|
t.Fatalf("ParseSource() error = %v", err)
|
|
}
|
|
if source.Type != SourceTypeGitHTTPS {
|
|
t.Errorf("Type = %v, want %v", source.Type, SourceTypeGitHTTPS)
|
|
}
|
|
if source.CloneURL != tt.wantCloneURL {
|
|
t.Errorf("CloneURL = %v, want %v", source.CloneURL, tt.wantCloneURL)
|
|
}
|
|
if source.Subdir != tt.wantSubdir {
|
|
t.Errorf("Subdir = %v, want %v", source.Subdir, tt.wantSubdir)
|
|
}
|
|
if source.Name != tt.wantName {
|
|
t.Errorf("Name = %v, want %v", source.Name, tt.wantName)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseSource_Errors(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
}{
|
|
{
|
|
name: "empty string",
|
|
input: "",
|
|
},
|
|
{
|
|
name: "whitespace only",
|
|
input: " ",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
_, err := ParseSource(tt.input)
|
|
if err == nil {
|
|
t.Error("ParseSource() should return error")
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestSource_HasSubdir(t *testing.T) {
|
|
source := &Source{Subdir: "path/to/skill"}
|
|
if !source.HasSubdir() {
|
|
t.Error("HasSubdir() should return true")
|
|
}
|
|
|
|
source = &Source{Subdir: ""}
|
|
if source.HasSubdir() {
|
|
t.Error("HasSubdir() should return false")
|
|
}
|
|
}
|
|
|
|
func TestSource_IsGit(t *testing.T) {
|
|
tests := []struct {
|
|
sourceType SourceType
|
|
wantIsGit bool
|
|
}{
|
|
{SourceTypeGitHub, true},
|
|
{SourceTypeGitHTTPS, true},
|
|
{SourceTypeGitSSH, true},
|
|
{SourceTypeLocalPath, false},
|
|
{SourceTypeUnknown, false},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
source := &Source{Type: tt.sourceType}
|
|
if source.IsGit() != tt.wantIsGit {
|
|
t.Errorf("IsGit() for %v = %v, want %v", tt.sourceType, source.IsGit(), tt.wantIsGit)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSource_MetaType(t *testing.T) {
|
|
tests := []struct {
|
|
source *Source
|
|
wantType string
|
|
}{
|
|
{
|
|
source: &Source{Type: SourceTypeGitHub},
|
|
wantType: "github",
|
|
},
|
|
{
|
|
source: &Source{Type: SourceTypeGitHub, Subdir: "path"},
|
|
wantType: "github-subdir",
|
|
},
|
|
{
|
|
source: &Source{Type: SourceTypeLocalPath},
|
|
wantType: "local",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
if tt.source.MetaType() != tt.wantType {
|
|
t.Errorf("MetaType() = %v, want %v", tt.source.MetaType(), tt.wantType)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSource_TrackName(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
raw string
|
|
want string
|
|
}{
|
|
{
|
|
name: "github shorthand",
|
|
raw: "openai/skills",
|
|
want: "openai-skills",
|
|
},
|
|
{
|
|
name: "github HTTPS URL",
|
|
raw: "https://github.com/anthropics/skills",
|
|
want: "anthropics-skills",
|
|
},
|
|
{
|
|
name: "github SSH URL",
|
|
raw: "git@github.com:openai/skills.git",
|
|
want: "openai-skills",
|
|
},
|
|
{
|
|
name: "gitlab HTTPS URL",
|
|
raw: "https://gitlab.com/team/my-repo.git",
|
|
want: "team-my-repo",
|
|
},
|
|
{
|
|
name: "github shorthand with subdir",
|
|
raw: "openai/skills/skills/pdf",
|
|
want: "openai-skills",
|
|
},
|
|
{
|
|
name: "gitlab subgroup HTTPS",
|
|
raw: "https://gitlab.com/group/subgroup/project",
|
|
want: "group-subgroup-project",
|
|
},
|
|
{
|
|
name: "gitlab deep subgroup shorthand",
|
|
raw: "onprem.gitlab.internal/org/sub1/sub2/project",
|
|
want: "org-sub1-sub2-project",
|
|
},
|
|
{
|
|
name: "file URL keeps basename",
|
|
raw: "file:///tmp/remotes/team-repo",
|
|
want: "team-repo",
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
source, err := ParseSource(tt.raw)
|
|
if err != nil {
|
|
t.Fatalf("ParseSource(%q) error: %v", tt.raw, err)
|
|
}
|
|
got := source.TrackName()
|
|
if got != tt.want {
|
|
t.Errorf("TrackName() = %q, want %q", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestSplitGitWebRef(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
host string
|
|
subdir string
|
|
want string
|
|
wantRef string
|
|
explicit bool
|
|
}{
|
|
{"empty", "bitbucket.org", "", "", "", false},
|
|
{"bitbucket src/main/path", "bitbucket.org", "src/main/learn-and-update", "learn-and-update", "main", false},
|
|
{"bitbucket src/main/nested", "bitbucket.org", "src/develop/a/b/c", "a/b/c", "develop", false},
|
|
{"bitbucket src/branch only", "bitbucket.org", "src/main", "", "main", false},
|
|
{"bitbucket trailing slash", "bitbucket.org", "src/main/skill/", "skill", "main", false},
|
|
{"gitlab -/tree/main/path", "gitlab.com", "-/tree/main/path/to/skill", "path/to/skill", "main", false},
|
|
{"gitlab -/blob/main/path", "gitlab.com", "-/blob/main/path/to/skill", "path/to/skill", "main", false},
|
|
{"gitlab blob SKILL target", "gitlab.com", "-/blob/main/skills/foo/SKILL.md", "skills/foo", "main", true},
|
|
{"gitlab -/tree/branch only", "gitlab.com", "-/tree/main", "", "main", false},
|
|
{"gitlab tag", "gitlab.com", "-/tree/v1.2.0/skills/foo", "skills/foo", "v1.2.0", false},
|
|
{"non-platform passthrough", "example.com", "some/path", "some/path", "", false},
|
|
{"bitbucket host variant", "bitbucket.mycompany.com", "src/main/skill", "skill", "main", false},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
var s Source
|
|
got := tt.subdir
|
|
if w, ok := splitGitWebRef(tt.host, tt.subdir); ok {
|
|
got = s.applyWebRef(w)
|
|
}
|
|
if got != tt.want {
|
|
t.Errorf("subdir = %q, want %q", got, tt.want)
|
|
}
|
|
if s.Branch != tt.wantRef {
|
|
t.Errorf("Branch = %q, want %q", s.Branch, tt.wantRef)
|
|
}
|
|
if s.ExplicitSkill != tt.explicit {
|
|
t.Errorf("explicit = %v, want %v", s.ExplicitSkill, tt.explicit)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseSource_DomainShorthand(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
wantType SourceType
|
|
wantCloneURL string
|
|
wantSubdir string
|
|
wantName string
|
|
}{
|
|
{
|
|
name: "gitlab shorthand",
|
|
input: "gitlab.com/user/repo",
|
|
wantType: SourceTypeGitHTTPS,
|
|
wantCloneURL: "https://gitlab.com/user/repo.git",
|
|
wantName: "repo",
|
|
},
|
|
{
|
|
name: "bitbucket shorthand",
|
|
input: "bitbucket.org/user/repo",
|
|
wantType: SourceTypeGitHTTPS,
|
|
wantCloneURL: "https://bitbucket.org/user/repo.git",
|
|
wantName: "repo",
|
|
},
|
|
{
|
|
name: "gitlab multi-segment path (treated as repo)",
|
|
input: "gitlab.com/user/repo/path/to/skill",
|
|
wantType: SourceTypeGitHTTPS,
|
|
wantCloneURL: "https://gitlab.com/user/repo/path/to/skill.git",
|
|
wantSubdir: "",
|
|
wantName: "skill",
|
|
},
|
|
{
|
|
name: "gitlab with .git subdir boundary",
|
|
input: "gitlab.com/user/repo.git/path/to/skill",
|
|
wantType: SourceTypeGitHTTPS,
|
|
wantCloneURL: "https://gitlab.com/user/repo.git",
|
|
wantSubdir: "path/to/skill",
|
|
wantName: "skill",
|
|
},
|
|
{
|
|
name: "custom domain",
|
|
input: "git.company.com/team/skills",
|
|
wantType: SourceTypeGitHTTPS,
|
|
wantCloneURL: "https://git.company.com/team/skills.git",
|
|
wantName: "skills",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
source, err := ParseSource(tt.input)
|
|
if err != nil {
|
|
t.Fatalf("ParseSource(%q) error = %v", tt.input, err)
|
|
}
|
|
if source.Type != tt.wantType {
|
|
t.Errorf("Type = %v, want %v", source.Type, tt.wantType)
|
|
}
|
|
if source.CloneURL != tt.wantCloneURL {
|
|
t.Errorf("CloneURL = %q, want %q", source.CloneURL, tt.wantCloneURL)
|
|
}
|
|
if source.Subdir != tt.wantSubdir {
|
|
t.Errorf("Subdir = %q, want %q", source.Subdir, tt.wantSubdir)
|
|
}
|
|
if source.Name != tt.wantName {
|
|
t.Errorf("Name = %q, want %q", source.Name, tt.wantName)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseSource_GitHubEnterprise(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
wantType SourceType
|
|
wantCloneURL string
|
|
wantSubdir string
|
|
wantName string
|
|
}{
|
|
// GitHub Enterprise Server: github.COMPANY.com
|
|
{
|
|
name: "GHE Server shorthand",
|
|
input: "github.mycompany.com/org/repo",
|
|
wantType: SourceTypeGitHTTPS,
|
|
wantCloneURL: "https://github.mycompany.com/org/repo.git",
|
|
wantName: "repo",
|
|
},
|
|
{
|
|
name: "GHE Server full URL",
|
|
input: "https://github.mycompany.com/org/repo",
|
|
wantType: SourceTypeGitHTTPS,
|
|
wantCloneURL: "https://github.mycompany.com/org/repo.git",
|
|
wantName: "repo",
|
|
},
|
|
{
|
|
name: "GHE Server with .git suffix",
|
|
input: "https://github.mycompany.com/org/repo.git",
|
|
wantType: SourceTypeGitHTTPS,
|
|
wantCloneURL: "https://github.mycompany.com/org/repo.git",
|
|
wantName: "repo",
|
|
},
|
|
{
|
|
name: "GHE Server with subdir",
|
|
input: "https://github.mycompany.com/org/repo/skills/my-skill",
|
|
wantType: SourceTypeGitHTTPS,
|
|
wantCloneURL: "https://github.mycompany.com/org/repo.git",
|
|
wantSubdir: "skills/my-skill",
|
|
wantName: "my-skill",
|
|
},
|
|
{
|
|
name: "GHE Server with .git subdir boundary",
|
|
input: "https://github.mycompany.com/org/repo.git/skills/my-skill",
|
|
wantType: SourceTypeGitHTTPS,
|
|
wantCloneURL: "https://github.mycompany.com/org/repo.git",
|
|
wantSubdir: "skills/my-skill",
|
|
wantName: "my-skill",
|
|
},
|
|
{
|
|
name: "GHE Server different company",
|
|
input: "github.acme.com/team/project",
|
|
wantType: SourceTypeGitHTTPS,
|
|
wantCloneURL: "https://github.acme.com/team/project.git",
|
|
wantName: "project",
|
|
},
|
|
// GitHub Enterprise Cloud: COMPANY.github.com
|
|
{
|
|
name: "GHE Cloud shorthand",
|
|
input: "mycompany.github.com/org/repo",
|
|
wantType: SourceTypeGitHTTPS,
|
|
wantCloneURL: "https://mycompany.github.com/org/repo.git",
|
|
wantName: "repo",
|
|
},
|
|
{
|
|
name: "GHE Cloud full URL",
|
|
input: "https://mycompany.github.com/org/repo",
|
|
wantType: SourceTypeGitHTTPS,
|
|
wantCloneURL: "https://mycompany.github.com/org/repo.git",
|
|
wantName: "repo",
|
|
},
|
|
{
|
|
name: "GHE Cloud with subdir",
|
|
input: "https://enterprise.github.com/team/skills/frontend/react",
|
|
wantType: SourceTypeGitHTTPS,
|
|
wantCloneURL: "https://enterprise.github.com/team/skills.git",
|
|
wantSubdir: "frontend/react",
|
|
wantName: "react",
|
|
},
|
|
{
|
|
name: "GHE Cloud with .git subdir boundary",
|
|
input: "https://enterprise.github.com/team/skills.git/frontend/react",
|
|
wantType: SourceTypeGitHTTPS,
|
|
wantCloneURL: "https://enterprise.github.com/team/skills.git",
|
|
wantSubdir: "frontend/react",
|
|
wantName: "react",
|
|
},
|
|
// SSH format
|
|
{
|
|
name: "GHE Server SSH",
|
|
input: "git@github.mycompany.com:org/repo.git",
|
|
wantType: SourceTypeGitSSH,
|
|
wantCloneURL: "git@github.mycompany.com:org/repo.git",
|
|
wantName: "repo",
|
|
},
|
|
{
|
|
name: "GHE Cloud SSH",
|
|
input: "git@mycompany.github.com:team/skills.git",
|
|
wantType: SourceTypeGitSSH,
|
|
wantCloneURL: "git@mycompany.github.com:team/skills.git",
|
|
wantName: "skills",
|
|
},
|
|
{
|
|
name: "GHE Data Residency SSH",
|
|
input: "acme@acme.ghe.com:MyOrg/my-skills.git",
|
|
wantType: SourceTypeGitSSH,
|
|
wantCloneURL: "acme@acme.ghe.com:MyOrg/my-skills.git",
|
|
wantName: "my-skills",
|
|
},
|
|
{
|
|
name: "GHE SSH with subdir",
|
|
input: "git@github.mycompany.com:org/repo.git//path/to/skill",
|
|
wantType: SourceTypeGitSSH,
|
|
wantCloneURL: "git@github.mycompany.com:org/repo.git",
|
|
wantSubdir: "path/to/skill",
|
|
wantName: "skill",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
source, err := ParseSource(tt.input)
|
|
if err != nil {
|
|
t.Fatalf("ParseSource(%q) error = %v", tt.input, err)
|
|
}
|
|
if source.Type != tt.wantType {
|
|
t.Errorf("Type = %v, want %v", source.Type, tt.wantType)
|
|
}
|
|
if source.CloneURL != tt.wantCloneURL {
|
|
t.Errorf("CloneURL = %q, want %q", source.CloneURL, tt.wantCloneURL)
|
|
}
|
|
if source.Subdir != tt.wantSubdir {
|
|
t.Errorf("Subdir = %q, want %q", source.Subdir, tt.wantSubdir)
|
|
}
|
|
if source.Name != tt.wantName {
|
|
t.Errorf("Name = %q, want %q", source.Name, tt.wantName)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseSource_GitHubEnterprise_TrackName(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
raw string
|
|
want string
|
|
}{
|
|
{
|
|
name: "GHE Server HTTPS",
|
|
raw: "https://github.mycompany.com/team/skills",
|
|
want: "team-skills",
|
|
},
|
|
{
|
|
name: "GHE Cloud HTTPS",
|
|
raw: "https://enterprise.github.com/org/repo",
|
|
want: "org-repo",
|
|
},
|
|
{
|
|
name: "GHE Server SSH",
|
|
raw: "git@github.mycompany.com:org/skills.git",
|
|
want: "org-skills",
|
|
},
|
|
{
|
|
name: "GHE Data Residency SSH",
|
|
raw: "acme@acme.ghe.com:MyOrg/my-skills.git",
|
|
want: "MyOrg-my-skills",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
source, err := ParseSource(tt.raw)
|
|
if err != nil {
|
|
t.Fatalf("ParseSource(%q) error: %v", tt.raw, err)
|
|
}
|
|
got := source.TrackName()
|
|
if got != tt.want {
|
|
t.Errorf("TrackName() = %q, want %q", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestSource_GitHubOwnerRepo(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
raw string
|
|
wantOwner string
|
|
wantRepo string
|
|
}{
|
|
{
|
|
name: "github shorthand",
|
|
raw: "openai/skills",
|
|
wantOwner: "openai",
|
|
wantRepo: "skills",
|
|
},
|
|
{
|
|
name: "ghe https",
|
|
raw: "https://github.acme.com/team/repo/skills/pkg",
|
|
wantOwner: "team",
|
|
wantRepo: "repo",
|
|
},
|
|
{
|
|
name: "ghe ssh",
|
|
raw: "git@github.acme.com:team/repo.git//skills/pkg",
|
|
wantOwner: "team",
|
|
wantRepo: "repo",
|
|
},
|
|
{
|
|
name: "ghe data residency https",
|
|
raw: "https://acme.ghe.com/MyOrg/my-skills/agents/reviewer",
|
|
wantOwner: "MyOrg",
|
|
wantRepo: "my-skills",
|
|
},
|
|
{
|
|
name: "ghe data residency ssh",
|
|
raw: "acme@acme.ghe.com:MyOrg/my-skills.git//agents/reviewer",
|
|
wantOwner: "MyOrg",
|
|
wantRepo: "my-skills",
|
|
},
|
|
{
|
|
name: "non-github host",
|
|
raw: "https://gitlab.com/team/repo",
|
|
wantOwner: "",
|
|
wantRepo: "",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
source, err := ParseSource(tt.raw)
|
|
if err != nil {
|
|
t.Fatalf("ParseSource(%q) error = %v", tt.raw, err)
|
|
}
|
|
if got := source.GitHubOwner(); got != tt.wantOwner {
|
|
t.Fatalf("GitHubOwner() = %q, want %q", got, tt.wantOwner)
|
|
}
|
|
if got := source.GitHubRepo(); got != tt.wantRepo {
|
|
t.Fatalf("GitHubRepo() = %q, want %q", got, tt.wantRepo)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseSource_GitLabSubgroups(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
wantType SourceType
|
|
wantCloneURL string
|
|
wantSubdir string
|
|
wantName string
|
|
}{
|
|
{
|
|
name: "gitlab two-level subgroup",
|
|
input: "https://gitlab.com/group/subgroup/project",
|
|
wantType: SourceTypeGitHTTPS,
|
|
wantCloneURL: "https://gitlab.com/group/subgroup/project.git",
|
|
wantName: "project",
|
|
},
|
|
{
|
|
name: "onprem gitlab deep subgroup (issue #72)",
|
|
input: "onprem.gitlab.internal/org-group/subgroup-1/subgroup-2/project",
|
|
wantType: SourceTypeGitHTTPS,
|
|
wantCloneURL: "https://onprem.gitlab.internal/org-group/subgroup-1/subgroup-2/project.git",
|
|
wantName: "project",
|
|
},
|
|
{
|
|
name: "gitlab subgroup with .git subdir boundary",
|
|
input: "https://gitlab.com/group/subgroup/project.git/skills/my-skill",
|
|
wantType: SourceTypeGitHTTPS,
|
|
wantCloneURL: "https://gitlab.com/group/subgroup/project.git",
|
|
wantSubdir: "skills/my-skill",
|
|
wantName: "my-skill",
|
|
},
|
|
{
|
|
name: "gitlab subgroup shorthand",
|
|
input: "gitlab.com/group/subgroup/project",
|
|
wantType: SourceTypeGitHTTPS,
|
|
wantCloneURL: "https://gitlab.com/group/subgroup/project.git",
|
|
wantName: "project",
|
|
},
|
|
{
|
|
name: "gitlab subgroup with .git suffix",
|
|
input: "https://gitlab.com/group/subgroup/project.git",
|
|
wantType: SourceTypeGitHTTPS,
|
|
wantCloneURL: "https://gitlab.com/group/subgroup/project.git",
|
|
wantName: "project",
|
|
},
|
|
{
|
|
name: "gitlab subgroup web URL with -/tree",
|
|
input: "https://gitlab.com/group/subgroup/project/-/tree/main/skills/react",
|
|
wantType: SourceTypeGitHTTPS,
|
|
wantCloneURL: "https://gitlab.com/group/subgroup/project.git",
|
|
wantSubdir: "skills/react",
|
|
wantName: "react",
|
|
},
|
|
{
|
|
name: "jihulab nested subgroup",
|
|
input: "https://jihulab.com/group/subgroup/project",
|
|
wantType: SourceTypeGitHTTPS,
|
|
wantCloneURL: "https://jihulab.com/group/subgroup/project.git",
|
|
wantName: "project",
|
|
},
|
|
{
|
|
name: "jihulab shorthand",
|
|
input: "jihulab.com/team/frontend/ui",
|
|
wantType: SourceTypeGitHTTPS,
|
|
wantCloneURL: "https://jihulab.com/team/frontend/ui.git",
|
|
wantName: "ui",
|
|
},
|
|
{
|
|
name: "jihulab web URL with -/tree",
|
|
input: "https://jihulab.com/org/sub/project/-/tree/main/skills/x",
|
|
wantType: SourceTypeGitHTTPS,
|
|
wantCloneURL: "https://jihulab.com/org/sub/project.git",
|
|
wantSubdir: "skills/x",
|
|
wantName: "x",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
source, err := ParseSource(tt.input)
|
|
if err != nil {
|
|
t.Fatalf("ParseSource(%q) error = %v", tt.input, err)
|
|
}
|
|
if source.Type != tt.wantType {
|
|
t.Errorf("Type = %v, want %v", source.Type, tt.wantType)
|
|
}
|
|
if source.CloneURL != tt.wantCloneURL {
|
|
t.Errorf("CloneURL = %q, want %q", source.CloneURL, tt.wantCloneURL)
|
|
}
|
|
if source.Subdir != tt.wantSubdir {
|
|
t.Errorf("Subdir = %q, want %q", source.Subdir, tt.wantSubdir)
|
|
}
|
|
if source.Name != tt.wantName {
|
|
t.Errorf("Name = %q, want %q", source.Name, tt.wantName)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseSource_GeminiCLIMonorepo(t *testing.T) {
|
|
// Real-world test case from the plan
|
|
input := "github.com/google-gemini/gemini-cli/packages/core/src/skills/builtin/skill-creator"
|
|
|
|
source, err := ParseSource(input)
|
|
if err != nil {
|
|
t.Fatalf("ParseSource() error = %v", err)
|
|
}
|
|
|
|
if source.Type != SourceTypeGitHub {
|
|
t.Errorf("Type = %v, want %v", source.Type, SourceTypeGitHub)
|
|
}
|
|
if source.CloneURL != "https://github.com/google-gemini/gemini-cli.git" {
|
|
t.Errorf("CloneURL = %v, want https://github.com/google-gemini/gemini-cli.git", source.CloneURL)
|
|
}
|
|
if source.Subdir != "packages/core/src/skills/builtin/skill-creator" {
|
|
t.Errorf("Subdir = %v, want packages/core/src/skills/builtin/skill-creator", source.Subdir)
|
|
}
|
|
if source.Name != "skill-creator" {
|
|
t.Errorf("Name = %v, want skill-creator", source.Name)
|
|
}
|
|
}
|
|
|
|
func TestExpandGitHubShorthand(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
want string
|
|
}{
|
|
{
|
|
name: "owner/repo shorthand",
|
|
input: "anthropics/skills",
|
|
want: "github.com/anthropics/skills",
|
|
},
|
|
{
|
|
name: "owner/repo/path shorthand",
|
|
input: "anthropics/skills/skills/pdf",
|
|
want: "github.com/anthropics/skills/skills/pdf",
|
|
},
|
|
{
|
|
name: "already has github.com prefix",
|
|
input: "github.com/user/repo",
|
|
want: "github.com/user/repo",
|
|
},
|
|
{
|
|
name: "https URL unchanged",
|
|
input: "https://github.com/user/repo",
|
|
want: "https://github.com/user/repo",
|
|
},
|
|
{
|
|
name: "http URL unchanged",
|
|
input: "http://example.com/user/repo",
|
|
want: "http://example.com/user/repo",
|
|
},
|
|
{
|
|
name: "git SSH unchanged",
|
|
input: "git@github.com:user/repo.git",
|
|
want: "git@github.com:user/repo.git",
|
|
},
|
|
{
|
|
name: "file URL unchanged",
|
|
input: "file:///path/to/repo",
|
|
want: "file:///path/to/repo",
|
|
},
|
|
{
|
|
name: "absolute path unchanged",
|
|
input: "/path/to/skill",
|
|
want: "/path/to/skill",
|
|
},
|
|
{
|
|
name: "tilde path unchanged",
|
|
input: "~/skills/my-skill",
|
|
want: "~/skills/my-skill",
|
|
},
|
|
{
|
|
name: "relative path unchanged",
|
|
input: "./local-skill",
|
|
want: "./local-skill",
|
|
},
|
|
{
|
|
name: "parent path unchanged",
|
|
input: "../other-skill",
|
|
want: "../other-skill",
|
|
},
|
|
{
|
|
name: "single word unchanged (no slash)",
|
|
input: "somename",
|
|
want: "somename",
|
|
},
|
|
{
|
|
name: "gitlab domain gets https prefix",
|
|
input: "gitlab.com/user/repo",
|
|
want: "https://gitlab.com/user/repo",
|
|
},
|
|
{
|
|
name: "bitbucket domain gets https prefix",
|
|
input: "bitbucket.org/user/repo",
|
|
want: "https://bitbucket.org/user/repo",
|
|
},
|
|
{
|
|
name: "custom domain gets https prefix",
|
|
input: "git.company.com/team/skills",
|
|
want: "https://git.company.com/team/skills",
|
|
},
|
|
{
|
|
name: "github shorthand still works",
|
|
input: "anthropics/skills",
|
|
want: "github.com/anthropics/skills",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := expandGitHubShorthand(tt.input)
|
|
if got != tt.want {
|
|
t.Errorf("expandGitHubShorthand(%q) = %q, want %q", tt.input, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseSource_GitHubShorthandExpansion(t *testing.T) {
|
|
// Test that shorthand is properly expanded and parsed
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
wantCloneURL string
|
|
wantSubdir string
|
|
wantName string
|
|
}{
|
|
{
|
|
name: "owner/repo shorthand",
|
|
input: "anthropics/skills",
|
|
wantCloneURL: "https://github.com/anthropics/skills.git",
|
|
wantSubdir: "",
|
|
wantName: "skills",
|
|
},
|
|
{
|
|
name: "owner/repo/subdir shorthand",
|
|
input: "anthropics/skills/skills/pdf",
|
|
wantCloneURL: "https://github.com/anthropics/skills.git",
|
|
wantSubdir: "skills/pdf",
|
|
wantName: "pdf",
|
|
},
|
|
{
|
|
name: "ComposioHQ example",
|
|
input: "ComposioHQ/awesome-claude-skills",
|
|
wantCloneURL: "https://github.com/ComposioHQ/awesome-claude-skills.git",
|
|
wantSubdir: "",
|
|
wantName: "awesome-claude-skills",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
source, err := ParseSource(tt.input)
|
|
if err != nil {
|
|
t.Fatalf("ParseSource(%q) error = %v", tt.input, err)
|
|
}
|
|
if source.Type != SourceTypeGitHub {
|
|
t.Errorf("Type = %v, want %v", source.Type, SourceTypeGitHub)
|
|
}
|
|
if source.CloneURL != tt.wantCloneURL {
|
|
t.Errorf("CloneURL = %q, want %q", source.CloneURL, tt.wantCloneURL)
|
|
}
|
|
if source.Subdir != tt.wantSubdir {
|
|
t.Errorf("Subdir = %q, want %q", source.Subdir, tt.wantSubdir)
|
|
}
|
|
if source.Name != tt.wantName {
|
|
t.Errorf("Name = %q, want %q", source.Name, tt.wantName)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseSource_AzureDevOps(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
wantType SourceType
|
|
wantCloneURL string
|
|
wantSubdir string
|
|
wantName string
|
|
}{
|
|
{
|
|
name: "modern HTTPS",
|
|
input: "https://dev.azure.com/myorg/myproj/_git/myrepo",
|
|
wantType: SourceTypeGitHTTPS,
|
|
wantCloneURL: "https://dev.azure.com/myorg/myproj/_git/myrepo",
|
|
wantName: "myrepo",
|
|
},
|
|
{
|
|
name: "modern HTTPS with .git suffix",
|
|
input: "https://dev.azure.com/myorg/myproj/_git/myrepo.git",
|
|
wantType: SourceTypeGitHTTPS,
|
|
wantCloneURL: "https://dev.azure.com/myorg/myproj/_git/myrepo",
|
|
wantName: "myrepo",
|
|
},
|
|
{
|
|
name: "modern HTTPS with subdir",
|
|
input: "https://dev.azure.com/org/proj/_git/repo/skills/react",
|
|
wantType: SourceTypeGitHTTPS,
|
|
wantCloneURL: "https://dev.azure.com/org/proj/_git/repo",
|
|
wantSubdir: "skills/react",
|
|
wantName: "react",
|
|
},
|
|
{
|
|
name: "legacy visualstudio.com format",
|
|
input: "https://myorg.visualstudio.com/myproj/_git/myrepo",
|
|
wantType: SourceTypeGitHTTPS,
|
|
wantCloneURL: "https://dev.azure.com/myorg/myproj/_git/myrepo",
|
|
wantName: "myrepo",
|
|
},
|
|
{
|
|
name: "SSH v3 format",
|
|
input: "git@ssh.dev.azure.com:v3/myorg/myproj/myrepo",
|
|
wantType: SourceTypeGitSSH,
|
|
wantCloneURL: "git@ssh.dev.azure.com:v3/myorg/myproj/myrepo",
|
|
wantName: "myrepo",
|
|
},
|
|
{
|
|
name: "SSH v3 with .git suffix",
|
|
input: "git@ssh.dev.azure.com:v3/myorg/myproj/myrepo.git",
|
|
wantType: SourceTypeGitSSH,
|
|
wantCloneURL: "git@ssh.dev.azure.com:v3/myorg/myproj/myrepo",
|
|
wantName: "myrepo",
|
|
},
|
|
{
|
|
name: "SSH v3 with subdir",
|
|
input: "git@ssh.dev.azure.com:v3/org/proj/repo//skills/react",
|
|
wantType: SourceTypeGitSSH,
|
|
wantCloneURL: "git@ssh.dev.azure.com:v3/org/proj/repo",
|
|
wantSubdir: "skills/react",
|
|
wantName: "react",
|
|
},
|
|
{
|
|
name: "ado: shorthand",
|
|
input: "ado:myorg/myproj/myrepo",
|
|
wantType: SourceTypeGitHTTPS,
|
|
wantCloneURL: "https://dev.azure.com/myorg/myproj/_git/myrepo",
|
|
wantName: "myrepo",
|
|
},
|
|
{
|
|
name: "ado: shorthand with subdir",
|
|
input: "ado:org/proj/repo/skills/react",
|
|
wantType: SourceTypeGitHTTPS,
|
|
wantCloneURL: "https://dev.azure.com/org/proj/_git/repo",
|
|
wantSubdir: "skills/react",
|
|
wantName: "react",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
source, err := ParseSource(tt.input)
|
|
if err != nil {
|
|
t.Fatalf("ParseSource(%q) error = %v", tt.input, err)
|
|
}
|
|
if source.Type != tt.wantType {
|
|
t.Errorf("Type = %v, want %v", source.Type, tt.wantType)
|
|
}
|
|
if source.CloneURL != tt.wantCloneURL {
|
|
t.Errorf("CloneURL = %q, want %q", source.CloneURL, tt.wantCloneURL)
|
|
}
|
|
if source.Subdir != tt.wantSubdir {
|
|
t.Errorf("Subdir = %q, want %q", source.Subdir, tt.wantSubdir)
|
|
}
|
|
if source.Name != tt.wantName {
|
|
t.Errorf("Name = %q, want %q", source.Name, tt.wantName)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseSource_AzureDevOps_TrackName(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
raw string
|
|
want string
|
|
}{
|
|
{
|
|
name: "modern HTTPS",
|
|
raw: "https://dev.azure.com/org/proj/_git/repo",
|
|
want: "org-proj-repo",
|
|
},
|
|
{
|
|
name: "legacy visualstudio.com",
|
|
raw: "https://myorg.visualstudio.com/myproj/_git/myrepo",
|
|
want: "myorg-myproj-myrepo",
|
|
},
|
|
{
|
|
name: "SSH v3",
|
|
raw: "git@ssh.dev.azure.com:v3/org/proj/repo",
|
|
want: "org-proj-repo",
|
|
},
|
|
{
|
|
name: "ado: shorthand",
|
|
raw: "ado:org/proj/repo",
|
|
want: "org-proj-repo",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
source, err := ParseSource(tt.raw)
|
|
if err != nil {
|
|
t.Fatalf("ParseSource(%q) error: %v", tt.raw, err)
|
|
}
|
|
got := source.TrackName()
|
|
if got != tt.want {
|
|
t.Errorf("TrackName() = %q, want %q", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseSourceWithOptions_GitLabHosts(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
hosts []string
|
|
wantURL string
|
|
wantName string
|
|
}{
|
|
{
|
|
name: "custom host treated as GitLab",
|
|
input: "git.company.com/group/sub/project",
|
|
hosts: []string{"git.company.com"},
|
|
wantURL: "https://git.company.com/group/sub/project.git",
|
|
wantName: "project",
|
|
},
|
|
{
|
|
name: "same URL without opts uses 2-segment split",
|
|
input: "git.company.com/group/sub/project",
|
|
hosts: nil,
|
|
wantURL: "https://git.company.com/group/sub.git",
|
|
wantName: "project", // "project" is treated as subdir of owner/repo
|
|
},
|
|
{
|
|
name: "case-insensitive host match",
|
|
input: "Git.Company.Com/group/sub/project",
|
|
hosts: []string{"git.company.com"},
|
|
wantURL: "https://Git.Company.Com/group/sub/project.git", // host case preserved in URL
|
|
wantName: "project",
|
|
},
|
|
{
|
|
name: ".git suffix still wins over host heuristic",
|
|
input: "git.company.com/owner/repo.git/subdir",
|
|
hosts: []string{"git.company.com"},
|
|
wantURL: "https://git.company.com/owner/repo.git",
|
|
wantName: "subdir",
|
|
},
|
|
{
|
|
name: "/-/ marker still wins over host heuristic",
|
|
input: "git.company.com/group/sub/project/-/tree/main/skills/pdf",
|
|
hosts: []string{"git.company.com"},
|
|
wantURL: "https://git.company.com/group/sub/project.git",
|
|
wantName: "pdf",
|
|
},
|
|
{
|
|
name: "built-in gitlab.com detection unchanged",
|
|
input: "gitlab.com/group/sub/project",
|
|
hosts: nil,
|
|
wantURL: "https://gitlab.com/group/sub/project.git",
|
|
wantName: "project",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
opts := ParseOptions{GitLabHosts: tt.hosts}
|
|
source, err := ParseSourceWithOptions(tt.input, opts)
|
|
if err != nil {
|
|
t.Fatalf("ParseSourceWithOptions(%q) error = %v", tt.input, err)
|
|
}
|
|
if source.CloneURL != tt.wantURL {
|
|
t.Errorf("CloneURL = %q, want %q", source.CloneURL, tt.wantURL)
|
|
}
|
|
if source.Name != tt.wantName {
|
|
t.Errorf("Name = %q, want %q", source.Name, tt.wantName)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseSourceWithOptions_CNBGiteaHosts(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
opts ParseOptions
|
|
wantCloneURL string
|
|
wantSubdir string
|
|
wantName string
|
|
}{
|
|
{
|
|
name: "cnb root repo keeps two segment repo",
|
|
input: "https://cnb.cool/org/repo",
|
|
wantCloneURL: "https://cnb.cool/org/repo.git",
|
|
wantName: "repo",
|
|
},
|
|
{
|
|
name: "cnb subdir uses owner repo split",
|
|
input: "https://cnb.cool/org/repo/skills/foo",
|
|
wantCloneURL: "https://cnb.cool/org/repo.git",
|
|
wantSubdir: "skills/foo",
|
|
wantName: "foo",
|
|
},
|
|
{
|
|
name: "custom cnb host uses configured host",
|
|
input: "https://git.corp.example/org/repo/skills/foo",
|
|
opts: ParseOptions{CNBHosts: []string{"git.corp.example"}},
|
|
wantCloneURL: "https://git.corp.example/org/repo.git",
|
|
wantSubdir: "skills/foo",
|
|
wantName: "foo",
|
|
},
|
|
{
|
|
name: "custom gitea host uses configured host",
|
|
input: "https://git.example.com/org/repo/skills/foo",
|
|
opts: ParseOptions{GiteaHosts: []string{"git.example.com"}},
|
|
wantCloneURL: "https://git.example.com/org/repo.git",
|
|
wantSubdir: "skills/foo",
|
|
wantName: "foo",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
source, err := ParseSourceWithOptions(tt.input, tt.opts)
|
|
if err != nil {
|
|
t.Fatalf("ParseSourceWithOptions(%q) error = %v", tt.input, err)
|
|
}
|
|
if source.CloneURL != tt.wantCloneURL {
|
|
t.Errorf("CloneURL = %q, want %q", source.CloneURL, tt.wantCloneURL)
|
|
}
|
|
if source.Subdir != tt.wantSubdir {
|
|
t.Errorf("Subdir = %q, want %q", source.Subdir, tt.wantSubdir)
|
|
}
|
|
if source.Name != tt.wantName {
|
|
t.Errorf("Name = %q, want %q", source.Name, tt.wantName)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseSourceWithOptions_AzureHosts(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
hosts []string
|
|
wantCloneURL string
|
|
wantSubdir string
|
|
wantName string
|
|
}{
|
|
{
|
|
name: "on-prem URL with host in azure_hosts",
|
|
input: "https://azuredevops.mycompany.com/Org/Project/_git/Repo",
|
|
hosts: []string{"azuredevops.mycompany.com"},
|
|
wantCloneURL: "https://azuredevops.mycompany.com/Org/Project/_git/Repo",
|
|
wantSubdir: "",
|
|
wantName: "Repo",
|
|
},
|
|
{
|
|
name: "on-prem URL with subdir",
|
|
input: "https://azuredevops.mycompany.com/Org/Project/_git/Repo/skills/react",
|
|
hosts: []string{"azuredevops.mycompany.com"},
|
|
wantCloneURL: "https://azuredevops.mycompany.com/Org/Project/_git/Repo",
|
|
wantSubdir: "skills/react",
|
|
wantName: "react",
|
|
},
|
|
{
|
|
name: "on-prem URL with .git suffix stripped",
|
|
input: "https://azuredevops.mycompany.com/Org/Project/_git/Repo.git",
|
|
hosts: []string{"azuredevops.mycompany.com"},
|
|
wantCloneURL: "https://azuredevops.mycompany.com/Org/Project/_git/Repo",
|
|
wantSubdir: "",
|
|
wantName: "Repo",
|
|
},
|
|
{
|
|
name: "case-insensitive host match",
|
|
input: "https://AzureDevOps.MyCompany.COM/Org/Project/_git/Repo",
|
|
hosts: []string{"azuredevops.mycompany.com"},
|
|
wantCloneURL: "https://AzureDevOps.MyCompany.COM/Org/Project/_git/Repo",
|
|
wantSubdir: "",
|
|
wantName: "Repo",
|
|
},
|
|
{
|
|
name: "/_git/ URL without azure_hosts falls through",
|
|
input: "https://azuredevops.mycompany.com/Org/Project/_git/Repo",
|
|
hosts: nil,
|
|
wantCloneURL: "https://azuredevops.mycompany.com/Org/Project.git",
|
|
wantSubdir: "_git/Repo",
|
|
wantName: "Repo",
|
|
},
|
|
{
|
|
name: "dev.azure.com still uses hardcoded pattern",
|
|
input: "https://dev.azure.com/org/proj/_git/repo",
|
|
hosts: nil,
|
|
wantCloneURL: "https://dev.azure.com/org/proj/_git/repo",
|
|
wantSubdir: "",
|
|
wantName: "repo",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
opts := ParseOptions{AzureHosts: tt.hosts}
|
|
source, err := ParseSourceWithOptions(tt.input, opts)
|
|
if err != nil {
|
|
t.Fatalf("ParseSourceWithOptions(%q) error = %v", tt.input, err)
|
|
}
|
|
if source.CloneURL != tt.wantCloneURL {
|
|
t.Errorf("CloneURL = %q, want %q", source.CloneURL, tt.wantCloneURL)
|
|
}
|
|
if source.Subdir != tt.wantSubdir {
|
|
t.Errorf("Subdir = %q, want %q", source.Subdir, tt.wantSubdir)
|
|
}
|
|
if source.Name != tt.wantName {
|
|
t.Errorf("Name = %q, want %q", source.Name, tt.wantName)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestTrackName_AzureOnPrem(t *testing.T) {
|
|
opts := ParseOptions{AzureHosts: []string{"azuredevops.mycompany.com"}}
|
|
source, err := ParseSourceWithOptions("https://azuredevops.mycompany.com/Org/Project/_git/Repo", opts)
|
|
if err != nil {
|
|
t.Fatalf("ParseSourceWithOptions() error: %v", err)
|
|
}
|
|
got := source.TrackName()
|
|
if got != "Org-Project-Repo" {
|
|
t.Errorf("TrackName() = %q, want %q", got, "Org-Project-Repo")
|
|
}
|
|
}
|
|
|
|
func TestParseSource_AzureDevOps_GitHubOwnerEmpty(t *testing.T) {
|
|
// Azure DevOps sources should return empty GitHubOwner/GitHubRepo
|
|
inputs := []string{
|
|
"https://dev.azure.com/org/proj/_git/repo",
|
|
"git@ssh.dev.azure.com:v3/org/proj/repo",
|
|
"ado:org/proj/repo",
|
|
}
|
|
|
|
for _, input := range inputs {
|
|
t.Run(input, func(t *testing.T) {
|
|
source, err := ParseSource(input)
|
|
if err != nil {
|
|
t.Fatalf("ParseSource(%q) error: %v", input, err)
|
|
}
|
|
if got := source.GitHubOwner(); got != "" {
|
|
t.Errorf("GitHubOwner() = %q, want empty", got)
|
|
}
|
|
if got := source.GitHubRepo(); got != "" {
|
|
t.Errorf("GitHubRepo() = %q, want empty", got)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestSource_GitHubAPIBase(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
want string
|
|
}{
|
|
{"github.com shorthand", "owner/repo", "https://api.github.com"},
|
|
{"github.com full URL", "https://github.com/owner/repo", "https://api.github.com"},
|
|
{"github.com SSH", "git@github.com:owner/repo.git", "https://api.github.com"},
|
|
{"GHE Server", "https://github.mycompany.com/org/repo", "https://github.mycompany.com/api/v3"},
|
|
{"GHE Server shorthand", "github.acme.com/team/project", "https://github.acme.com/api/v3"},
|
|
{"GHE Cloud .ghe.com", "https://octocorp.ghe.com/org/repo", "https://api.octocorp.ghe.com"},
|
|
{"GHE SSH", "git@github.mycompany.com:org/repo.git", "https://github.mycompany.com/api/v3"},
|
|
{"GitLab is not GitHub", "https://gitlab.com/group/project", ""},
|
|
{"Bitbucket is not GitHub", "https://bitbucket.org/team/repo", ""},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
source, err := ParseSource(tt.input)
|
|
if err != nil {
|
|
t.Fatalf("ParseSource(%q) error: %v", tt.input, err)
|
|
}
|
|
if got := source.GitHubAPIBase(); got != tt.want {
|
|
t.Errorf("GitHubAPIBase() = %q, want %q", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|