Commit b31d1db4 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #48831 from enisoc/resource-filter-test

Automatic merge from submit-queue (batch tested with PRs 46738, 48827, 48831) Add test for kubectl resource filter. This should prevent regression of the bug fixed in #48786.
parents 4da48f1c bbe3ac9f
......@@ -20,6 +20,7 @@ go_test(
"namespace_test.go",
"proxy_server_test.go",
"quota_test.go",
"resource_filter_test.go",
"rolebinding_test.go",
"rolling_updater_test.go",
"rollout_status_test.go",
......@@ -51,6 +52,7 @@ go_test(
"//pkg/client/clientset_generated/internalclientset/typed/core/internalversion:go_default_library",
"//pkg/client/clientset_generated/internalclientset/typed/extensions/internalversion:go_default_library",
"//pkg/kubectl/util:go_default_library",
"//pkg/printers:go_default_library",
"//vendor/github.com/spf13/cobra:go_default_library",
"//vendor/k8s.io/api/apps/v1beta1:go_default_library",
"//vendor/k8s.io/api/batch/v1:go_default_library",
......
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package kubectl
import (
"testing"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/printers"
)
func TestResourceFilter(t *testing.T) {
tests := []struct {
name string
hide bool
object runtime.Object
}{
{"v1.Pod pending", false, &v1.Pod{Status: v1.PodStatus{Phase: v1.PodPending}}},
{"v1.Pod running", false, &v1.Pod{Status: v1.PodStatus{Phase: v1.PodRunning}}},
{"v1.Pod succeeded", true, &v1.Pod{Status: v1.PodStatus{Phase: v1.PodSucceeded}}},
{"v1.Pod failed", true, &v1.Pod{Status: v1.PodStatus{Phase: v1.PodFailed}}},
{"v1.Pod evicted", true, &v1.Pod{Status: v1.PodStatus{Phase: v1.PodFailed, Reason: "Evicted"}}},
{"v1.Pod unknown", false, &v1.Pod{Status: v1.PodStatus{Phase: v1.PodUnknown}}},
{"api.Pod pending", false, &api.Pod{Status: api.PodStatus{Phase: api.PodPending}}},
{"api.Pod running", false, &api.Pod{Status: api.PodStatus{Phase: api.PodRunning}}},
{"api.Pod succeeded", true, &api.Pod{Status: api.PodStatus{Phase: api.PodSucceeded}}},
{"api.Pod failed", true, &api.Pod{Status: api.PodStatus{Phase: api.PodFailed}}},
{"api.Pod evicted", true, &api.Pod{Status: api.PodStatus{Phase: api.PodFailed, Reason: "Evicted"}}},
{"api.Pod unknown", false, &api.Pod{Status: api.PodStatus{Phase: api.PodUnknown}}},
}
filters := NewResourceFilter()
options := &printers.PrintOptions{
ShowAll: false,
}
for _, test := range tests {
got, err := filters.Filter(test.object, options)
if err != nil {
t.Errorf("%v: unexpected error: %v", test.name, err)
continue
}
if want := test.hide; got != want {
t.Errorf("%v: got %v, want %v", test.name, got, want)
}
}
options.ShowAll = true
for _, test := range tests {
got, err := filters.Filter(test.object, options)
if err != nil {
t.Errorf("%v: unexpected error: %v", test.name, err)
continue
}
if want := false; got != want {
t.Errorf("%v (ShowAll): got %v, want %v", test.name, got, want)
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment