mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-11-03 15:25:19 +00:00
Match label and fields selectors in ComponentStatus List API
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user