1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
// Copyright 2024 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package setting
import (
"testing"
"code.gitea.io/gitea/modules/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestDisplayNameDefault(t *testing.T) {
defer test.MockVariableValue(&AppName, "Forgejo")()
defer test.MockVariableValue(&AppSlogan, "Beyond coding. We Forge.")()
defer test.MockVariableValue(&AppDisplayNameFormat, "{APP_NAME}: {APP_SLOGAN}")()
displayName := generateDisplayName()
assert.Equal(t, "Forgejo: Beyond coding. We Forge.", displayName)
}
func TestDisplayNameEmptySlogan(t *testing.T) {
defer test.MockVariableValue(&AppName, "Forgejo")()
defer test.MockVariableValue(&AppSlogan, "")()
defer test.MockVariableValue(&AppDisplayNameFormat, "{APP_NAME}: {APP_SLOGAN}")()
displayName := generateDisplayName()
assert.Equal(t, "Forgejo", displayName)
}
func TestDisplayNameCustomFormat(t *testing.T) {
defer test.MockVariableValue(&AppName, "Forgejo")()
defer test.MockVariableValue(&AppSlogan, "Beyond coding. We Forge.")()
defer test.MockVariableValue(&AppDisplayNameFormat, "{APP_NAME} - {APP_SLOGAN}")()
displayName := generateDisplayName()
assert.Equal(t, "Forgejo - Beyond coding. We Forge.", displayName)
}
func TestMaxUserRedirectsDefault(t *testing.T) {
iniStr := ``
cfg, err := NewConfigProviderFromData(iniStr)
require.NoError(t, err)
loadServiceFrom(cfg)
assert.EqualValues(t, 0, Service.UsernameCooldownPeriod)
assert.EqualValues(t, 0, Service.MaxUserRedirects)
iniStr = `[service]
MAX_USER_REDIRECTS = 8`
cfg, err = NewConfigProviderFromData(iniStr)
require.NoError(t, err)
loadServiceFrom(cfg)
assert.EqualValues(t, 0, Service.UsernameCooldownPeriod)
assert.EqualValues(t, 8, Service.MaxUserRedirects)
iniStr = `[service]
USERNAME_COOLDOWN_PERIOD = 3`
cfg, err = NewConfigProviderFromData(iniStr)
require.NoError(t, err)
loadServiceFrom(cfg)
assert.EqualValues(t, 3, Service.UsernameCooldownPeriod)
assert.EqualValues(t, 5, Service.MaxUserRedirects)
iniStr = `[service]
USERNAME_COOLDOWN_PERIOD = 3
MAX_USER_REDIRECTS = 8`
cfg, err = NewConfigProviderFromData(iniStr)
require.NoError(t, err)
loadServiceFrom(cfg)
assert.EqualValues(t, 3, Service.UsernameCooldownPeriod)
assert.EqualValues(t, 8, Service.MaxUserRedirects)
}
|