diff --git a/mesheryctl/helpers/component_info.json b/mesheryctl/helpers/component_info.json index 20bf590135f..b121c4e88b9 100644 --- a/mesheryctl/helpers/component_info.json +++ b/mesheryctl/helpers/component_info.json @@ -1,5 +1,5 @@ { "name": "mesheryctl", "type": "client", - "next_error_code": 1121 + "next_error_code": 1122 } \ No newline at end of file diff --git a/mesheryctl/internal/cli/root/pattern/error.go b/mesheryctl/internal/cli/root/pattern/error.go index 2c66503a5e8..22fb4f5d94e 100644 --- a/mesheryctl/internal/cli/root/pattern/error.go +++ b/mesheryctl/internal/cli/root/pattern/error.go @@ -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" @@ -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"}, diff --git a/mesheryctl/internal/cli/root/pattern/import.go b/mesheryctl/internal/cli/root/pattern/import.go index a7182350209..cc5be61bb4a 100644 --- a/mesheryctl/internal/cli/root/pattern/import.go +++ b/mesheryctl/internal/cli/root/pattern/import.go @@ -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: ` @@ -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 { diff --git a/mesheryctl/internal/cli/root/pattern/import_test.go b/mesheryctl/internal/cli/root/pattern/import_test.go new file mode 100644 index 00000000000..4fcf9da19a0 --- /dev/null +++ b/mesheryctl/internal/cli/root/pattern/import_test.go @@ -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 + } + }) + } +}