mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-04-24 13:56:57 +00:00
add test to override values from config when args are present
This commit is contained in:
parent
2238a57801
commit
5ed4ca2500
2 changed files with 55 additions and 7 deletions
|
@ -8,15 +8,15 @@ httpServerEnabled = true
|
||||||
mainDomain = 'codeberg.page'
|
mainDomain = 'codeberg.page'
|
||||||
rawDomain = 'raw.codeberg.page'
|
rawDomain = 'raw.codeberg.page'
|
||||||
allowedCorsDomains = ['fonts.codeberg.org', 'design.codeberg.org']
|
allowedCorsDomains = ['fonts.codeberg.org', 'design.codeberg.org']
|
||||||
blacklistedPaths = []
|
blacklistedPaths = ['do/not/use']
|
||||||
|
|
||||||
[gitea]
|
[gitea]
|
||||||
root = 'codeberg.org'
|
root = 'codeberg.org'
|
||||||
token = 'XXXXX'
|
token = 'XXXXXXXX'
|
||||||
lfsEnabled = true
|
lfsEnabled = true
|
||||||
followSymlinks = true
|
followSymlinks = true
|
||||||
defaultMimeType = "application/wasm"
|
defaultMimeType = "application/wasm"
|
||||||
forbiddenMimeTypes = []
|
forbiddenMimeTypes = ["text/html"]
|
||||||
|
|
||||||
[database]
|
[database]
|
||||||
type = 'sqlite'
|
type = 'sqlite'
|
||||||
|
@ -27,7 +27,7 @@ email = 'a@b.c'
|
||||||
apiEndpoint = 'https://example.com'
|
apiEndpoint = 'https://example.com'
|
||||||
acceptTerms = false
|
acceptTerms = false
|
||||||
useRateLimits = true
|
useRateLimits = true
|
||||||
eab_hmac = ''
|
eab_hmac = 'asdf'
|
||||||
eab_kid = ''
|
eab_kid = 'qwer'
|
||||||
dnsProvider = ''
|
dnsProvider = 'cloudflare.com'
|
||||||
accountConfigFile = ''
|
accountConfigFile = 'nope'
|
||||||
|
|
|
@ -42,6 +42,21 @@ func fixArrayFromCtx(ctx *cli.Context, key string, expected []string) []string {
|
||||||
return expected
|
return expected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func readTestConfig() (*Config, error) {
|
||||||
|
content, err := os.ReadFile("assets/test_config.toml")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedConfig := &Config{}
|
||||||
|
err = toml.Unmarshal(content, expectedConfig)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return expectedConfig, nil
|
||||||
|
}
|
||||||
|
|
||||||
func TestReadConfigShouldReturnEmptyConfigWhenConfigArgEmpty(t *testing.T) {
|
func TestReadConfigShouldReturnEmptyConfigWhenConfigArgEmpty(t *testing.T) {
|
||||||
runApp(
|
runApp(
|
||||||
t,
|
t,
|
||||||
|
@ -79,6 +94,39 @@ func TestReadConfigShouldReturnConfigFromFileWhenConfigArgPresent(t *testing.T)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestValuesReadFromConfigFileShouldBeOverwrittenByArgs(t *testing.T) {
|
||||||
|
runApp(
|
||||||
|
t,
|
||||||
|
func(ctx *cli.Context) error {
|
||||||
|
cfg, err := ReadConfig(ctx)
|
||||||
|
|
||||||
|
MergeConfig(ctx, cfg)
|
||||||
|
|
||||||
|
expectedConfig, err := readTestConfig()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedConfig.LogLevel = "debug"
|
||||||
|
expectedConfig.Gitea.Root = "not-codeberg.org"
|
||||||
|
expectedConfig.ACME.AcceptTerms = true
|
||||||
|
expectedConfig.Server.Host = "172.17.0.2"
|
||||||
|
expectedConfig.Server.BlacklistedPaths = append(expectedConfig.Server.BlacklistedPaths, ALWAYS_BLACKLISTED_PATHS...)
|
||||||
|
|
||||||
|
assert.Equal(t, expectedConfig, cfg)
|
||||||
|
|
||||||
|
return err
|
||||||
|
},
|
||||||
|
[]string{
|
||||||
|
"--config-file", "assets/test_config.toml",
|
||||||
|
"--log-level", "debug",
|
||||||
|
"--gitea-root", "not-codeberg.org",
|
||||||
|
"--acme-accept-terms",
|
||||||
|
"--host", "172.17.0.2",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
func TestMergeConfigShouldReplaceAllExistingValuesGivenAllArgsExist(t *testing.T) {
|
func TestMergeConfigShouldReplaceAllExistingValuesGivenAllArgsExist(t *testing.T) {
|
||||||
runApp(
|
runApp(
|
||||||
t,
|
t,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue