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