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:07 UTC
[camel-k] 07/10: fixed linter reported issues.
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 e223276c1158a517f284fb8644763e22d7b5463f
Author: Andrea Tarocchi <an...@gmail.com>
AuthorDate: Mon Dec 16 12:08:17 2019 +0100
fixed linter reported issues.
---
pkg/cmd/builder_test.go | 1 +
pkg/cmd/delete_test.go | 1 +
pkg/cmd/install_test.go | 4 +++-
pkg/cmd/kit_create_test.go | 1 +
pkg/cmd/kit_test.go | 1 +
pkg/cmd/root_test.go | 23 ++++++++++++++++-------
pkg/cmd/run_test.go | 3 ++-
pkg/util/test/cmd.go | 1 +
8 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/pkg/cmd/builder_test.go b/pkg/cmd/builder_test.go
index 080f565..a757dbf 100644
--- a/pkg/cmd/builder_test.go
+++ b/pkg/cmd/builder_test.go
@@ -22,6 +22,7 @@ import (
"github.com/spf13/cobra"
)
+//nolint:deadcode,unused
func addTestBuilderCmd(options RootCmdOptions, rootCmd *cobra.Command) *builderCmdOptions {
//add a testing version of builder Command
builderCmd, builderCmdOptions := newCmdBuilder(&options)
diff --git a/pkg/cmd/delete_test.go b/pkg/cmd/delete_test.go
index 0c8e317..b66604c 100644
--- a/pkg/cmd/delete_test.go
+++ b/pkg/cmd/delete_test.go
@@ -22,6 +22,7 @@ import (
"github.com/spf13/cobra"
)
+//nolint:deadcode,unused
func addTestDeleteCmd(options RootCmdOptions, rootCmd *cobra.Command) *deleteCmdOptions {
//add a testing version of delete Command
deleteCmd, deleteCmdOptions := newCmdDelete(&options)
diff --git a/pkg/cmd/install_test.go b/pkg/cmd/install_test.go
index 8136a59..bf8b58d 100644
--- a/pkg/cmd/install_test.go
+++ b/pkg/cmd/install_test.go
@@ -18,15 +18,17 @@ limitations under the License.
package cmd
import (
+ "testing"
+
"github.com/apache/camel-k/pkg/util/test"
"github.com/spf13/cobra"
- "testing"
"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
"github.com/stretchr/testify/assert"
)
+//nolint:deadcode,unused
func addTestInstallCmd(options RootCmdOptions, rootCmd *cobra.Command) *installCmdOptions {
//add a testing version of install Command
installCmd, installOptions := newCmdInstall(&options)
diff --git a/pkg/cmd/kit_create_test.go b/pkg/cmd/kit_create_test.go
index 88686f3..baa965f 100644
--- a/pkg/cmd/kit_create_test.go
+++ b/pkg/cmd/kit_create_test.go
@@ -22,6 +22,7 @@ import (
"github.com/spf13/cobra"
)
+//nolint:deadcode,unused
func addTestKitCreateCmd(options RootCmdOptions, rootCmd *cobra.Command) *kitCreateCommandOptions {
//add a testing version of kitCreate Command
kitCreateCmd, kitCreateCmdOptions := newKitCreateCmd(&options)
diff --git a/pkg/cmd/kit_test.go b/pkg/cmd/kit_test.go
index c1367f7..ee4d61f 100644
--- a/pkg/cmd/kit_test.go
+++ b/pkg/cmd/kit_test.go
@@ -21,6 +21,7 @@ import (
"github.com/spf13/cobra"
)
+//nolint:deadcode,unused
func newTestCmdKit(options *RootCmdOptions) *cobra.Command {
//add a testing version of kit Command
kitCmd := newCmdKit(options)
diff --git a/pkg/cmd/root_test.go b/pkg/cmd/root_test.go
index 0bbad46..50e0293 100644
--- a/pkg/cmd/root_test.go
+++ b/pkg/cmd/root_test.go
@@ -20,11 +20,12 @@ package cmd
import (
"bytes"
"context"
+ "os"
+ "testing"
+
"github.com/apache/camel-k/pkg/util/test"
"github.com/spf13/cobra"
"github.com/spf13/viper"
- "os"
- "testing"
)
func kamelTestPostAddCommandInit(rootCmd *cobra.Command) *cobra.Command {
@@ -48,7 +49,8 @@ func TestLoadFromCommandLine(t *testing.T) {
rootCmd = kamelTestPostAddCommandInit(rootCmd)
- _, err := test.ExecuteCommand(rootCmd, "run", "route.java", "--env", "VAR1=value,othervalue", "--env", "VAR2=value2")
+ const VAR2 = "VAR2=value2"
+ _, err := test.ExecuteCommand(rootCmd, "run", "route.java", "--env", "VAR1=value,othervalue", "--env", VAR2)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
@@ -56,7 +58,7 @@ func TestLoadFromCommandLine(t *testing.T) {
if len(runCmdOptions.EnvVars) != 2 {
t.Errorf("Properties expected to contain: \n %v elements\nGot:\n %v elemtns\n", 2, len(runCmdOptions.EnvVars))
}
- if runCmdOptions.EnvVars[0] != "VAR1=value,othervalue" || runCmdOptions.EnvVars[1] != "VAR2=value2" {
+ if runCmdOptions.EnvVars[0] != "VAR1=value,othervalue" || runCmdOptions.EnvVars[1] != VAR2 {
t.Errorf("EnvVars expected to be: \n %v\nGot:\n %v\n", "[VAR1=value,othervalue VAR=value2]", runCmdOptions.EnvVars)
}
}
@@ -88,7 +90,7 @@ func TestLoadFromFile(t *testing.T) {
//shows how to include a "," character inside a property value see VAR1 value
var propertiesFile = []byte(`kamel.run.envs: "VAR1=value,""othervalue""",VAR2=value2`)
viper.SetConfigType("properties")
- viper.ReadConfig(bytes.NewReader(propertiesFile))
+ readViperConfigFromBytes(propertiesFile, t)
options, rootCmd := kamelTestPreAddCommandInit()
runCmdOptions := addTestRunCmd(options, rootCmd)
@@ -112,7 +114,7 @@ func TestPrecedenceEnvVarOverFile(t *testing.T) {
os.Setenv("KAMEL_RUN_ENVS", "VAR1=envVar")
var propertiesFile = []byte(`kamel.run.envs: VAR2=file`)
viper.SetConfigType("properties")
- viper.ReadConfig(bytes.NewReader(propertiesFile))
+ readViperConfigFromBytes(propertiesFile, t)
options, rootCmd := kamelTestPreAddCommandInit()
runCmdOptions := addTestRunCmd(options, rootCmd)
@@ -136,7 +138,7 @@ func TestPrecedenceCommandLineOverEverythingElse(t *testing.T) {
os.Setenv("KAMEL_RUN_ENVS", "VAR1=envVar")
var propertiesFile = []byte(`kamel.run.envs: VAR2=file`)
viper.SetConfigType("properties")
- viper.ReadConfig(bytes.NewReader(propertiesFile))
+ readViperConfigFromBytes(propertiesFile, t)
options, rootCmd := kamelTestPreAddCommandInit()
runCmdOptions := addTestRunCmd(options, rootCmd)
@@ -155,3 +157,10 @@ func TestPrecedenceCommandLineOverEverythingElse(t *testing.T) {
t.Fatalf("EnvVars expected to be: \n %v\nGot:\n %v\n", "VAR3=commandLine", runCmdOptions.EnvVars)
}
}
+
+func readViperConfigFromBytes(propertiesFile []byte, t *testing.T) {
+ unexpectedErr := viper.ReadConfig(bytes.NewReader(propertiesFile))
+ if unexpectedErr != nil {
+ t.Fatalf("Unexpected error: %v", unexpectedErr)
+ }
+}
diff --git a/pkg/cmd/run_test.go b/pkg/cmd/run_test.go
index 4509006..f33fbee 100644
--- a/pkg/cmd/run_test.go
+++ b/pkg/cmd/run_test.go
@@ -18,9 +18,10 @@ limitations under the License.
package cmd
import (
+ "testing"
+
"github.com/apache/camel-k/pkg/util/test"
"github.com/spf13/cobra"
- "testing"
)
func addTestRunCmd(options RootCmdOptions, rootCmd *cobra.Command) *runCmdOptions {
diff --git a/pkg/util/test/cmd.go b/pkg/util/test/cmd.go
index 4988d78..7d7f003 100644
--- a/pkg/util/test/cmd.go
+++ b/pkg/util/test/cmd.go
@@ -19,6 +19,7 @@ package test
import (
"bytes"
+
"github.com/spf13/cobra"
)