code.gitea.io/gitea@v1.22.3/routers/utils/utils_test.go (about)

     1  // Copyright 2017 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package utils
     5  
     6  import (
     7  	"testing"
     8  )
     9  
    10  func TestSanitizeFlashErrorString(t *testing.T) {
    11  	tests := []struct {
    12  		name string
    13  		arg  string
    14  		want string
    15  	}{
    16  		{
    17  			name: "no error",
    18  			arg:  "",
    19  			want: "",
    20  		},
    21  		{
    22  			name: "normal error",
    23  			arg:  "can not open file: \"abc.exe\"",
    24  			want: "can not open file: "abc.exe"",
    25  		},
    26  		{
    27  			name: "line break error",
    28  			arg:  "some error:\n\nawesome!",
    29  			want: "some error:<br><br>awesome!",
    30  		},
    31  	}
    32  
    33  	for _, tt := range tests {
    34  		t.Run(tt.name, func(t *testing.T) {
    35  			if got := SanitizeFlashErrorString(tt.arg); got != tt.want {
    36  				t.Errorf("SanitizeFlashErrorString() = '%v', want '%v'", got, tt.want)
    37  			}
    38  		})
    39  	}
    40  }