Error: kubectl --all-namespaces get {node|ev|cs}
Report an error if someone asks for --all-namespaces when getting a thing that is not namespaced. This is in preparation for a subsequent commit which prints namespace as its own column. Restructured test to expect an error for non-namespaced things. Dropped the part where it was trying to test that not printing namespace didn't contain namespace. Some other test can cover that.
This commit is contained in:
@@ -774,14 +774,14 @@ func TestPrintHumanReadableWithNamespace(t *testing.T) {
|
||||
namespaceName := "testnamespace"
|
||||
name := "test"
|
||||
table := []struct {
|
||||
obj runtime.Object
|
||||
printNamespace bool
|
||||
obj runtime.Object
|
||||
isNamespaced bool
|
||||
}{
|
||||
{
|
||||
obj: &api.Pod{
|
||||
ObjectMeta: api.ObjectMeta{Name: name, Namespace: namespaceName},
|
||||
},
|
||||
printNamespace: true,
|
||||
isNamespaced: true,
|
||||
},
|
||||
{
|
||||
obj: &api.ReplicationController{
|
||||
@@ -812,7 +812,7 @@ func TestPrintHumanReadableWithNamespace(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
printNamespace: true,
|
||||
isNamespaced: true,
|
||||
},
|
||||
{
|
||||
obj: &api.Service{
|
||||
@@ -836,7 +836,7 @@ func TestPrintHumanReadableWithNamespace(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
printNamespace: true,
|
||||
isNamespaced: true,
|
||||
},
|
||||
{
|
||||
obj: &api.Endpoints{
|
||||
@@ -846,47 +846,47 @@ func TestPrintHumanReadableWithNamespace(t *testing.T) {
|
||||
Ports: []api.EndpointPort{{Port: 8080}},
|
||||
},
|
||||
}},
|
||||
printNamespace: true,
|
||||
isNamespaced: true,
|
||||
},
|
||||
{
|
||||
obj: &api.Namespace{
|
||||
ObjectMeta: api.ObjectMeta{Name: name},
|
||||
},
|
||||
printNamespace: false,
|
||||
isNamespaced: false,
|
||||
},
|
||||
{
|
||||
obj: &api.Secret{
|
||||
ObjectMeta: api.ObjectMeta{Name: name, Namespace: namespaceName},
|
||||
},
|
||||
printNamespace: true,
|
||||
isNamespaced: true,
|
||||
},
|
||||
{
|
||||
obj: &api.ServiceAccount{
|
||||
ObjectMeta: api.ObjectMeta{Name: name, Namespace: namespaceName},
|
||||
Secrets: []api.ObjectReference{},
|
||||
},
|
||||
printNamespace: true,
|
||||
isNamespaced: true,
|
||||
},
|
||||
{
|
||||
obj: &api.Node{
|
||||
ObjectMeta: api.ObjectMeta{Name: name},
|
||||
Status: api.NodeStatus{},
|
||||
},
|
||||
printNamespace: false,
|
||||
isNamespaced: false,
|
||||
},
|
||||
{
|
||||
obj: &api.PersistentVolume{
|
||||
ObjectMeta: api.ObjectMeta{Name: name, Namespace: namespaceName},
|
||||
Spec: api.PersistentVolumeSpec{},
|
||||
},
|
||||
printNamespace: true,
|
||||
isNamespaced: false,
|
||||
},
|
||||
{
|
||||
obj: &api.PersistentVolumeClaim{
|
||||
ObjectMeta: api.ObjectMeta{Name: name, Namespace: namespaceName},
|
||||
Spec: api.PersistentVolumeClaimSpec{},
|
||||
},
|
||||
printNamespace: true,
|
||||
isNamespaced: true,
|
||||
},
|
||||
{
|
||||
obj: &api.Event{
|
||||
@@ -897,19 +897,19 @@ func TestPrintHumanReadableWithNamespace(t *testing.T) {
|
||||
LastTimestamp: util.NewTime(time.Date(2014, time.January, 15, 0, 0, 0, 0, time.UTC)),
|
||||
Count: 1,
|
||||
},
|
||||
printNamespace: false,
|
||||
isNamespaced: true,
|
||||
},
|
||||
{
|
||||
obj: &api.LimitRange{
|
||||
ObjectMeta: api.ObjectMeta{Name: name, Namespace: namespaceName},
|
||||
},
|
||||
printNamespace: true,
|
||||
isNamespaced: true,
|
||||
},
|
||||
{
|
||||
obj: &api.ResourceQuota{
|
||||
ObjectMeta: api.ObjectMeta{Name: name, Namespace: namespaceName},
|
||||
},
|
||||
printNamespace: true,
|
||||
isNamespaced: true,
|
||||
},
|
||||
{
|
||||
obj: &api.ComponentStatus{
|
||||
@@ -917,35 +917,31 @@ func TestPrintHumanReadableWithNamespace(t *testing.T) {
|
||||
{Type: api.ComponentHealthy, Status: api.ConditionTrue, Message: "ok", Error: ""},
|
||||
},
|
||||
},
|
||||
printNamespace: false,
|
||||
isNamespaced: false,
|
||||
},
|
||||
}
|
||||
|
||||
printer := NewHumanReadablePrinter(false, false, false, []string{})
|
||||
for _, test := range table {
|
||||
buffer := &bytes.Buffer{}
|
||||
err := printer.PrintObj(test.obj, buffer)
|
||||
if err != nil {
|
||||
t.Fatalf("An error occurred printing object: %#v", err)
|
||||
}
|
||||
matched := contains(strings.Fields(buffer.String()), fmt.Sprintf("%s/%s", namespaceName, name))
|
||||
if matched {
|
||||
t.Errorf("Expect printing object not to contain namespace: %v", test.obj)
|
||||
}
|
||||
}
|
||||
|
||||
printer = NewHumanReadablePrinter(false, true, false, []string{})
|
||||
for _, test := range table {
|
||||
buffer := &bytes.Buffer{}
|
||||
err := printer.PrintObj(test.obj, buffer)
|
||||
if err != nil {
|
||||
t.Fatalf("An error occurred printing object: %#v", err)
|
||||
}
|
||||
matched := contains(strings.Fields(buffer.String()), fmt.Sprintf("%s/%s", namespaceName, name))
|
||||
if test.printNamespace && !matched {
|
||||
t.Errorf("Expect printing object to contain namespace: %v", test.obj)
|
||||
} else if !test.printNamespace && matched {
|
||||
t.Errorf("Expect printing object not to contain namespace: %v", test.obj)
|
||||
if test.isNamespaced {
|
||||
// Expect output to include namespace when requested.
|
||||
printer := NewHumanReadablePrinter(false, true, false, []string{})
|
||||
buffer := &bytes.Buffer{}
|
||||
err := printer.PrintObj(test.obj, buffer)
|
||||
if err != nil {
|
||||
t.Fatalf("An error occurred printing object: %#v", err)
|
||||
}
|
||||
matched := contains(strings.Fields(buffer.String()), fmt.Sprintf("%s/%s", namespaceName, name))
|
||||
if !matched {
|
||||
t.Errorf("Expect printing object to contain namespace: %#v", test.obj)
|
||||
}
|
||||
} else {
|
||||
// Expect error when trying to get all namespaces for un-namespaced object.
|
||||
printer := NewHumanReadablePrinter(false, true, false, []string{})
|
||||
buffer := &bytes.Buffer{}
|
||||
err := printer.PrintObj(test.obj, buffer)
|
||||
if err == nil {
|
||||
t.Errorf("Expected error when printing un-namespaced type")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user