istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pkg/config/schema/kubeclient/common_test.go (about)

     1  // Copyright Istio Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package kubeclient
    16  
    17  import (
    18  	"context"
    19  	"testing"
    20  
    21  	corev1 "k8s.io/api/core/v1"
    22  	v1 "k8s.io/api/networking/v1"
    23  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    24  	"k8s.io/apimachinery/pkg/runtime"
    25  	"k8s.io/apimachinery/pkg/watch"
    26  
    27  	"istio.io/istio/pkg/kube"
    28  	ktypes "istio.io/istio/pkg/kube/kubetypes"
    29  )
    30  
    31  func TestCustomRegistration(t *testing.T) {
    32  	Register[*v1.NetworkPolicy](
    33  		v1.SchemeGroupVersion.WithResource("networkpolicies"),
    34  		v1.SchemeGroupVersion.WithKind("NetworkPolicy"),
    35  		func(c ClientGetter, namespace string, o metav1.ListOptions) (runtime.Object, error) {
    36  			return c.Kube().NetworkingV1().NetworkPolicies(namespace).List(context.Background(), o)
    37  		},
    38  		func(c ClientGetter, namespace string, o metav1.ListOptions) (watch.Interface, error) {
    39  			return c.Kube().NetworkingV1().NetworkPolicies(namespace).Watch(context.Background(), o)
    40  		},
    41  	)
    42  
    43  	ns := &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "funkyns"}}
    44  
    45  	client := kube.NewFakeClient(ns)
    46  
    47  	inf := GetInformerFiltered[*v1.NetworkPolicy](client, ktypes.InformerOptions{})
    48  	if inf.Informer == nil {
    49  		t.Errorf("Expected valid informer, got empty")
    50  	}
    51  }
    52  
    53  var _ TypeRegistration[*v1.NetworkPolicy] = (*internalTypeReg[*v1.NetworkPolicy])(nil)