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 6, 2020
1 parent 429f3b0 commit 95aa284
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 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
27 changes: 27 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 @@ -79,8 +80,16 @@ func TestKnAdminPlugin(t *testing.T) {
err = e2eTest.restoreConfigMap("config-domain")
assert.NilError(t, err)

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)

}

func (et *e2eTest) backupConfigMap(cm string) error {
Expand Down Expand Up @@ -124,3 +133,21 @@ func (et *e2eTest) knAdminDomain(t *testing.T, r *test.KnRunResultCollector) {
out = et.kn.Run(pluginName, "domain", "unset", "--custom-domain", domain)
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)
}

0 comments on commit 95aa284

Please sign in to comment.