From fc2d241cb7f80dde5b0eb00b7370b5b9bd6725ce Mon Sep 17 00:00:00 2001 From: Ibrahim AshShohail Date: Fri, 17 Nov 2017 10:24:58 +0300 Subject: [PATCH] dep: conver some errors to a variable Signed-off-by: Ibrahim AshShohail --- manifest.go | 25 ++++++++++++++----------- manifest_test.go | 6 ++++-- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/manifest.go b/manifest.go index c5e3f419cf..6115a5f482 100644 --- a/manifest.go +++ b/manifest.go @@ -24,17 +24,20 @@ const ManifestName = "Gopkg.toml" // Errors var ( - errInvalidConstraint = errors.Errorf("%q must be a TOML array of tables", "constraint") - errInvalidOverride = errors.Errorf("%q must be a TOML array of tables", "override") - errInvalidRequired = errors.Errorf("%q must be a TOML list of strings", "required") - errInvalidIgnored = errors.Errorf("%q must be a TOML list of strings", "ignored") - errInvalidPrune = errors.Errorf("%q must be a TOML table of booleans", "prune") - - errInvalidProjectRoot = errors.New("ProjectRoot name validation failed") - errInvalidPruneValue = errors.New("prune options values must be booleans") + errInvalidConstraint = errors.Errorf("%q must be a TOML array of tables", "constraint") + errInvalidOverride = errors.Errorf("%q must be a TOML array of tables", "override") + errInvalidRequired = errors.Errorf("%q must be a TOML list of strings", "required") + errInvalidIgnored = errors.Errorf("%q must be a TOML list of strings", "ignored") + errInvalidPrune = errors.Errorf("%q must be a TOML table of booleans", "prune") errInvalidPruneProject = errors.Errorf("%q must be a TOML array of tables", "prune.project") - errPruneSubProject = errors.New("prune projects should not contain sub projects") + errInvalidMetadata = errors.New("metadata should be a TOML table") + errInvalidProjectRoot = errors.New("ProjectRoot name validation failed") + + errInvalidPruneValue = errors.New("prune options values must be booleans") + errPruneSubProject = errors.New("prune projects should not contain sub projects") + + errRootPruneContainsName = errors.Errorf("%q should not include a name", "prune") errInvalidRootPruneValue = errors.New("root prune options must be omitted instead of being set to false") errInvalidPruneProjectName = errors.Errorf("%q in %q must be a string", "name", "prune.project") ) @@ -115,7 +118,7 @@ func validateManifest(s string) ([]error, error) { case "metadata": // Check if metadata is of Map type if reflect.TypeOf(val).Kind() != reflect.Map { - warns = append(warns, errors.New("metadata should be a TOML table")) + warns = append(warns, errInvalidMetadata) } case "constraint", "override": valid := true @@ -215,7 +218,7 @@ func validatePruneOptions(val interface{}, root bool) (warns []error, err error) } case "name": if root { - warns = append(warns, errors.Errorf("%q should not include a name", "prune")) + warns = append(warns, errRootPruneContainsName) } else if _, ok := value.(string); !ok { return warns, errInvalidPruneProjectName } diff --git a/manifest_test.go b/manifest_test.go index 531ae85e05..93eb95ab83 100644 --- a/manifest_test.go +++ b/manifest_test.go @@ -253,7 +253,9 @@ func TestValidateManifest(t *testing.T) { [[constraint]] name = "github.com/foo/bar" `, - wantWarn: []error{errors.New("metadata should be a TOML table")}, + wantWarn: []error{ + errInvalidMetadata, + }, wantError: nil, }, { @@ -402,7 +404,7 @@ func TestValidateManifest(t *testing.T) { name = "github.com/golang/dep" `, wantWarn: []error{ - fmt.Errorf("%q should not include a name", "prune"), + errRootPruneContainsName, }, wantError: nil, },