2017-12-07 02:00:09 -05:00
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
2022-11-27 13:20:29 -05:00
|
|
|
// SPDX-License-Identifier: MIT
|
2017-12-07 02:00:09 -05:00
|
|
|
|
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2021-06-29 17:00:02 -04:00
|
|
|
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: "abc.exe"",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|