mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-28 19:29:02 +03:00
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
This commit is contained in:
parent
add74fb368
commit
dea7a5c5b9
3 changed files with 60 additions and 0 deletions
|
@ -8,10 +8,16 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
|
||||||
|
"xorm.io/xorm/schemas"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ConvertUtf8ToUtf8mb4 converts database and tables from utf8 to utf8mb4 if it's mysql and set ROW_FORMAT=dynamic
|
// ConvertUtf8ToUtf8mb4 converts database and tables from utf8 to utf8mb4 if it's mysql and set ROW_FORMAT=dynamic
|
||||||
func ConvertUtf8ToUtf8mb4() error {
|
func ConvertUtf8ToUtf8mb4() error {
|
||||||
|
if x.Dialect().URI().DBType != schemas.MYSQL {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
_, err := x.Exec(fmt.Sprintf("ALTER DATABASE `%s` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci", setting.Database.Name))
|
_, err := x.Exec(fmt.Sprintf("ALTER DATABASE `%s` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci", setting.Database.Name))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
20
routers/install/routes_test.go
Normal file
20
routers/install/routes_test.go
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package install
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestRoutes(t *testing.T) {
|
||||||
|
routes := Routes()
|
||||||
|
assert.NotNil(t, routes)
|
||||||
|
assert.Len(t, routes.R.Routes(), 1)
|
||||||
|
assert.EqualValues(t, "/", routes.R.Routes()[0].Pattern)
|
||||||
|
assert.Nil(t, routes.R.Routes()[0].SubRoutes)
|
||||||
|
assert.Len(t, routes.R.Routes()[0].Handlers, 2)
|
||||||
|
}
|
|
@ -62,7 +62,41 @@ func TestIsExternalURL(t *testing.T) {
|
||||||
"//try.gitea.io/test?param=false"),
|
"//try.gitea.io/test?param=false"),
|
||||||
newTest(false,
|
newTest(false,
|
||||||
"/hey/hey/hey#3244"),
|
"/hey/hey/hey#3244"),
|
||||||
|
newTest(true,
|
||||||
|
"://missing protocol scheme"),
|
||||||
} {
|
} {
|
||||||
assert.Equal(t, test.Expected, IsExternalURL(test.RawURL))
|
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: "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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue