forgejo/modules/setting/server_test.go
Minecon724 5016926d01
Some checks are pending
/ release (push) Waiting to run
testing / backend-checks (push) Waiting to run
testing / frontend-checks (push) Waiting to run
testing / test-unit (push) Blocked by required conditions
testing / test-e2e (push) Blocked by required conditions
testing / test-remote-cacher (redis) (push) Blocked by required conditions
testing / test-remote-cacher (valkey) (push) Blocked by required conditions
testing / test-remote-cacher (garnet) (push) Blocked by required conditions
testing / test-remote-cacher (redict) (push) Blocked by required conditions
testing / test-mysql (push) Blocked by required conditions
testing / test-pgsql (push) Blocked by required conditions
testing / test-sqlite (push) Blocked by required conditions
testing / security-check (push) Blocked by required conditions
Just merg
2025-03-29 20:14:01 +01:00

88 lines
2.5 KiB
Go

// Copyright 2024 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package setting
import (
"testing"
"forgejo.org/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)
}
func TestUnixSocketAbstractNamespace(t *testing.T) {
iniStr := `
[server]
PROTOCOL=http+unix
HTTP_ADDR=@forgejo
`
cfg, err := NewConfigProviderFromData(iniStr)
require.NoError(t, err)
loadServerFrom(cfg)
assert.EqualValues(t, "@forgejo", HTTPAddr)
}