...

Source file src/sigs.k8s.io/controller-runtime/pkg/internal/field/selector/utils_test.go

Documentation: sigs.k8s.io/controller-runtime/pkg/internal/field/selector

     1  /*
     2  Copyright 2022 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 selector_test
    18  
    19  import (
    20  	. "github.com/onsi/ginkgo/v2"
    21  	. "github.com/onsi/gomega"
    22  	"k8s.io/apimachinery/pkg/fields"
    23  
    24  	. "sigs.k8s.io/controller-runtime/pkg/internal/field/selector"
    25  )
    26  
    27  var _ = Describe("RequiresExactMatch function", func() {
    28  
    29  	It("Returns false when the selector matches everything", func() {
    30  		requiresExactMatch := RequiresExactMatch(fields.Everything())
    31  		Expect(requiresExactMatch).To(BeFalse())
    32  	})
    33  
    34  	It("Returns false when the selector matches nothing", func() {
    35  		requiresExactMatch := RequiresExactMatch(fields.Nothing())
    36  		Expect(requiresExactMatch).To(BeFalse())
    37  	})
    38  
    39  	It("Returns false when the selector has the form key!=val", func() {
    40  		requiresExactMatch := RequiresExactMatch(fields.ParseSelectorOrDie("key!=val"))
    41  		Expect(requiresExactMatch).To(BeFalse())
    42  	})
    43  
    44  	It("Returns true when the selector has the form key1==val1,key2==val2", func() {
    45  		requiresExactMatch := RequiresExactMatch(fields.ParseSelectorOrDie("key1==val1,key2==val2"))
    46  		Expect(requiresExactMatch).To(BeTrue())
    47  	})
    48  
    49  	It("Returns true when the selector has the form key==val", func() {
    50  		requiresExactMatch := RequiresExactMatch(fields.ParseSelectorOrDie("key==val"))
    51  		Expect(requiresExactMatch).To(BeTrue())
    52  	})
    53  
    54  	It("Returns true when the selector has the form key=val", func() {
    55  		requiresExactMatch := RequiresExactMatch(fields.ParseSelectorOrDie("key=val"))
    56  		Expect(requiresExactMatch).To(BeTrue())
    57  	})
    58  })
    59  

View as plain text