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