diff --git a/config/assets/test_config.toml b/config/assets/test_config.toml index eda0fc1..6a2f0d0 100644 --- a/config/assets/test_config.toml +++ b/config/assets/test_config.toml @@ -8,15 +8,15 @@ httpServerEnabled = true mainDomain = 'codeberg.page' rawDomain = 'raw.codeberg.page' allowedCorsDomains = ['fonts.codeberg.org', 'design.codeberg.org'] -blacklistedPaths = [] +blacklistedPaths = ['do/not/use'] [gitea] root = 'codeberg.org' -token = 'XXXXX' +token = 'XXXXXXXX' lfsEnabled = true followSymlinks = true defaultMimeType = "application/wasm" -forbiddenMimeTypes = [] +forbiddenMimeTypes = ["text/html"] [database] type = 'sqlite' @@ -27,7 +27,7 @@ email = 'a@b.c' apiEndpoint = 'https://example.com' acceptTerms = false useRateLimits = true -eab_hmac = '' -eab_kid = '' -dnsProvider = '' -accountConfigFile = '' +eab_hmac = 'asdf' +eab_kid = 'qwer' +dnsProvider = 'cloudflare.com' +accountConfigFile = 'nope' diff --git a/config/setup_test.go b/config/setup_test.go index 60df384..f0cab3a 100644 --- a/config/setup_test.go +++ b/config/setup_test.go @@ -42,6 +42,21 @@ func fixArrayFromCtx(ctx *cli.Context, key string, expected []string) []string { 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) { runApp( 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) { runApp( t,