Skip to content

Commit

Permalink
resolve error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
medmes committed Nov 26, 2024
1 parent da3ba26 commit 497df2f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions internal/common/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ func ValidateIsValidHTTPSURL(input string) error {
func validateSemanticVersion(version string) error {
_, err := semver.StrictNewVersion(strings.TrimSpace(version))
if err != nil {
return fmt.Errorf("opts.ModuleVersion failed to parse as semantic version: %w: %w",
commonerrors.ErrInvalidOption, err)
return fmt.Errorf("opts.ModuleVersion failed to parse as semantic version: %w",
commonerrors.ErrInvalidOption)
}

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func ValidateModuleConfig(moduleConfig *contentprovider.ModuleConfig) error {
}

if len(moduleConfig.Icons) == 0 {
return fmt.Errorf("failed to validate module icons: %w: must contain at least one icon",
return fmt.Errorf("failed to validate module icons: must contain at least one icon: %w",
commonerrors.ErrInvalidOption)
}

Expand Down
36 changes: 18 additions & 18 deletions internal/service/moduleconfig/reader/moduleconfig_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func Test_ValidateModuleConfig(t *testing.T) {
"module-icon": "https://example.com/path/to/some-icon",
},
},
expectedError: fmt.Errorf("failed to validate module name: %w", commonerrors.ErrInvalidOption),
expectedError: fmt.Errorf("opts.ModuleName must match the required pattern, e.g: 'github.com/path-to/your-repo': %w", commonerrors.ErrInvalidOption),
},
{
name: "invalid module version",
Expand All @@ -103,7 +103,7 @@ func Test_ValidateModuleConfig(t *testing.T) {
"module-icon": "https://example.com/path/to/some-icon",
},
},
expectedError: fmt.Errorf("failed to validate module version: %w", commonerrors.ErrInvalidOption),
expectedError: fmt.Errorf("opts.ModuleVersion failed to parse as semantic version: %w", commonerrors.ErrInvalidOption),
},
{
name: "invalid module namespace",
Expand All @@ -118,7 +118,7 @@ func Test_ValidateModuleConfig(t *testing.T) {
"module-icon": "https://example.com/path/to/some-icon",
},
},
expectedError: fmt.Errorf("failed to validate module namespace: %w", commonerrors.ErrInvalidOption),
expectedError: fmt.Errorf("namespace must match the required pattern, only small alphanumeric characters and hyphens: %w", commonerrors.ErrInvalidOption),
},
{
name: "empty manifest path",
Expand All @@ -133,7 +133,7 @@ func Test_ValidateModuleConfig(t *testing.T) {
"module-icon": "https://example.com/path/to/some-icon",
},
},
expectedError: fmt.Errorf("failed to validate manifest: %w: must not be empty",
expectedError: fmt.Errorf("failed to validate manifest: must not be empty: %w",
commonerrors.ErrInvalidOption),
},
{
Expand All @@ -149,7 +149,7 @@ func Test_ValidateModuleConfig(t *testing.T) {
"module-icon": "https://example.com/path/to/some-icon",
},
},
expectedError: fmt.Errorf("failed to validate manifest: %w: './test' is not using https scheme",
expectedError: fmt.Errorf("failed to validate manifest: './test' is not using https scheme: %w",
commonerrors.ErrInvalidOption),
},
{
Expand All @@ -166,7 +166,7 @@ func Test_ValidateModuleConfig(t *testing.T) {
},
DefaultCR: "/test",
},
expectedError: fmt.Errorf("failed to validate default CR: %w: '/test' is not using https scheme",
expectedError: fmt.Errorf("failed to validate default CR: '/test' is not using https scheme: %w",
commonerrors.ErrInvalidOption),
},
{
Expand All @@ -182,7 +182,7 @@ func Test_ValidateModuleConfig(t *testing.T) {
"module-icon": "https://example.com/path/to/some-icon",
},
},
expectedError: fmt.Errorf("failed to validate repository: %w: must not be empty",
expectedError: fmt.Errorf("failed to validate repository: must not be empty: %w",
commonerrors.ErrInvalidOption),
},
{
Expand All @@ -198,7 +198,7 @@ func Test_ValidateModuleConfig(t *testing.T) {
"module-icon": "https://example.com/path/to/some-icon",
},
},
expectedError: fmt.Errorf("failed to validate repository: %w: 'some repository' is not using https scheme",
expectedError: fmt.Errorf("failed to validate repository: 'some repository' is not using https scheme: %w",
commonerrors.ErrInvalidOption),
},
{
Expand All @@ -214,7 +214,7 @@ func Test_ValidateModuleConfig(t *testing.T) {
"module-icon": "https://example.com/path/to/some-icon",
},
},
expectedError: fmt.Errorf("failed to validate documentation: %w: must not be empty",
expectedError: fmt.Errorf("failed to validate documentation: must not be empty: %w",
commonerrors.ErrInvalidOption),
},
{
Expand All @@ -230,7 +230,7 @@ func Test_ValidateModuleConfig(t *testing.T) {
"module-icon": "https://example.com/path/to/some-icon",
},
},
expectedError: fmt.Errorf("failed to validate documentation: %w: 'some documentation' is not using https scheme",
expectedError: fmt.Errorf("failed to validate documentation: 'some documentation' is not using https scheme: %w",
commonerrors.ErrInvalidOption),
},
{
Expand All @@ -244,7 +244,7 @@ func Test_ValidateModuleConfig(t *testing.T) {
Documentation: "https://example.com/path/to/documentation",
Icons: contentprovider.Icons{},
},
expectedError: fmt.Errorf("failed to validate module icons: %w: must contain at least one icon",
expectedError: fmt.Errorf("failed to validate module icons: must contain at least one icon: %w",
commonerrors.ErrInvalidOption),
},
{
Expand All @@ -260,7 +260,7 @@ func Test_ValidateModuleConfig(t *testing.T) {
"": "https://example.com/path/to/some-icon",
},
},
expectedError: fmt.Errorf("failed to validate module icons: %w: name must not be empty",
expectedError: fmt.Errorf("failed to validate module icons: name must not be empty: %w",
commonerrors.ErrInvalidOption),
},
{
Expand All @@ -276,7 +276,7 @@ func Test_ValidateModuleConfig(t *testing.T) {
"module-icon": "",
},
},
expectedError: fmt.Errorf("failed to validate module icons: %w: link must not be empty",
expectedError: fmt.Errorf("failed to validate module icons: link must not be empty: %w",
commonerrors.ErrInvalidOption),
},
{
Expand All @@ -292,7 +292,7 @@ func Test_ValidateModuleConfig(t *testing.T) {
"module-icon": "this is not a URL",
},
},
expectedError: fmt.Errorf("failed to validate module icons: failed to validate link: %w: 'this is not a URL' is not using https scheme",
expectedError: fmt.Errorf("failed to validate module icons: failed to validate link: 'this is not a URL' is not using https scheme: %w",
commonerrors.ErrInvalidOption),
},
{
Expand All @@ -311,7 +311,7 @@ func Test_ValidateModuleConfig(t *testing.T) {
"key": "%% not a URL",
},
},
expectedError: fmt.Errorf("failed to validate resources: failed to validate link: %w: '%%%% not a URL' is not a valid URL",
expectedError: fmt.Errorf("failed to validate resources: failed to validate link: '%%%% not a URL' is not a valid URL: %w",
commonerrors.ErrInvalidOption),
},
{
Expand All @@ -330,7 +330,7 @@ func Test_ValidateModuleConfig(t *testing.T) {
"": "https://github.com/kyma-project/template-operator/releases/download/1.0.1/template-operator.yaml",
},
},
expectedError: fmt.Errorf("failed to validate resources: %w: name must not be empty",
expectedError: fmt.Errorf("failed to validate resources: name must not be empty: %w",
commonerrors.ErrInvalidOption),
},
{
Expand All @@ -349,15 +349,15 @@ func Test_ValidateModuleConfig(t *testing.T) {
"name": "",
},
},
expectedError: fmt.Errorf("failed to validate resources: %w: link must not be empty",
expectedError: fmt.Errorf("failed to validate resources: link must not be empty: %w",
commonerrors.ErrInvalidOption),
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
err := moduleconfigreader.ValidateModuleConfig(test.moduleConfig)
if test.expectedError != nil {
require.ErrorIs(t, err, test.expectedError, test.expectedError.Error())
require.ErrorContains(t, err, test.expectedError.Error())
return
}
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ var _ = Describe("Test 'create' command", Ordered, func() {
It("Then the command should fail", func() {
err := cmd.execute()
Expect(err).Should(HaveOccurred())
Expect(err.Error()).Should(ContainSubstring("failed to parse module config: failed to validate module config: failed to validate module icons: invalid Option: must contain at least one icon"))
Expect(err.Error()).Should(ContainSubstring("failed to parse module config: failed to validate module config: failed to validate module icons: must contain at least one icon: invalid Option"))
})
})

Expand Down

0 comments on commit 497df2f

Please sign in to comment.