Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

cloneUrl.test.ts

46 lines2.1 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { cloneUrlForProtocol, cloneUrlProtocol } from "./cloneUrl.ts";
4​
5describe("cloneUrlForProtocol", () => {
6 it("switches between scp-style SSH and HTTPS", () => {
7 expect(cloneUrlForProtocol("git@github.com:pingdotgg/t3code.git", "https")).toBe(
8 "https://github.com/pingdotgg/t3code.git",
9 );
10 expect(cloneUrlForProtocol("https://github.com/pingdotgg/t3code.git", "ssh")).toBe(
11 "git@github.com:pingdotgg/t3code.git",
12 );
13 expect(cloneUrlForProtocol("ssh://git@gitlab.com/group/sub/repo.git", "https")).toBe(
14 "https://gitlab.com/group/sub/repo.git",
15 );
16 expect(cloneUrlForProtocol("https://host/é/repo.git", "ssh")).toBe("git@host:é/repo.git");
17 expect(cloneUrlForProtocol("https://host//srv/git/repo.git", "ssh")).toBe(
18 "git@host:/srv/git/repo.git",
19 );
20 expect(cloneUrlForProtocol("http:team/repo.git", "https")).toBe("https://http/team/repo.git");
21 });
22​
23 it("keeps the URL as is for its own protocol and drops HTTPS credentials on switch", () => {
24 expect(cloneUrlForProtocol("https://token@github.com/a/b.git", "https")).toBe(
25 "https://token@github.com/a/b.git",
26 );
27 expect(cloneUrlForProtocol("https://token@github.com/a/b.git", "ssh")).toBe(
28 "git@github.com:a/b.git",
29 );
30 expect(cloneUrlForProtocol("https://user:tok@en@github.com/a/b.git", "ssh")).toBe(
31 "git@github.com:a/b.git",
32 );
33 });
34​
35 it("refuses rewrites that would guess wrong", () => {
36 expect(cloneUrlForProtocol("ssh://git@host.example:2222/a/b.git", "https")).toBeNull();
37 expect(cloneUrlForProtocol("https://host.example:8443/a/b.git", "ssh")).toBeNull();
38 expect(cloneUrlForProtocol("https://host.example:443/a/b.git", "ssh")).toBeNull();
39 expect(cloneUrlForProtocol("http://host.example:80/a/b.git", "ssh")).toBeNull();
40 expect(cloneUrlForProtocol("https://host.example:8443/a/b.git", "https")).toBe(
41 "https://host.example:8443/a/b.git",
42 );
43 expect(cloneUrlForProtocol("/srv/git/repo.git", "https")).toBeNull();
44 expect(cloneUrlProtocol("file:///srv/git/repo.git")).toBeNull();
45 });
46});