Match label and fields selectors in ComponentStatus List API

This commit is contained in:
Jan Janik
2019-05-28 23:37:10 +12:00
parent 90f41951cd
commit 80cb726110
4 changed files with 89 additions and 3 deletions

View File

@@ -22,6 +22,10 @@ import (
"strings"
"testing"
metainternalversion "k8s.io/apimachinery/pkg/apis/meta/internalversion"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
"net/http"
"net/url"
"time"
@@ -88,6 +92,44 @@ func TestList_NoError(t *testing.T) {
}
}
func TestList_WithLabelSelectors(t *testing.T) {
r := NewTestREST(testResponse{result: probe.Success, data: "ok"})
opts := metainternalversion.ListOptions{
LabelSelector: labels.SelectorFromSet(map[string]string{
"testLabel": "testValue",
}),
}
got, err := r.List(genericapirequest.NewContext(), &opts)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
expect := &api.ComponentStatusList{
Items: []api.ComponentStatus{},
}
if e, a := expect, got; !reflect.DeepEqual(e, a) {
t.Errorf("Got unexpected object. Diff: %s", diff.ObjectDiff(e, a))
}
}
func TestList_WithFieldSelectors(t *testing.T) {
r := NewTestREST(testResponse{result: probe.Success, data: "ok"})
opts := metainternalversion.ListOptions{
FieldSelector: fields.SelectorFromSet(map[string]string{
"testField": "testValue",
}),
}
got, err := r.List(genericapirequest.NewContext(), &opts)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
expect := &api.ComponentStatusList{
Items: []api.ComponentStatus{},
}
if e, a := expect, got; !reflect.DeepEqual(e, a) {
t.Errorf("Got unexpected object. Diff: %s", diff.ObjectDiff(e, a))
}
}
func TestList_FailedCheck(t *testing.T) {
r := NewTestREST(testResponse{result: probe.Failure, data: ""})
got, err := r.List(genericapirequest.NewContext(), nil)