You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2021/01/13 10:35:22 UTC

[camel-k] branch master updated: feat(test): operator command unit test

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


The following commit(s) were added to refs/heads/master by this push:
     new 955d73b  feat(test): operator command unit test
955d73b is described below

commit 955d73bf5ac26af9360623f6f81fb97ce8aaa9f7
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Mon Jan 11 11:39:27 2021 +0100

    feat(test): operator command unit test
    
    Added unit test for operator command flags
    
    Closes #1892
---
 pkg/cmd/operator_test.go | 80 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)

diff --git a/pkg/cmd/operator_test.go b/pkg/cmd/operator_test.go
new file mode 100644
index 0000000..fa95ebe
--- /dev/null
+++ b/pkg/cmd/operator_test.go
@@ -0,0 +1,80 @@
+/*
+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"
+
+	"github.com/stretchr/testify/assert"
+)
+
+const cmdOperator = "operator"
+
+func initializeOperatorCmdOptions(t *testing.T) (*operatorCmdOptions, *cobra.Command, RootCmdOptions) {
+	options, rootCmd := kamelTestPreAddCommandInit()
+	operatorCmdOptions := addTestOperatorCmd(*options, rootCmd)
+	kamelTestPostAddCommandInit(t, rootCmd)
+
+	return operatorCmdOptions, rootCmd, *options
+}
+
+func addTestOperatorCmd(options RootCmdOptions, rootCmd *cobra.Command) *operatorCmdOptions {
+	//add a testing version of operator Command
+	operatorCmd, operatorOptions := newCmdOperator()
+	operatorCmd.RunE = func(c *cobra.Command, args []string) error {
+		return nil
+	}
+	operatorCmd.PostRunE = func(c *cobra.Command, args []string) error {
+		return nil
+	}
+	operatorCmd.Args = test.ArbitraryArgs
+	rootCmd.AddCommand(operatorCmd)
+	return operatorOptions
+}
+
+func TestOperatorNoFlag(t *testing.T) {
+	operatorCmdOptions, rootCmd, _ := initializeOperatorCmdOptions(t)
+	_, err := test.ExecuteCommand(rootCmd, cmdOperator)
+	assert.Nil(t, err)
+	//Check default expected values
+	assert.Equal(t, int32(8081), operatorCmdOptions.HealthPort)
+	assert.Equal(t, int32(8080), operatorCmdOptions.MonitoringPort)
+}
+
+func TestOperatorNonExistingFlag(t *testing.T) {
+	_, rootCmd, _ := initializeOperatorCmdOptions(t)
+	_, err := test.ExecuteCommand(rootCmd, cmdOperator, "--nonExistingFlag")
+	assert.NotNil(t, err)
+}
+
+func TestOperatorHealthPortFlag(t *testing.T) {
+	operatorCmdOptions, rootCmd, _ := initializeOperatorCmdOptions(t)
+	_, err := test.ExecuteCommand(rootCmd, cmdOperator, "--health-port", "7171")
+	assert.Nil(t, err)
+	assert.Equal(t, int32(7171), operatorCmdOptions.HealthPort)
+}
+
+func TestOperatorMonitoringPortFlag(t *testing.T) {
+	operatorCmdOptions, rootCmd, _ := initializeOperatorCmdOptions(t)
+	_, err := test.ExecuteCommand(rootCmd, cmdOperator, "--monitoring-port", "7172")
+	assert.Nil(t, err)
+	assert.Equal(t, int32(7172), operatorCmdOptions.MonitoringPort)
+}