You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2019/12/18 10:30:05 UTC

[camel-k] 05/10: Added run_test.go to test runCmd flags and blueprinted other major commands tests.

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

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

commit ac5919d467c72ca2161a9632cf6544974bbf628e
Author: Andrea Tarocchi <an...@gmail.com>
AuthorDate: Mon Dec 16 01:34:26 2019 +0100

    Added run_test.go to test runCmd flags and blueprinted other major commands tests.
---
 pkg/cmd/{run_test.go => builder_test.go}    | 16 +++++++++-------
 pkg/cmd/{run_test.go => delete_test.go}     | 16 +++++++++-------
 pkg/cmd/install_test.go                     | 15 +++++++++++++++
 pkg/cmd/{run_test.go => kit_create_test.go} | 18 +++++++++++-------
 pkg/cmd/{run_test.go => kit_test.go}        | 16 ++++++----------
 pkg/cmd/run_test.go                         | 21 +++++++++++++++++++++
 6 files changed, 71 insertions(+), 31 deletions(-)

diff --git a/pkg/cmd/run_test.go b/pkg/cmd/builder_test.go
similarity index 67%
copy from pkg/cmd/run_test.go
copy to pkg/cmd/builder_test.go
index bd32ed4..080f565 100644
--- a/pkg/cmd/run_test.go
+++ b/pkg/cmd/builder_test.go
@@ -22,13 +22,15 @@ import (
 	"github.com/spf13/cobra"
 )
 
-func addTestRunCmd(options RootCmdOptions, rootCmd *cobra.Command) *runCmdOptions {
-	//add a testing version of run Command
-	runCmd, runCmdOptions := newCmdRun(&options)
-	runCmd.RunE = func(c *cobra.Command, args []string) error {
+func addTestBuilderCmd(options RootCmdOptions, rootCmd *cobra.Command) *builderCmdOptions {
+	//add a testing version of builder Command
+	builderCmd, builderCmdOptions := newCmdBuilder(&options)
+	builderCmd.RunE = func(c *cobra.Command, args []string) error {
 		return nil
 	}
-	runCmd.Args = test.ArbitraryArgs
-	rootCmd.AddCommand(runCmd)
-	return runCmdOptions
+	builderCmd.Args = test.ArbitraryArgs
+	rootCmd.AddCommand(builderCmd)
+	return builderCmdOptions
 }
+
+//TODO: add a proper test, take inspiration by run_test.go
diff --git a/pkg/cmd/run_test.go b/pkg/cmd/delete_test.go
similarity index 68%
copy from pkg/cmd/run_test.go
copy to pkg/cmd/delete_test.go
index bd32ed4..0c8e317 100644
--- a/pkg/cmd/run_test.go
+++ b/pkg/cmd/delete_test.go
@@ -22,13 +22,15 @@ import (
 	"github.com/spf13/cobra"
 )
 
-func addTestRunCmd(options RootCmdOptions, rootCmd *cobra.Command) *runCmdOptions {
-	//add a testing version of run Command
-	runCmd, runCmdOptions := newCmdRun(&options)
-	runCmd.RunE = func(c *cobra.Command, args []string) error {
+func addTestDeleteCmd(options RootCmdOptions, rootCmd *cobra.Command) *deleteCmdOptions {
+	//add a testing version of delete Command
+	deleteCmd, deleteCmdOptions := newCmdDelete(&options)
+	deleteCmd.RunE = func(c *cobra.Command, args []string) error {
 		return nil
 	}
-	runCmd.Args = test.ArbitraryArgs
-	rootCmd.AddCommand(runCmd)
-	return runCmdOptions
+	deleteCmd.Args = test.ArbitraryArgs
+	rootCmd.AddCommand(deleteCmd)
+	return deleteCmdOptions
 }
+
+//TODO: add a proper test, take inspiration by run_test.go
diff --git a/pkg/cmd/install_test.go b/pkg/cmd/install_test.go
index 27a8473..8136a59 100644
--- a/pkg/cmd/install_test.go
+++ b/pkg/cmd/install_test.go
@@ -18,6 +18,8 @@ limitations under the License.
 package cmd
 
 import (
+	"github.com/apache/camel-k/pkg/util/test"
+	"github.com/spf13/cobra"
 	"testing"
 
 	"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
@@ -25,6 +27,19 @@ import (
 	"github.com/stretchr/testify/assert"
 )
 
+func addTestInstallCmd(options RootCmdOptions, rootCmd *cobra.Command) *installCmdOptions {
+	//add a testing version of install Command
+	installCmd, installOptions := newCmdInstall(&options)
+	installCmd.RunE = func(c *cobra.Command, args []string) error {
+		return nil
+	}
+	installCmd.Args = test.ArbitraryArgs
+	rootCmd.AddCommand(installCmd)
+	return installOptions
+}
+
+//TODO: add a proper command flags test, take inspiration by run_test.go
+
 func TestDecodeMavenSettings(t *testing.T) {
 	var err error
 	var val v1alpha1.ValueSource
diff --git a/pkg/cmd/run_test.go b/pkg/cmd/kit_create_test.go
similarity index 63%
copy from pkg/cmd/run_test.go
copy to pkg/cmd/kit_create_test.go
index bd32ed4..88686f3 100644
--- a/pkg/cmd/run_test.go
+++ b/pkg/cmd/kit_create_test.go
@@ -22,13 +22,17 @@ import (
 	"github.com/spf13/cobra"
 )
 
-func addTestRunCmd(options RootCmdOptions, rootCmd *cobra.Command) *runCmdOptions {
-	//add a testing version of run Command
-	runCmd, runCmdOptions := newCmdRun(&options)
-	runCmd.RunE = func(c *cobra.Command, args []string) error {
+func addTestKitCreateCmd(options RootCmdOptions, rootCmd *cobra.Command) *kitCreateCommandOptions {
+	//add a testing version of kitCreate Command
+	kitCreateCmd, kitCreateCmdOptions := newKitCreateCmd(&options)
+	kitCreateCmd.RunE = func(c *cobra.Command, args []string) error {
 		return nil
 	}
-	runCmd.Args = test.ArbitraryArgs
-	rootCmd.AddCommand(runCmd)
-	return runCmdOptions
+	kitCreateCmd.Args = test.ArbitraryArgs
+	kitCmd := newTestCmdKit(&options)
+	kitCmd.AddCommand(kitCreateCmd)
+	rootCmd.AddCommand(kitCmd)
+	return kitCreateCmdOptions
 }
+
+//TODO: add a proper test, take inspiration by run_test.go
diff --git a/pkg/cmd/run_test.go b/pkg/cmd/kit_test.go
similarity index 68%
copy from pkg/cmd/run_test.go
copy to pkg/cmd/kit_test.go
index bd32ed4..c1367f7 100644
--- a/pkg/cmd/run_test.go
+++ b/pkg/cmd/kit_test.go
@@ -18,17 +18,13 @@ limitations under the License.
 package cmd
 
 import (
-	"github.com/apache/camel-k/pkg/util/test"
 	"github.com/spf13/cobra"
 )
 
-func addTestRunCmd(options RootCmdOptions, rootCmd *cobra.Command) *runCmdOptions {
-	//add a testing version of run Command
-	runCmd, runCmdOptions := newCmdRun(&options)
-	runCmd.RunE = func(c *cobra.Command, args []string) error {
-		return nil
-	}
-	runCmd.Args = test.ArbitraryArgs
-	rootCmd.AddCommand(runCmd)
-	return runCmdOptions
+func newTestCmdKit(options *RootCmdOptions) *cobra.Command {
+	//add a testing version of kit Command
+	kitCmd := newCmdKit(options)
+	kitCmd.ResetCommands()
+
+	return kitCmd
 }
diff --git a/pkg/cmd/run_test.go b/pkg/cmd/run_test.go
index bd32ed4..4509006 100644
--- a/pkg/cmd/run_test.go
+++ b/pkg/cmd/run_test.go
@@ -20,6 +20,7 @@ package cmd
 import (
 	"github.com/apache/camel-k/pkg/util/test"
 	"github.com/spf13/cobra"
+	"testing"
 )
 
 func addTestRunCmd(options RootCmdOptions, rootCmd *cobra.Command) *runCmdOptions {
@@ -32,3 +33,23 @@ func addTestRunCmd(options RootCmdOptions, rootCmd *cobra.Command) *runCmdOption
 	rootCmd.AddCommand(runCmd)
 	return runCmdOptions
 }
+
+func TestRunPropertyFlag(t *testing.T) {
+	options, rootCmd := kamelTestPreAddCommandInit()
+
+	runCmdOptions := addTestRunCmd(options, rootCmd)
+
+	rootCmd = kamelTestPostAddCommandInit(rootCmd)
+
+	_, err := test.ExecuteCommand(rootCmd, "run", "route.java", "--property", "key1=value,othervalue", "--property", "key2=value2")
+	if err != nil {
+		t.Fatalf("Unexpected error: %v", err)
+	}
+
+	if len(runCmdOptions.Properties) != 2 {
+		t.Fatalf("Properties expected to contain: \n %v elements\nGot:\n %v elemtns\n", 2, len(runCmdOptions.Properties))
+	}
+	if runCmdOptions.Properties[0] != "key1=value,othervalue" || runCmdOptions.Properties[1] != "key2=value2" {
+		t.Fatalf("Properties expected to be: \n %v\nGot:\n %v\n", "[key1=value,othervalue key2=value2]", runCmdOptions.Properties)
+	}
+}