github.com/cilium/cilium@v1.16.2/pkg/k8s/watchers/watcher_test.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package watchers 5 6 import ( 7 "context" 8 "testing" 9 10 "github.com/stretchr/testify/require" 11 12 "github.com/cilium/cilium/pkg/k8s/client" 13 "github.com/cilium/cilium/pkg/k8s/synced" 14 ) 15 16 type fakeK8sWatcherConfiguration struct{} 17 18 func (f *fakeK8sWatcherConfiguration) K8sNetworkPolicyEnabled() bool { 19 return true 20 } 21 22 func Test_No_Resources_InitK8sSubsystem(t *testing.T) { 23 fakeClientSet, _ := client.NewFakeClientset() 24 25 w := newWatcher( 26 fakeClientSet, 27 &K8sPodWatcher{ 28 controllersStarted: make(chan struct{}), 29 podStoreSet: make(chan struct{}), 30 }, 31 nil, 32 nil, 33 nil, 34 nil, 35 nil, 36 nil, 37 nil, 38 &synced.Resources{CacheStatus: make(synced.CacheStatus)}, 39 nil, 40 &fakeK8sWatcherConfiguration{}, 41 ) 42 43 w.resourceGroupsFn = func(cfg WatcherConfiguration) (resourceGroups []string, waitForCachesOnly []string) { 44 return []string{}, []string{} 45 } 46 47 // ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) 48 deadline, _ := t.Deadline() 49 ctx, cancel := context.WithDeadline(context.Background(), deadline) 50 defer cancel() 51 52 cachesSynced := make(chan struct{}) 53 w.InitK8sSubsystem(ctx, cachesSynced) 54 // Expect channel to be closed. 55 select { 56 case <-ctx.Done(): 57 t.Fail() 58 case _, ok := <-cachesSynced: 59 require.False(t, ok) 60 } 61 }