|
| 1 | +/* |
| 2 | +Copyright 2018 The Kubernetes Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package client_test |
| 18 | + |
| 19 | +import ( |
| 20 | + . "github.com/onsi/ginkgo" |
| 21 | + . "github.com/onsi/gomega" |
| 22 | + |
| 23 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 24 | + "k8s.io/apimachinery/pkg/fields" |
| 25 | + "k8s.io/apimachinery/pkg/labels" |
| 26 | + "sigs.k8s.io/controller-runtime/pkg/client" |
| 27 | +) |
| 28 | + |
| 29 | +var _ = Describe("ListOptions", func() { |
| 30 | + It("Should set LabelSelector", func() { |
| 31 | + labelSelector, err := labels.Parse("a=b") |
| 32 | + Expect(err).NotTo(HaveOccurred()) |
| 33 | + o := &client.ListOptions{LabelSelector: labelSelector} |
| 34 | + newListOpts := &client.ListOptions{} |
| 35 | + o.ApplyToList(newListOpts) |
| 36 | + Expect(newListOpts).To(Equal(o)) |
| 37 | + }) |
| 38 | + It("Should set FieldSelector", func() { |
| 39 | + o := &client.ListOptions{FieldSelector: fields.Nothing()} |
| 40 | + newListOpts := &client.ListOptions{} |
| 41 | + o.ApplyToList(newListOpts) |
| 42 | + Expect(newListOpts).To(Equal(o)) |
| 43 | + }) |
| 44 | + It("Should set Namespace", func() { |
| 45 | + o := &client.ListOptions{Namespace: "my-ns"} |
| 46 | + newListOpts := &client.ListOptions{} |
| 47 | + o.ApplyToList(newListOpts) |
| 48 | + Expect(newListOpts).To(Equal(o)) |
| 49 | + }) |
| 50 | + It("Should set Raw", func() { |
| 51 | + o := &client.ListOptions{Raw: &metav1.ListOptions{FieldSelector: "Hans"}} |
| 52 | + newListOpts := &client.ListOptions{} |
| 53 | + o.ApplyToList(newListOpts) |
| 54 | + Expect(newListOpts).To(Equal(o)) |
| 55 | + }) |
| 56 | + It("Should not set anything", func() { |
| 57 | + o := &client.ListOptions{} |
| 58 | + newListOpts := &client.ListOptions{} |
| 59 | + o.ApplyToList(newListOpts) |
| 60 | + Expect(newListOpts).To(Equal(o)) |
| 61 | + }) |
| 62 | +}) |
0 commit comments