fix issue(#52244)kubectl describe serviceaccount have redundance null line, we should keep accordance for kubectl describe command

This commit is contained in:
zhengjiajin 2017-09-13 09:56:26 +08:00
parent e821e531db
commit 23a05f6c23
2 changed files with 37 additions and 2 deletions

View File

@ -2225,7 +2225,6 @@ func describeServiceAccount(serviceAccount *api.ServiceAccount, tokens []api.Sec
w.Write(LEVEL_0, "Namespace:\t%s\n", serviceAccount.Namespace)
printLabelsMultiline(w, "Labels", serviceAccount.Labels)
printAnnotationsMultiline(w, "Annotations", serviceAccount.Annotations)
w.WriteLine()
var (
emptyHeader = " "
@ -2267,7 +2266,6 @@ func describeServiceAccount(serviceAccount *api.ServiceAccount, tokens []api.Sec
prefix = emptyHeader
}
}
w.WriteLine()
}
if events != nil {

View File

@ -1593,6 +1593,43 @@ func TestDescribeResourceQuota(t *testing.T) {
}
}
func TestDescribeServiceAccount(t *testing.T) {
fake := fake.NewSimpleClientset(&api.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
Namespace: "foo",
},
Secrets: []api.ObjectReference{
{
Name: "test-objectref",
},
},
ImagePullSecrets: []api.LocalObjectReference{
{
Name: "test-local-ref",
},
},
})
c := &describeClient{T: t, Namespace: "foo", Interface: fake}
d := ServiceAccountDescriber{c}
out, err := d.Describe("foo", "bar", printers.DescriberSettings{ShowEvents: true})
if err != nil {
t.Errorf("unexpected error: %v", err)
}
expectedOut := `Name: bar
Namespace: foo
Labels: <none>
Annotations: <none>
Image pull secrets: test-local-ref (not found)
Mountable secrets: test-objectref (not found)
Tokens: <none>
Events: <none>` + "\n"
if out != expectedOut {
t.Errorf("expected : %q\n but got output:\n %q", expectedOut, out)
}
}
// boolPtr returns a pointer to a bool
func boolPtr(b bool) *bool {
o := b