mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #45729 from zhangxiaoyu-zidif/add-printer-unittest
Automatic merge from submit-queue (batch tested with PRs 45653, 45719, 45729, 45730, 44250) get pod -o wide: add unittest for nodeName **What this PR does / why we need it**: get pod -o wide: add unittest for nodeName In case that when nodeName is empty, we can get correct info. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
This commit is contained in:
commit
ce65431c1c
@ -825,6 +825,43 @@ func TestPrintNodeKernelVersion(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrintNodeName(t *testing.T) {
|
||||
printer := printers.NewHumanReadablePrinter(nil, nil, printers.PrintOptions{
|
||||
Wide: true,
|
||||
})
|
||||
AddHandlers(printer)
|
||||
table := []struct {
|
||||
node api.Node
|
||||
Name string
|
||||
}{
|
||||
{
|
||||
node: api.Node{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "127.0.0.1"},
|
||||
Status: api.NodeStatus{},
|
||||
},
|
||||
Name: "127.0.0.1",
|
||||
},
|
||||
{
|
||||
node: api.Node{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: ""},
|
||||
Status: api.NodeStatus{},
|
||||
},
|
||||
Name: "<unknown>",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range table {
|
||||
buffer := &bytes.Buffer{}
|
||||
err := printer.PrintObj(&test.node, buffer)
|
||||
if err != nil {
|
||||
t.Fatalf("An error occurred printing Node: %#v", err)
|
||||
}
|
||||
if !contains(strings.Fields(buffer.String()), test.Name) {
|
||||
t.Fatalf("Expect printing node %s with node name %#v, got: %#v", test.node.Name, test.Name, buffer.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrintNodeExternalIP(t *testing.T) {
|
||||
printer := printers.NewHumanReadablePrinter(nil, nil, printers.PrintOptions{
|
||||
Wide: true,
|
||||
|
Loading…
Reference in New Issue
Block a user