Skip to content

Commit

Permalink
Add a test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Miles-Garnsey committed Jul 15, 2024
1 parent 02ed208 commit 22c337c
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions cmd/kubectl-k8ssandra/register/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import (
"time"

configapi "github.com/k8ssandra/k8ssandra-operator/apis/config/v1beta1"
"github.com/spf13/cobra"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/cli-runtime/pkg/genericiooptions"
"k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -138,3 +140,39 @@ func ClientConfigFromSecret(s *corev1.Secret) (clientcmdapi.Config, error) {
}
return *out, nil
}

func TestInputParameters(t *testing.T) {
require := require.New(t)

RegisterClusterCmd.RunE = func(cmd *cobra.Command, args []string) error {
return nil
}
cmd := &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
return nil
},
}
SetupRegisterClusterCmd(cmd, genericiooptions.NewTestIOStreamsDiscard())
RegisterClusterCmd.SetArgs([]string{
"register",
"--source-context", "source-ctx",
"--source-kubeconfig", "testsourcekubeconfig",
"dest-kubeconfig", "testdestkubeconfig",
"--dest-context", "dest-ctx",
"--source-namespace", "source-namespace",
"--source-namespace", "dest-namespace",
"--service-account", "test-sa",
"--override-src-ip", "127.0.0.2",
"--override-src-port", "9999"})
executor := NewRegistrationExecutorFromRegisterClusterCmd(*RegisterClusterCmd)
require.NoError(RegisterClusterCmd.Execute())
require.Equal("127.0.0.2", executor.OverrideSourceIP)
require.Equal("9999", executor.OverrideSourcePort)
require.Equal("testsourcekubeconfig", executor.SourceKubeconfig)
require.Equal("source-ctx", executor.SourceContext)
require.Equal("testdestkubeconfig", executor.DestKubeconfig)
require.Equal("dest-ctx", executor.DestContext)
require.Equal("source-namespace", executor.SourceNamespace)
require.Equal("dest-namespace", executor.DestNamespace)
require.Equal("test-sa", executor.ServiceAccount)
}

0 comments on commit 22c337c

Please sign in to comment.