1package git
2
3import (
4 "testing"
5)
6
7func TestStringifyRepo(t *testing.T) {
8 wantGitHub := "data/github.com/owner/repo"
9 wantSourceHut := "data/git.sr.ht/~owner/repo"
10
11 tests := []struct {
12 name string
13 input string
14 want string
15 }{
16 {
17 name: "GitHubHTTP",
18 input: "http://github.com/owner/repo",
19 want: wantGitHub,
20 },
21 {
22 name: "GitHubHTTPS",
23 input: "https://github.com/owner/repo",
24 want: wantGitHub,
25 },
26 {
27 name: "GitHubSSH",
28 input: "git@github.com:owner/repo",
29 want: wantGitHub,
30 },
31 {
32 name: "SourceHutHTTP",
33 input: "http://git.sr.ht/~owner/repo",
34 want: wantSourceHut,
35 },
36 {
37 name: "SourceHutHTTPS",
38 input: "https://git.sr.ht/~owner/repo",
39 want: wantSourceHut,
40 },
41 {
42 name: "SourceHutSSH",
43 input: "git@git.sr.ht:~owner/repo",
44 want: wantSourceHut,
45 },
46 }
47
48 for _, test := range tests {
49 t.Run(test.name, func(t *testing.T) {
50 got, err := stringifyRepo(test.input)
51 if err != nil {
52 t.Errorf("stringifyRepo(%s) returned error: %v", test.input, err)
53 }
54 if got != test.want {
55 t.Errorf("stringifyRepo(%s) = %s, want %s", test.input, got, test.want)
56 }
57 })
58 }
59}