2017-12-07 07:00:09 +00:00
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
2022-11-27 18:20:29 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2017-12-07 07:00:09 +00:00
|
|
|
|
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2021-06-29 21:00:02 +00: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)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|