aboutsummaryrefslogtreecommitdiffstats
path: root/routers/utils
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2021-06-29 23:00:02 +0200
committerGitHub <noreply@github.com>2021-06-29 22:00:02 +0100
commitdea7a5c5b9fa7eea331159020268f8898a0a678d (patch)
tree2f21d25395957a79435874de2c875c249317702b /routers/utils
parentadd74fb368b4b6a5deee91e052240c0956d7dc5b (diff)
downloadgitea-dea7a5c5b9fa7eea331159020268f8898a0a678d.tar.gz
gitea-dea7a5c5b9fa7eea331159020268f8898a0a678d.zip
just add some unit tests (#16291)
* code.gitea.io/gitea/routers/utils coverage: 100.0% * code.gitea.io/gitea/routers/install 0% -> 5.0% * ConvertUtf8ToUtf8mb4: make sure DBType is mysql
Diffstat (limited to 'routers/utils')
-rw-r--r--routers/utils/utils_test.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/routers/utils/utils_test.go b/routers/utils/utils_test.go
index 78ab3d20ee..bca5263311 100644
--- a/routers/utils/utils_test.go
+++ b/routers/utils/utils_test.go
@@ -62,7 +62,41 @@ func TestIsExternalURL(t *testing.T) {
"//try.gitea.io/test?param=false"),
newTest(false,
"/hey/hey/hey#3244"),
+ newTest(true,
+ "://missing protocol scheme"),
} {
assert.Equal(t, test.Expected, IsExternalURL(test.RawURL))
}
}
+
+func TestSanitizeFlashErrorString(t *testing.T) {
+ tests := []struct {
+ name string
+ arg string
+ want string
+ }{
+ {
+ name: "no error",
+ arg: "",
+ want: "",
+ },
+ {
+ name: "normal error",
+ arg: "can not open file: \"abc.exe\"",
+ want: "can not open file: &#34;abc.exe&#34;",
+ },
+ {
+ name: "line break error",
+ arg: "some error:\n\nawesome!",
+ want: "some error:<br><br>awesome!",
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := SanitizeFlashErrorString(tt.arg); got != tt.want {
+ t.Errorf("SanitizeFlashErrorString() = '%v', want '%v'", got, tt.want)
+ }
+ })
+ }
+}