mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-11-01 06:10:17 +00:00
remove unused func deprecatedAlias
This commit is contained in:
@@ -17,16 +17,12 @@ limitations under the License.
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
||||
)
|
||||
@@ -57,56 +53,6 @@ func TestNormalizationFuncGlobalExistence(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func Test_deprecatedAlias(t *testing.T) {
|
||||
var correctCommandCalled bool
|
||||
makeCobraCommand := func() *cobra.Command {
|
||||
cobraCmd := new(cobra.Command)
|
||||
cobraCmd.Use = "print five lines"
|
||||
cobraCmd.Run = func(*cobra.Command, []string) {
|
||||
correctCommandCalled = true
|
||||
}
|
||||
return cobraCmd
|
||||
}
|
||||
|
||||
original := makeCobraCommand()
|
||||
alias := deprecatedAlias("echo", makeCobraCommand())
|
||||
|
||||
if len(alias.Deprecated) == 0 {
|
||||
t.Error("deprecatedAlias should always have a non-empty .Deprecated")
|
||||
}
|
||||
if !strings.Contains(alias.Deprecated, "print") {
|
||||
t.Error("deprecatedAlias should give the name of the new function in its .Deprecated field")
|
||||
}
|
||||
if !alias.Hidden {
|
||||
t.Error("deprecatedAlias should never have .Hidden == false (deprecated aliases should be hidden)")
|
||||
}
|
||||
|
||||
if alias.Name() != "echo" {
|
||||
t.Errorf("deprecatedAlias has name %q, expected %q",
|
||||
alias.Name(), "echo")
|
||||
}
|
||||
if original.Name() != "print" {
|
||||
t.Errorf("original command has name %q, expected %q",
|
||||
original.Name(), "print")
|
||||
}
|
||||
|
||||
buffer := new(bytes.Buffer)
|
||||
alias.SetOutput(buffer)
|
||||
alias.Execute()
|
||||
str := buffer.String()
|
||||
if !strings.Contains(str, "deprecated") || !strings.Contains(str, "print") {
|
||||
t.Errorf("deprecation warning %q does not include enough information", str)
|
||||
}
|
||||
|
||||
// It would be nice to test to see that original.Run == alias.Run
|
||||
// Unfortunately Golang does not allow comparing functions. I could do
|
||||
// this with reflect, but that's technically invoking undefined
|
||||
// behavior. Best we can do is make sure that the function is called.
|
||||
if !correctCommandCalled {
|
||||
t.Errorf("original function doesn't appear to have been called by alias")
|
||||
}
|
||||
}
|
||||
|
||||
func TestKubectlCommandHandlesPlugins(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
Reference in New Issue
Block a user