|
|
|
@@ -22,20 +22,29 @@ import (
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"k8s.io/apimachinery/pkg/api/meta"
|
|
|
|
|
"k8s.io/client-go/rest/fake"
|
|
|
|
|
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
|
|
|
|
cmdtesting "k8s.io/kubernetes/pkg/kubectl/cmd/testing"
|
|
|
|
|
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
|
|
|
|
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
|
|
|
|
|
"k8s.io/kubernetes/pkg/kubectl/scheme"
|
|
|
|
|
"k8s.io/kubernetes/pkg/printers"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Verifies that schemas that are not in the master tree of Kubernetes can be retrieved via Get.
|
|
|
|
|
func TestDescribeUnknownSchemaObject(t *testing.T) {
|
|
|
|
|
d := &testDescriber{Output: "test output"}
|
|
|
|
|
oldFn := cmdutil.DescriberFn
|
|
|
|
|
defer func() {
|
|
|
|
|
cmdutil.DescriberFn = oldFn
|
|
|
|
|
}()
|
|
|
|
|
cmdutil.DescriberFn = d.describerFor
|
|
|
|
|
|
|
|
|
|
tf := cmdtesting.NewTestFactory()
|
|
|
|
|
defer tf.Cleanup()
|
|
|
|
|
_, _, codec := cmdtesting.NewExternalScheme()
|
|
|
|
|
tf.DescriberVal = d
|
|
|
|
|
|
|
|
|
|
tf.UnstructuredClient = &fake.RESTClient{
|
|
|
|
|
NegotiatedSerializer: unstructuredSerializer,
|
|
|
|
|
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, cmdtesting.NewInternalType("", "", "foo"))},
|
|
|
|
@@ -59,11 +68,16 @@ func TestDescribeUnknownSchemaObject(t *testing.T) {
|
|
|
|
|
// Verifies that schemas that are not in the master tree of Kubernetes can be retrieved via Get.
|
|
|
|
|
func TestDescribeUnknownNamespacedSchemaObject(t *testing.T) {
|
|
|
|
|
d := &testDescriber{Output: "test output"}
|
|
|
|
|
oldFn := cmdutil.DescriberFn
|
|
|
|
|
defer func() {
|
|
|
|
|
cmdutil.DescriberFn = oldFn
|
|
|
|
|
}()
|
|
|
|
|
cmdutil.DescriberFn = d.describerFor
|
|
|
|
|
|
|
|
|
|
tf := cmdtesting.NewTestFactory()
|
|
|
|
|
defer tf.Cleanup()
|
|
|
|
|
_, _, codec := cmdtesting.NewExternalScheme()
|
|
|
|
|
|
|
|
|
|
tf.DescriberVal = d
|
|
|
|
|
tf.UnstructuredClient = &fake.RESTClient{
|
|
|
|
|
NegotiatedSerializer: unstructuredSerializer,
|
|
|
|
|
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, cmdtesting.NewInternalNamespacedType("", "", "foo", "non-default"))},
|
|
|
|
@@ -85,13 +99,18 @@ func TestDescribeUnknownNamespacedSchemaObject(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestDescribeObject(t *testing.T) {
|
|
|
|
|
d := &testDescriber{Output: "test output"}
|
|
|
|
|
oldFn := cmdutil.DescriberFn
|
|
|
|
|
defer func() {
|
|
|
|
|
cmdutil.DescriberFn = oldFn
|
|
|
|
|
}()
|
|
|
|
|
cmdutil.DescriberFn = d.describerFor
|
|
|
|
|
|
|
|
|
|
_, _, rc := testData()
|
|
|
|
|
tf := cmdtesting.NewTestFactory()
|
|
|
|
|
defer tf.Cleanup()
|
|
|
|
|
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
|
|
|
|
|
|
|
|
|
|
d := &testDescriber{Output: "test output"}
|
|
|
|
|
tf.DescriberVal = d
|
|
|
|
|
tf.UnstructuredClient = &fake.RESTClient{
|
|
|
|
|
NegotiatedSerializer: unstructuredSerializer,
|
|
|
|
|
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
|
|
|
@@ -122,13 +141,18 @@ func TestDescribeObject(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestDescribeListObjects(t *testing.T) {
|
|
|
|
|
d := &testDescriber{Output: "test output"}
|
|
|
|
|
oldFn := cmdutil.DescriberFn
|
|
|
|
|
defer func() {
|
|
|
|
|
cmdutil.DescriberFn = oldFn
|
|
|
|
|
}()
|
|
|
|
|
cmdutil.DescriberFn = d.describerFor
|
|
|
|
|
|
|
|
|
|
pods, _, _ := testData()
|
|
|
|
|
tf := cmdtesting.NewTestFactory()
|
|
|
|
|
defer tf.Cleanup()
|
|
|
|
|
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
|
|
|
|
|
|
|
|
|
|
d := &testDescriber{Output: "test output"}
|
|
|
|
|
tf.DescriberVal = d
|
|
|
|
|
tf.UnstructuredClient = &fake.RESTClient{
|
|
|
|
|
NegotiatedSerializer: unstructuredSerializer,
|
|
|
|
|
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, pods)},
|
|
|
|
@@ -145,13 +169,18 @@ func TestDescribeListObjects(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestDescribeObjectShowEvents(t *testing.T) {
|
|
|
|
|
d := &testDescriber{Output: "test output"}
|
|
|
|
|
oldFn := cmdutil.DescriberFn
|
|
|
|
|
defer func() {
|
|
|
|
|
cmdutil.DescriberFn = oldFn
|
|
|
|
|
}()
|
|
|
|
|
cmdutil.DescriberFn = d.describerFor
|
|
|
|
|
|
|
|
|
|
pods, _, _ := testData()
|
|
|
|
|
tf := cmdtesting.NewTestFactory()
|
|
|
|
|
defer tf.Cleanup()
|
|
|
|
|
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
|
|
|
|
|
|
|
|
|
|
d := &testDescriber{Output: "test output"}
|
|
|
|
|
tf.DescriberVal = d
|
|
|
|
|
tf.UnstructuredClient = &fake.RESTClient{
|
|
|
|
|
NegotiatedSerializer: unstructuredSerializer,
|
|
|
|
|
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, pods)},
|
|
|
|
@@ -167,13 +196,18 @@ func TestDescribeObjectShowEvents(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestDescribeObjectSkipEvents(t *testing.T) {
|
|
|
|
|
d := &testDescriber{Output: "test output"}
|
|
|
|
|
oldFn := cmdutil.DescriberFn
|
|
|
|
|
defer func() {
|
|
|
|
|
cmdutil.DescriberFn = oldFn
|
|
|
|
|
}()
|
|
|
|
|
cmdutil.DescriberFn = d.describerFor
|
|
|
|
|
|
|
|
|
|
pods, _, _ := testData()
|
|
|
|
|
tf := cmdtesting.NewTestFactory()
|
|
|
|
|
defer tf.Cleanup()
|
|
|
|
|
codec := legacyscheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
|
|
|
|
|
|
|
|
|
|
d := &testDescriber{Output: "test output"}
|
|
|
|
|
tf.DescriberVal = d
|
|
|
|
|
tf.UnstructuredClient = &fake.RESTClient{
|
|
|
|
|
NegotiatedSerializer: unstructuredSerializer,
|
|
|
|
|
Resp: &http.Response{StatusCode: 200, Header: defaultHeader(), Body: objBody(codec, pods)},
|
|
|
|
@@ -215,3 +249,19 @@ func TestDescribeHelpMessage(t *testing.T) {
|
|
|
|
|
t.Errorf("Expected not to contain: \n %v\nGot:\n %v\n", unexpected, got)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type testDescriber struct {
|
|
|
|
|
Name, Namespace string
|
|
|
|
|
Settings printers.DescriberSettings
|
|
|
|
|
Output string
|
|
|
|
|
Err error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (t *testDescriber) Describe(namespace, name string, describerSettings printers.DescriberSettings) (output string, err error) {
|
|
|
|
|
t.Namespace, t.Name = namespace, name
|
|
|
|
|
t.Settings = describerSettings
|
|
|
|
|
return t.Output, t.Err
|
|
|
|
|
}
|
|
|
|
|
func (t *testDescriber) describerFor(restClientGetter genericclioptions.RESTClientGetter, mapping *meta.RESTMapping) (printers.Describer, error) {
|
|
|
|
|
return t, nil
|
|
|
|
|
}
|
|
|
|
|