test: validate repo

Carlos Alexandro Becker created

Change summary

server/utils/utils_test.go | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)

Detailed changes

server/utils/utils_test.go 🔗

@@ -0,0 +1,36 @@
+package utils
+
+import "testing"
+
+func TestValidateRepo(t *testing.T) {
+	t.Run("valid", func(t *testing.T) {
+		for _, repo := range []string{
+			"lower",
+			"Upper",
+			"with-dash",
+			"with/slash",
+			"withnumb3r5",
+			"with.dot",
+			"with_underline",
+		} {
+			t.Run(repo, func(t *testing.T) {
+				if err := ValidateRepo(repo); err != nil {
+					t.Errorf("expected no error, got %v", err)
+				}
+			})
+		}
+	})
+	t.Run("invalid", func(t *testing.T) {
+		for _, repo := range []string{
+			"with$",
+			"with@",
+			"with!",
+		} {
+			t.Run(repo, func(t *testing.T) {
+				if err := ValidateRepo(repo); err == nil {
+					t.Error("expected an error, got nil")
+				}
+			})
+		}
+	})
+}