From ab43a97a459204711337904848405a2cd9df12d6 Mon Sep 17 00:00:00 2001 From: Alan Moran Date: Fri, 9 Aug 2024 13:06:35 +0200 Subject: [PATCH] Refactor error variable names and update associated tests in metricsforwarder config --- .../metricsforwarder/config/config.go | 19 +++++++++---------- .../metricsforwarder/config/config_test.go | 16 ++++++++-------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/autoscaler/metricsforwarder/config/config.go b/src/autoscaler/metricsforwarder/config/config.go index 9aa5fb3c82..29c2af0a31 100644 --- a/src/autoscaler/metricsforwarder/config/config.go +++ b/src/autoscaler/metricsforwarder/config/config.go @@ -18,14 +18,13 @@ import ( ) // There are 3 type of errors that this package can return: -// - ReadYamlError -// - ReadFileError -// - ReadEnvironmentError +// - ErrReadYaml +// - ErrReadEnvironment +// - ErrReadVCAPEnvironment -var ReadYamlError = errors.New("failed to read config file") -var ReadFileError = errors.New("failed to open config file") -var ReadEnvironmentError = errors.New("failed to read environment variables") -var ReadVCAPEnvironmentError = errors.New("failed to read VCAP environment variables") +var ErrReadYaml = errors.New("failed to read config file") +var ErrReadEnvironment = errors.New("failed to read environment variables") +var ErrReadVCAPEnvironment = errors.New("failed to read VCAP environment variables") const ( DefaultMetronAddress = "127.0.0.1:3458" @@ -116,7 +115,7 @@ func LoadConfig(filepath string) (*Config, error) { err = dec.Decode(&conf) if err != nil { - return nil, fmt.Errorf("%w: %w", ReadYamlError, err) + return nil, fmt.Errorf("%w: %w", ErrReadYaml, err) } defer r.Close() @@ -124,12 +123,12 @@ func LoadConfig(filepath string) (*Config, error) { err = envconfig.Process("", &conf) if err != nil { - return nil, fmt.Errorf("%w: %w", ReadEnvironmentError, err) + return nil, fmt.Errorf("%w: %w", ErrReadEnvironment, err) } err = loadVCAPEnvs(&conf) if err != nil { - return nil, fmt.Errorf("%w: %w", ReadVCAPEnvironmentError, err) + return nil, fmt.Errorf("%w: %w", ErrReadVCAPEnvironment, err) } return &conf, nil diff --git a/src/autoscaler/metricsforwarder/config/config_test.go b/src/autoscaler/metricsforwarder/config/config_test.go index 6d7ded3463..b7b1db94fc 100644 --- a/src/autoscaler/metricsforwarder/config/config_test.go +++ b/src/autoscaler/metricsforwarder/config/config_test.go @@ -119,7 +119,7 @@ cred_helper_impl: default }) It("return invalid port error", func() { - Expect(err).To(MatchError(config.ReadEnvironmentError)) + Expect(err).To(MatchError(config.ErrReadEnvironment)) Expect(err).To(MatchError(MatchRegexp("converting 'NAN' to type int"))) }) @@ -206,7 +206,7 @@ server: }) It("should error", func() { - Expect(err).To(MatchError(config.ReadYamlError)) + Expect(err).To(MatchError(config.ErrReadYaml)) Expect(err).To(MatchError(MatchRegexp("cannot unmarshal.*into int"))) }) }) @@ -220,7 +220,7 @@ health: }) It("should error", func() { - Expect(err).To(MatchError(config.ReadYamlError)) + Expect(err).To(MatchError(config.ErrReadYaml)) Expect(err).To(MatchError(MatchRegexp("cannot unmarshal.*into int"))) }) }) @@ -246,7 +246,7 @@ health: }) It("should error", func() { - Expect(err).To(MatchError(config.ReadYamlError)) + Expect(err).To(MatchError(config.ErrReadYaml)) Expect(err).To(MatchError(MatchRegexp("cannot unmarshal.*into int"))) }) }) @@ -272,7 +272,7 @@ health: }) It("should error", func() { - Expect(err).To(MatchError(config.ReadYamlError)) + Expect(err).To(MatchError(config.ErrReadYaml)) Expect(err).To(MatchError(MatchRegexp("cannot unmarshal.*into int"))) }) }) @@ -298,7 +298,7 @@ health: }) It("should error", func() { - Expect(err).To(MatchError(config.ReadYamlError)) + Expect(err).To(MatchError(config.ErrReadYaml)) Expect(err).To(MatchError(MatchRegexp("cannot unmarshal .* into time.Duration"))) }) }) @@ -327,7 +327,7 @@ rate_limit: }) It("should error", func() { - Expect(err).To(MatchError(config.ReadYamlError)) + Expect(err).To(MatchError(config.ErrReadYaml)) Expect(err).To(MatchError(MatchRegexp("cannot unmarshal .* into int"))) }) }) @@ -356,7 +356,7 @@ rate_limit: }) It("should error", func() { - Expect(err).To(MatchError(config.ReadYamlError)) + Expect(err).To(MatchError(config.ErrReadYaml)) Expect(err).To(MatchError(MatchRegexp("cannot unmarshal .* into time.Duration"))) }) })