add flag --no-headers to kubectl top ...

This commit is contained in:
WanLinghao
2018-08-27 19:27:48 +08:00
parent 4733b85714
commit c9b6c92f10
5 changed files with 36 additions and 14 deletions

View File

@@ -37,6 +37,7 @@ import (
"k8s.io/client-go/rest/fake"
core "k8s.io/client-go/testing"
cmdtesting "k8s.io/kubernetes/pkg/kubectl/cmd/testing"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/scheme"
metricsv1alpha1api "k8s.io/metrics/pkg/apis/metrics/v1alpha1"
metricsv1beta1api "k8s.io/metrics/pkg/apis/metrics/v1beta1"
@@ -132,6 +133,14 @@ func TestTopPod(t *testing.T) {
namespaces: []string{testNS},
containers: true,
},
{
name: "no-headers set",
flags: map[string]string{"containers": "true", "no-headers": "true"},
args: []string{"pod1"},
expectedPath: topPathPrefix + "/namespaces/" + testNS + "/pods/pod1",
namespaces: []string{testNS},
containers: true,
},
}
initTestErrorHandler(t)
for _, testCase := range testCases {
@@ -221,6 +230,9 @@ func TestTopPod(t *testing.T) {
t.Errorf("%s: unexpected metrics for %s: \n%s", testCase.name, name, result)
}
}
if cmdutil.GetFlagBool(cmd, "no-headers") && strings.Contains(result, "MEMORY") {
t.Errorf("%s: unexpected headers with no-headers option set: \n%s", testCase.name, result)
}
})
}
}