This is an automated email from the ASF dual-hosted git repository.

nferraro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 430ba1b6d9eced7ae2be9f3550bcc4753b7c3e28
Author: Doru Bercea <[email protected]>
AuthorDate: Tue Nov 10 16:41:15 2020 -0500

    Add test for property-file and dependency flags for local-run.
---
 pkg/cmd/local_run.go      |  6 ++--
 pkg/cmd/local_run_test.go | 76 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 79 insertions(+), 3 deletions(-)

diff --git a/pkg/cmd/local_run.go b/pkg/cmd/local_run.go
index 5959a8e..654ffce 100644
--- a/pkg/cmd/local_run.go
+++ b/pkg/cmd/local_run.go
@@ -65,7 +65,7 @@ where <type> is one of 
{`+strings.Join(acceptedDependencyTypes, "|")+`}.`)
 
 type localRunCmdOptions struct {
        *RootCmdOptions
-       PropertiesFiles        []string `mapstructure:"property-files"`
+       PropertyFiles          []string `mapstructure:"property-files"`
        AdditionalDependencies []string `mapstructure:"dependencies"`
 }
 
@@ -77,7 +77,7 @@ func (command *localRunCmdOptions) validate(args []string) 
error {
        }
 
        // Validate properties file.
-       err = validateFiles(command.PropertiesFiles)
+       err = validateFiles(command.PropertyFiles)
        if err != nil {
                return nil
        }
@@ -103,7 +103,7 @@ func (command *localRunCmdOptions) run(args []string) error 
{
        }
 
        // Run the integration locally.
-       err = RunLocalIntegration(command.PropertiesFiles, dependencies, args)
+       err = RunLocalIntegration(command.PropertyFiles, dependencies, args)
        if err != nil {
                return nil
        }
diff --git a/pkg/cmd/local_run_test.go b/pkg/cmd/local_run_test.go
new file mode 100644
index 0000000..2858021
--- /dev/null
+++ b/pkg/cmd/local_run_test.go
@@ -0,0 +1,76 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package cmd
+
+import (
+       "testing"
+
+       "github.com/apache/camel-k/pkg/util/test"
+       "github.com/spf13/cobra"
+)
+
+func addTestLocalRunCmd(options *RootCmdOptions, rootCmd *cobra.Command) 
*localRunCmdOptions {
+       //add a testing version of run Command
+       localRunCmd, localRunCmdOptions := newCmdLocalRun(options)
+       localRunCmd.RunE = func(c *cobra.Command, args []string) error {
+               return nil
+       }
+       localRunCmd.Args = test.ArbitraryArgs
+       rootCmd.AddCommand(localRunCmd)
+       return localRunCmdOptions
+}
+
+func TestLocalRunPropertyFileFlag(t *testing.T) {
+       options, rootCmd := kamelTestPreAddCommandInit()
+
+       localRunCmdOptions := addTestLocalRunCmd(options, rootCmd)
+
+       kamelTestPostAddCommandInit(t, rootCmd)
+
+       _, err := test.ExecuteCommand(rootCmd, "local-run", "route.java", 
"--property-file", "file1.properties", "--property-file", "file2.properties")
+       if err != nil {
+               t.Fatalf("Unexpected error: %v", err)
+       }
+
+       if len(localRunCmdOptions.PropertyFiles) != 2 {
+               t.Fatalf("Property files expected to contain: \n %v 
elements\nGot:\n %v elements\n", 2, len(localRunCmdOptions.PropertyFiles))
+       }
+       if localRunCmdOptions.PropertyFiles[0] != "file1.properties" || 
localRunCmdOptions.PropertyFiles[1] != "file2.properties" {
+               t.Fatalf("Property files expected to be: \n %v\nGot:\n %v\n", 
"[file1.properties, file2.properties]", localRunCmdOptions.PropertyFiles)
+       }
+}
+
+func TestLocalRunAdditionalDependenciesFlag(t *testing.T) {
+       options, rootCmd := kamelTestPreAddCommandInit()
+
+       localRunCmdOptions := addTestLocalRunCmd(options, rootCmd)
+
+       kamelTestPostAddCommandInit(t, rootCmd)
+
+       _, err := test.ExecuteCommand(rootCmd, "local-run", "route.java", "-d", 
"mvn:camel-component-1", "-d", "mvn:camel-component-2")
+       if err != nil {
+               t.Fatalf("Unexpected error: %v", err)
+       }
+
+       if len(localRunCmdOptions.AdditionalDependencies) != 2 {
+               t.Fatalf("Additional dependencies expected to contain: \n %v 
elements\nGot:\n %v elements\n", 2, 
len(localRunCmdOptions.AdditionalDependencies))
+       }
+       if localRunCmdOptions.AdditionalDependencies[0] != 
"mvn:camel-component-1" || localRunCmdOptions.AdditionalDependencies[1] != 
"mvn:camel-component-2" {
+               t.Fatalf("Additional dependencies expected to be: \n %v\nGot:\n 
%v\n", "[mvn:camel-component-1, mvn:camel-component-2]", 
localRunCmdOptions.AdditionalDependencies)
+       }
+}

Reply via email to