Skip to content
This repository has been archived by the owner on Mar 9, 2021. It is now read-only.

Commit

Permalink
add e2e to profiling subcommand
Browse files Browse the repository at this point in the history
Signed-off-by: Lance Liu <[email protected]>
  • Loading branch information
Lance Liu committed Aug 17, 2020
1 parent 12c6882 commit 5be890a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
4 changes: 2 additions & 2 deletions plugins/admin/core/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (

var cfgFile string

// rootCmd represents the base command when called without any subcommands
// NewAdminCommand represents the base command when called without any subcommands
func NewAdminCommand(params ...pkg.AdminParams) *cobra.Command {
p := &pkg.AdminParams{}
p.Initialize()
Expand All @@ -47,7 +47,7 @@ func NewAdminCommand(params ...pkg.AdminParams) *cobra.Command {
cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.config/kn/plugins/admin.yaml)")
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")

rootCmd.SetOut(os.Stdout)
rootCmd.AddCommand(domain.NewDomainCmd(p))
rootCmd.AddCommand(private_registry.NewPrivateRegistryCmd(p))
rootCmd.AddCommand(autoscaling.NewAutoscalingCmd(p))
Expand Down
26 changes: 26 additions & 0 deletions plugins/admin/test/e2e/kn_admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"

testcommon "github.com/maximilien/kn-source-pkg/test/e2e"
Expand Down Expand Up @@ -81,6 +82,13 @@ func TestKnAdminPlugin(t *testing.T) {

t.Log("test kn admin registry subcommand")
e2eTest.knAdminRegistry(t, r)
err = e2eTest.backupConfigMap("config-observability")
assert.NilError(t, err)

t.Log("test kn admin profiling subcommand")
e2eTest.knAdminProfiling(t, r)
err = e2eTest.restoreConfigMap("config-observability")
assert.NilError(t, err)

err = e2eTest.it.KnPlugin().Uninstall()
assert.NilError(t, err)
Expand Down Expand Up @@ -134,3 +142,21 @@ func (et *e2eTest) knAdminRegistry(t *testing.T, r *test.KnRunResultCollector) {
out = et.kn.Run(pluginName, "registry", "remove", "--username", "custom-user", "--server", "dummy.test.io")
r.AssertNoError(out)
}

func (et *e2eTest) knAdminProfiling(t *testing.T, r *test.KnRunResultCollector) {
out := et.kn.Run(pluginName, "profiling", "--enable")
r.AssertNoError(out)
assert.Equal(t, "Knative Serving profiling is enabled\n", out.Stdout)

out = et.kn.Run(pluginName, "profiling", "--heap", "--target", "controller")
r.AssertNoError(out)
assert.Check(t, strings.Contains(out.Stdout, "Saving heap profiling data to"))

out = et.kn.Run(pluginName, "profiling", "--cpu", "5s", "--target", "controller")
r.AssertNoError(out)
assert.Check(t, strings.Contains(out.Stdout, "Saving 5 second(s) cpu profiling data to"))

out = et.kn.Run(pluginName, "profiling", "--disable")
r.AssertNoError(out)
assert.Equal(t, "Knative Serving profiling is disabled\n", out.Stdout)
}
9 changes: 8 additions & 1 deletion plugins/admin/vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ github.com/spf13/afero
github.com/spf13/afero/mem
# github.com/spf13/cast v1.3.0
github.com/spf13/cast
# github.com/spf13/cobra v0.0.5
# github.com/spf13/cobra v0.0.6
## explicit
github.com/spf13/cobra
# github.com/spf13/jwalterweatherman v1.0.0
Expand Down Expand Up @@ -201,6 +201,7 @@ k8s.io/api/storage/v1alpha1
k8s.io/api/storage/v1beta1
# k8s.io/apimachinery v0.17.4
## explicit
k8s.io/apimachinery/pkg/api/apitesting/fuzzer
k8s.io/apimachinery/pkg/api/equality
k8s.io/apimachinery/pkg/api/errors
k8s.io/apimachinery/pkg/api/meta
Expand Down Expand Up @@ -451,6 +452,7 @@ k8s.io/client-go/tools/clientcmd/api
k8s.io/client-go/tools/clientcmd/api/latest
k8s.io/client-go/tools/clientcmd/api/v1
k8s.io/client-go/tools/metrics
k8s.io/client-go/tools/pager
k8s.io/client-go/tools/portforward
k8s.io/client-go/tools/reference
k8s.io/client-go/transport
Expand All @@ -472,6 +474,11 @@ k8s.io/utils/integer
k8s.io/utils/trace
# knative.dev/client v0.14.0
## explicit
knative.dev/client/lib/test
knative.dev/client/pkg/dynamic
knative.dev/client/pkg/errors
knative.dev/client/pkg/eventing/v1alpha1
knative.dev/client/pkg/kn/commands
knative.dev/client/pkg/kn/flags
knative.dev/client/pkg/printers
knative.dev/client/pkg/serving
Expand Down

0 comments on commit 5be890a

Please sign in to comment.