Updating Config to a more protected access paradigm

This commit is contained in:
🐙PiperYxzzy
2022-08-14 13:37:15 +02:00
parent 9cc37b0d0d
commit 2922793427
5 changed files with 26 additions and 22 deletions

View File

@@ -16,52 +16,52 @@ func TestAllConfigs(t *testing.T) {
}
func SingleStackTest(t *testing.T, stack string, expected StackConfiguration) {
Config = StackConfiguration{}
configInternal = StackConfiguration{}
if Config.ConfigLoaded {
if Config().ConfigLoaded {
t.Errorf("Config.ConfigLoaded should be false before any processing")
}
if len(Config.AdminEmails) > 0 ||
Config.AdminHmacEnv != "" ||
Config.UserHmacEnv != "" ||
Config.AllowFreshAdminGeneration ||
Config.AuthedRateLimitConfig != "" ||
Config.UnauthedRateLimitConfig != "" { // Extend this IF for any other config values
if len(Config().AdminEmails) > 0 ||
Config().AdminHmacEnv != "" ||
Config().UserHmacEnv != "" ||
Config().AllowFreshAdminGeneration ||
Config().AuthedRateLimitConfig != "" ||
Config().UnauthedRateLimitConfig != "" { // Extend this IF for any other config values
t.Errorf("Config already has values before loading")
}
Environment = stack
LoadConfig()
if !Config.ConfigLoaded {
if !Config().ConfigLoaded {
t.Errorf("Config was not set to loaded")
}
// Finally test values
if Config.AllowFreshAdminGeneration != expected.AllowFreshAdminGeneration {
if Config().AllowFreshAdminGeneration != expected.AllowFreshAdminGeneration {
t.Errorf("AllowFreshAdminGeneration value not set properly")
}
for i, email := range Config.AdminEmails {
for i, email := range Config().AdminEmails {
if expected.AdminEmails[i] != email {
t.Errorf("AdminEmails value not set properly, expected %v at %v, was %v", expected.AdminEmails[i], i, email)
}
}
if Config.AdminHmacEnv != expected.AdminHmacEnv {
if Config().AdminHmacEnv != expected.AdminHmacEnv {
t.Errorf("AdminHmacEnv value not set properly")
}
if Config.UserHmacEnv != expected.UserHmacEnv {
if Config().UserHmacEnv != expected.UserHmacEnv {
t.Errorf("UserHmacEnv value not set properly")
}
if Config.AuthedRateLimitConfig != expected.AuthedRateLimitConfig {
if Config().AuthedRateLimitConfig != expected.AuthedRateLimitConfig {
t.Errorf("AuthedRateLimitConfig value not set properly")
}
if Config.UnauthedRateLimitConfig != expected.UnauthedRateLimitConfig {
if Config().UnauthedRateLimitConfig != expected.UnauthedRateLimitConfig {
t.Errorf("UnauthedRateLimitConfig value not set properly")
}