Skip to content

Commit

Permalink
Merge pull request #11020 from lekaf974/bug/issue-10960-mesheryctl-pa…
Browse files Browse the repository at this point in the history
…ttern-import-url

Set source-type flag required
  • Loading branch information
MUzairS15 committed May 28, 2024
2 parents 323198d + 8283674 commit 6ff2200
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mesheryctl/helpers/component_info.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "mesheryctl",
"type": "client",
"next_error_code": 1121
"next_error_code": 1122
}
9 changes: 9 additions & 0 deletions mesheryctl/internal/cli/root/pattern/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
ErrOffboardPatternCode = "mesheryctl-1005"
ErrPatternFlagCode = "mesheryctl-1006"
ErrPatternManifestCode = "mesheryctl-1007"
ErrPatternSourceTypeCode = "mesheryctl-1121"
ErrPatternsNotFoundCode = "mesheryctl-1037"
ErrInvalidPatternFileCode = "mesheryctl-1038"
ErrPatternInvalidNameOrIDCode = "mesheryctl-1039"
Expand Down Expand Up @@ -85,6 +86,14 @@ func ErrPatternManifest() error {
[]string{"Provide the path to the pattern manifest. \n\n%v", errPatternMsg})
}

func ErrPatternSourceType() error {
return errors.New(ErrPatternSourceTypeCode, errors.Alert,
[]string{"Source type for the design to import not specified"},
[]string{"Empty source type detected"},
[]string{"Design source type not provided"},
[]string{"Provide one of the supported source type for the design to import. \n\n%v", errPatternMsg})
}

func ErrOnboardPattern() error {
return errors.New(ErrOnboardPatternCode, errors.Alert,
[]string{"Error Onboarding pattern"},
Expand Down
7 changes: 6 additions & 1 deletion mesheryctl/internal/cli/root/pattern/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var importCmd = &cobra.Command{
YAML and TGZ (with helm only) format of file is accepted, if you are importing Meshery Design OCI file format is also supported
If you are providing remote URL, it should be a direct URL to a downloadable file.
If you are providing remote URL, it should be a direct URL to a downloadable file.
For example, if the file is stored on GitHub, the URL should be 'https://raw.githubusercontent.com/path-to-file'.
`,
Example: `
Expand All @@ -58,6 +58,11 @@ mesheryctl pattern import -f [file/URL] -s [source-type] -n [name]
return ErrPatternManifest()
}

if sourceType == "" {
utils.Log.Debug("source-type not provided")
return ErrPatternSourceType()
}

return nil
},
PreRunE: func(cmd *cobra.Command, args []string) error {
Expand Down
43 changes: 43 additions & 0 deletions mesheryctl/internal/cli/root/pattern/import_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package pattern

import (
"testing"
)

func Test_importPattern_DisplayErrorsMissingFlags(t *testing.T) {
type args struct {
sourceType string
file string
patternURL string
save bool
}

tests := []struct {
name string
args args
want error
wantErr bool
}{
{
name: "Import missing source type flag",
args: args{"", "file.yaml", "", false},
want: ErrPatternSourceType(),
wantErr: true,
},
{
name: "Import missing file flag",
args: args{"helm", "", "", false},
want: ErrPatternManifest(),
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, err := importPattern(tt.args.sourceType, tt.args.file, tt.args.patternURL, tt.args.save)
if (err != nil) != tt.wantErr {
t.Errorf("importPattern() error = %v, wantErr %v", err, tt.wantErr)
return
}
})
}
}

0 comments on commit 6ff2200

Please sign in to comment.