diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go index 5904272ac4..695f01f049 100644 --- a/pkg/cmd/run.go +++ b/pkg/cmd/run.go @@ -380,7 +380,7 @@ func (o *runCmdOptions) syncIntegration(cmd *cobra.Command, c client.Client, sou files = append(files, o.OpenAPIs...) for _, s := range files { - if isLocal(s) { + if isLocalAndFileExists(s) { changes, err := sync.File(o.Context, s) if err != nil { return err @@ -645,7 +645,7 @@ func (*runCmdOptions) configureTraits(integration *v1.Integration, options []str return nil } -func isLocal(fileName string) bool { +func isLocalAndFileExists(fileName string) bool { info, err := os.Stat(fileName) if os.IsNotExist(err) { return false diff --git a/pkg/cmd/run_test.go b/pkg/cmd/run_test.go index 9db419392d..ce9527f30f 100644 --- a/pkg/cmd/run_test.go +++ b/pkg/cmd/run_test.go @@ -416,6 +416,23 @@ func TestRunVolumeFlagWrongPVCFormat(t *testing.T) { assert.NotNil(t, err) } +func TestRunValidateArgs(t *testing.T) { + runCmdOptions, rootCmd, _ := initializeRunCmdOptions(t) + args := []string{} + err := runCmdOptions.validateArgs(rootCmd, args) + assert.NotNil(t, err) + assert.Equal(t, "run expects at least 1 argument, received 0", err.Error()) + + args = []string{"run_test.go"} + err = runCmdOptions.validateArgs(rootCmd, args) + assert.Nil(t, err) + + args = []string{"missing_file"} + err = runCmdOptions.validateArgs(rootCmd, args) + assert.NotNil(t, err) + assert.Equal(t, "One of the provided sources is not reachable: Missing file or unsupported scheme in missing_file", err.Error()) +} + // // This test does work when running as single test but fails // otherwise as we are using a global viper instance diff --git a/pkg/cmd/util_content.go b/pkg/cmd/util_content.go index 75d9c08ef5..c210870d2c 100644 --- a/pkg/cmd/util_content.go +++ b/pkg/cmd/util_content.go @@ -30,7 +30,7 @@ func loadContent(source string, compress bool, compressBinary bool) (string, boo var content []byte var err error - if isLocal(source) { + if isLocalAndFileExists(source) { content, err = ioutil.ReadFile(source) } else { u, err := url.Parse(source) diff --git a/pkg/cmd/util_sources.go b/pkg/cmd/util_sources.go index 50a0838593..f53970527c 100644 --- a/pkg/cmd/util_sources.go +++ b/pkg/cmd/util_sources.go @@ -65,7 +65,7 @@ func ResolveSources(ctx context.Context, locations []string, compress bool) ([]S sources := make([]Source, 0, len(locations)) for _, location := range locations { - if isLocal(location) { + if isLocalAndFileExists(location) { answer, err := ResolveLocalSource(location, compress) if err != nil { return sources, err @@ -176,6 +176,8 @@ func ResolveSources(ctx context.Context, locations []string, compress bool) ([]S return sources, err } sources = append(sources, answer) + default: + return sources, fmt.Errorf("Missing file or unsupported scheme in %s", location) } } }