1
0
mirror of https://github.com/google/gops.git synced 2024-11-24 08:22:25 +02:00
gops/internal/cmd/shared_test.go
Glib Smaga 9069aa4d19 Migrate gops to use spf13/cobra for command execution
Manual command setup was starting to show some strain in
terms of documentation and also adding new features
(regardless of what the protocol supports currently).

This new setup aims to make it easier to add new
documentation and functionality.

In comparison to the previous version, this increased the
binary size by 2.4M.
```
6.4M gops
4.0M gops_master
```
2022-08-30 14:31:29 +02:00

40 lines
934 B
Go

// Copyright 2022 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package cmd
import (
"bytes"
"strings"
"testing"
"github.com/spf13/cobra"
)
func TestCommandPresence(t *testing.T) {
cmd := &cobra.Command{Use: "gops"}
cmd.AddCommand(AgentCommands()...)
var out bytes.Buffer
cmd.SetOut(&out)
cmd.SetArgs([]string{"--help"})
if err := cmd.Execute(); err != nil {
t.Error(err)
}
// basic check to make sure all the legacy commands have been ported over
// it doesn't test they are correctly _implemented_, just that they are not
// missing.
wants := []string{
"completion", "gc", "memstats", "pprof-cpu", "pprof-heap", "setgc",
"stack", "stats", "trace", "version",
}
outs := out.String()
for _, want := range wants {
if !strings.Contains(outs, want) {
t.Errorf("%q command not found in help", want)
}
}
}