diff --git a/pkg/configutil/once.go b/pkg/configutil/once.go index 77daaee5..3d6acd17 100644 --- a/pkg/configutil/once.go +++ b/pkg/configutil/once.go @@ -25,17 +25,15 @@ import ( // If previous config file does not exist, it reads the config from file // or return a default config if not found. // The returned config is only suitable for read only scenarios for short-lived processes. -func LoadConfigOnce() (*config.Config, error) { - return sync.OnceValues(func() (*config.Config, error) { - configInfo, err := config.LoadConfig() - if err != nil { - return nil, err - } - // set default value - configInfo.SignatureFormat = strings.ToLower(configInfo.SignatureFormat) - if configInfo.SignatureFormat == "" { - configInfo.SignatureFormat = envelope.JWS - } - return configInfo, nil - })() -} +var LoadConfigOnce = sync.OnceValues(func() (*config.Config, error) { + configInfo, err := config.LoadConfig() + if err != nil { + return nil, err + } + // set default value + configInfo.SignatureFormat = strings.ToLower(configInfo.SignatureFormat) + if configInfo.SignatureFormat == "" { + configInfo.SignatureFormat = envelope.JWS + } + return configInfo, nil +}) diff --git a/pkg/configutil/once_test.go b/pkg/configutil/once_test.go index aba9c25a..5f6ebdef 100644 --- a/pkg/configutil/once_test.go +++ b/pkg/configutil/once_test.go @@ -16,7 +16,6 @@ package configutil import ( "os" "path/filepath" - "reflect" "strings" "testing" @@ -32,8 +31,8 @@ func TestLoadConfigOnce(t *testing.T) { if err != nil { t.Fatal("LoadConfigOnce failed.") } - if !reflect.DeepEqual(config1, config2) { - t.Fatal("Configs differ in content.") + if config1 != config2 { + t.Fatal("LoadConfigOnce should return the same config.") } } @@ -50,8 +49,8 @@ func TestLoadConfigOnceError(t *testing.T) { if err == nil || !strings.Contains(err.Error(), "invalid character") { t.Fatal("LoadConfigOnce should fail.") } - _, err = LoadConfigOnce() - if err == nil || !strings.Contains(err.Error(), "invalid character") { - t.Fatal("LoadConfigOnce should fail.") + _, err2 := LoadConfigOnce() + if err != err2 { + t.Fatal("LoadConfigOnce should return the same error.") } }