1package utils
 2
 3import "testing"
 4
 5func TestValidateRepo(t *testing.T) {
 6	t.Run("valid", func(t *testing.T) {
 7		for _, repo := range []string{
 8			"lower",
 9			"Upper",
10			"with-dash",
11			"with/slash",
12			"withnumb3r5",
13			"with.dot",
14			"with_underline",
15		} {
16			t.Run(repo, func(t *testing.T) {
17				if err := ValidateRepo(repo); err != nil {
18					t.Errorf("expected no error, got %v", err)
19				}
20			})
21		}
22	})
23	t.Run("invalid", func(t *testing.T) {
24		for _, repo := range []string{
25			"with$",
26			"with@",
27			"with!",
28		} {
29			t.Run(repo, func(t *testing.T) {
30				if err := ValidateRepo(repo); err == nil {
31					t.Error("expected an error, got nil")
32				}
33			})
34		}
35	})
36}
37
38func TestSanitizeRepo(t *testing.T) {
39	cases := []struct {
40		in, out string
41	}{
42		{"lower", "lower"},
43		{"Upper", "Upper"},
44		{"with/slash", "with/slash"},
45		{"with.dot", "with.dot"},
46		{"/with_forward_slash", "with_forward_slash"},
47		{"withgitsuffix.git", "withgitsuffix"},
48	}
49	for _, c := range cases {
50		t.Run(c.in, func(t *testing.T) {
51			if got := SanitizeRepo(c.in); got != c.out {
52				t.Errorf("expected %q, got %q", c.out, got)
53			}
54		})
55	}
56}