diff --git a/pkg/commands/env_test.go b/pkg/commands/env_test.go index 89ace81c9..9dc5859e7 100644 --- a/pkg/commands/env_test.go +++ b/pkg/commands/env_test.go @@ -8,16 +8,13 @@ import ( "testing" "github.com/crossplane/crossplane-runtime/pkg/test" - - "github.com/oam-dev/kubevela/pkg/utils/env" - - "github.com/oam-dev/kubevela/apis/types" - - "github.com/oam-dev/kubevela/pkg/utils/system" - + "github.com/spf13/cobra" "github.com/stretchr/testify/assert" + "github.com/oam-dev/kubevela/apis/types" cmdutil "github.com/oam-dev/kubevela/pkg/commands/util" + "github.com/oam-dev/kubevela/pkg/utils/env" + "github.com/oam-dev/kubevela/pkg/utils/system" ) func TestENV(t *testing.T) { @@ -101,3 +98,10 @@ func TestENV(t *testing.T) { err = SetEnv([]string{"default"}, ioStream) assert.NoError(t, err) } + +func TestEnvInitCommandPersistentPreRunE(t *testing.T) { + io := cmdutil.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr} + fakeC := types.Args{} + cmd := NewEnvInitCommand(fakeC, io) + assert.Nil(t, cmd.PersistentPreRunE(new(cobra.Command), []string{})) +} diff --git a/pkg/commands/exec_test.go b/pkg/commands/exec_test.go index 72e182155..c940589a3 100644 --- a/pkg/commands/exec_test.go +++ b/pkg/commands/exec_test.go @@ -5,6 +5,7 @@ import ( "os" "testing" + "github.com/spf13/cobra" "github.com/stretchr/testify/assert" corev1 "k8s.io/api/core/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -12,12 +13,11 @@ import ( "k8s.io/kubectl/pkg/cmd/exec" cmdtesting "k8s.io/kubectl/pkg/cmd/testing" - "github.com/oam-dev/kubevela/pkg/oam" - "github.com/oam-dev/kubevela/apis/types" "github.com/oam-dev/kubevela/pkg/appfile" "github.com/oam-dev/kubevela/pkg/application" cmdutil "github.com/oam-dev/kubevela/pkg/commands/util" + "github.com/oam-dev/kubevela/pkg/oam" ) func TestExecCommand(t *testing.T) { @@ -60,3 +60,10 @@ func TestExecCommand(t *testing.T) { err = o.Complete() assert.NoError(t, err) } + +func TestExecCommandPersistentPreRunE(t *testing.T) { + io := cmdutil.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr} + fakeC := types.Args{} + cmd := NewExecCommand(fakeC, io) + assert.Nil(t, cmd.PersistentPreRunE(new(cobra.Command), []string{})) +} diff --git a/pkg/commands/portforward_test.go b/pkg/commands/portforward_test.go index 61c50a31c..42cb0f8ac 100644 --- a/pkg/commands/portforward_test.go +++ b/pkg/commands/portforward_test.go @@ -5,6 +5,7 @@ import ( "os" "testing" + "github.com/spf13/cobra" "github.com/stretchr/testify/assert" corev1 "k8s.io/api/core/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -12,10 +13,9 @@ import ( "k8s.io/kubectl/pkg/cmd/portforward" cmdtesting "k8s.io/kubectl/pkg/cmd/testing" - "github.com/oam-dev/kubevela/pkg/oam" - "github.com/oam-dev/kubevela/apis/types" cmdutil "github.com/oam-dev/kubevela/pkg/commands/util" + "github.com/oam-dev/kubevela/pkg/oam" ) func TestPortForwardCommand(t *testing.T) { @@ -51,3 +51,10 @@ func TestPortForwardCommand(t *testing.T) { err := o.Init(context.Background(), cmd, []string{"fakeApp", "8081:8080"}) assert.NoError(t, err) } + +func TestNewPortForwardCommandPersistentPreRunE(t *testing.T) { + io := cmdutil.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr} + fakeC := types.Args{} + cmd := NewPortForwardCommand(fakeC, io) + assert.Nil(t, cmd.PersistentPreRunE(new(cobra.Command), []string{})) +} diff --git a/pkg/commands/traits_test.go b/pkg/commands/traits_test.go index 3a902957c..eee34b8b6 100644 --- a/pkg/commands/traits_test.go +++ b/pkg/commands/traits_test.go @@ -2,11 +2,12 @@ package commands import ( "bytes" + "os" "testing" - "github.com/stretchr/testify/assert" - "github.com/gosuri/uitable" + "github.com/spf13/cobra" + "github.com/stretchr/testify/assert" "github.com/oam-dev/kubevela/apis/types" cmdutil "github.com/oam-dev/kubevela/pkg/commands/util" @@ -90,3 +91,10 @@ func Test_printTraitList(t *testing.T) { assert.NoError(t, printTraitList(&nn, iostream)) } } + +func TestNewTraitsCommandPersistentPreRunE(t *testing.T) { + io := cmdutil.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr} + fakeC := types.Args{} + cmd := NewTraitsCommand(fakeC, io) + assert.Nil(t, cmd.PersistentPreRunE(new(cobra.Command), []string{})) +} diff --git a/pkg/commands/up.go b/pkg/commands/up.go index a014d0577..8325e6180 100644 --- a/pkg/commands/up.go +++ b/pkg/commands/up.go @@ -9,8 +9,6 @@ import ( "path/filepath" "strings" - "github.com/oam-dev/kubevela/pkg/utils/common" - "github.com/pkg/errors" "github.com/spf13/cobra" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -26,6 +24,7 @@ import ( "github.com/oam-dev/kubevela/pkg/application" cmdutil "github.com/oam-dev/kubevela/pkg/commands/util" "github.com/oam-dev/kubevela/pkg/oam" + "github.com/oam-dev/kubevela/pkg/utils/common" ) var ( diff --git a/pkg/commands/up_test.go b/pkg/commands/up_test.go index 593fa23c7..fd7cfc69f 100644 --- a/pkg/commands/up_test.go +++ b/pkg/commands/up_test.go @@ -5,13 +5,13 @@ import ( "os" "testing" + "github.com/spf13/cobra" "github.com/stretchr/testify/assert" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes/scheme" "sigs.k8s.io/controller-runtime/pkg/client/fake" "github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha2" - "github.com/oam-dev/kubevela/apis/types" "github.com/oam-dev/kubevela/pkg/commands/util" ) @@ -39,3 +39,10 @@ func TestUp(t *testing.T) { assert.Contains(t, msg, "App has been deployed") assert.Contains(t, msg, fmt.Sprintf("App status: vela status %s", appName)) } + +func TestNewUpCommandPersistentPreRunE(t *testing.T) { + io := util.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr} + fakeC := types.Args{} + cmd := NewUpCommand(fakeC, io) + assert.Nil(t, cmd.PersistentPreRunE(new(cobra.Command), []string{})) +}