Merge pull request #71906 from Pingan2017/remove-deprecatedAlias

remove unused func deprecatedAlias
k3s-v1.15.3
Kubernetes Prow Robot 2019-04-25 10:18:48 -07:00 committed by GitHub
commit 7511e93371
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 0 additions and 70 deletions

View File

@ -80,7 +80,6 @@ go_test(
deps = [
"//pkg/kubectl/cmd/util:go_default_library",
"//staging/src/k8s.io/cli-runtime/pkg/genericclioptions:go_default_library",
"//vendor/github.com/spf13/cobra:go_default_library",
],
)

View File

@ -572,18 +572,3 @@ func NewKubectlCommand(in io.Reader, out, err io.Writer) *cobra.Command {
func runHelp(cmd *cobra.Command, args []string) {
cmd.Help()
}
// deprecatedAlias is intended to be used to create a "wrapper" command around
// an existing command. The wrapper works the same but prints a deprecation
// message before running. This command is identical functionality.
func deprecatedAlias(deprecatedVersion string, cmd *cobra.Command) *cobra.Command {
// Have to be careful here because Cobra automatically extracts the name
// of the command from the .Use field.
originalName := cmd.Name()
cmd.Use = deprecatedVersion
cmd.Deprecated = fmt.Sprintf("use %q instead", originalName)
cmd.Short = fmt.Sprintf("%s. This command is deprecated, use %q instead", cmd.Short, originalName)
cmd.Hidden = true
return cmd
}

View File

@ -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