package gitsource import "testing" func TestNormalizeURL(t *testing.T) { cases := []struct { name, in, wantURL, wantRoot string }{ {"github repo", "https://github.com/org/repo", "https://github.com/org/repo.git", ""}, {"github tree with subpath", "https://github.com/org/repo/tree/main/skills", "https://github.com/org/repo.git", "skills"}, {"github tree nested subpath", "https://github.com/org/repo/tree/main/content/skills", "https://github.com/org/repo.git", "content/skills"}, {"github tree no subpath", "https://github.com/org/repo/tree/main", "https://github.com/org/repo.git", ""}, {"gitlab tree with subpath", "https://gitlab.com/org/repo/-/tree/main/agents", "https://gitlab.com/org/repo.git", "agents"}, {"gitlab plain repo", "https://gitlab.com/org/repo", "https://gitlab.com/org/repo.git", ""}, {"already normalized github", "https://github.com/org/repo.git", "https://github.com/org/repo.git", ""}, {"ssh url untouched", "git@github.com:org/repo.git", "git@github.com:org/repo.git", ""}, {"https url untouched", "https://example.com/repo.git", "https://example.com/repo.git", ""}, {"local path untouched", "/tmp/fixture-upstream", "/tmp/fixture-upstream", ""}, {"file url stripped", "file:///tmp/fixture-upstream", "/tmp/fixture-upstream", ""}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { url, root, err := NormalizeURL(tc.in) if err != nil { t.Fatalf("unexpected error: %v", err) } if url != tc.wantURL { t.Errorf("url = %q, want %q", url, tc.wantURL) } if root != tc.wantRoot { t.Errorf("root = %q, want %q", root, tc.wantRoot) } }) } }