Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set source-type flag required #11020

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
}
})
}
}