github.com/cilium/cilium@v1.16.2/pkg/endpoint/regenerator_test.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package endpoint 5 6 import ( 7 "context" 8 "testing" 9 "time" 10 11 "github.com/sirupsen/logrus" 12 "github.com/stretchr/testify/assert" 13 ) 14 15 func TestRegeneratorWaitForIPCacheSync(t *testing.T) { 16 regenerator := Regenerator{ 17 logger: func() logrus.FieldLogger { 18 logger := logrus.New() 19 logger.SetLevel(logrus.FatalLevel) 20 return logger 21 }(), 22 23 cmWaitFn: func(ctx context.Context) error { 24 <-ctx.Done() 25 return ctx.Err() 26 }, 27 28 cmWaitTimeout: 10 * time.Millisecond, 29 } 30 31 tests := []struct { 32 name string 33 ctx context.Context 34 assert assert.ErrorAssertionFunc 35 }{ 36 { 37 name: "valid context", 38 ctx: context.Background(), 39 assert: assert.NoError, 40 }, 41 { 42 name: "expired context", 43 ctx: func() context.Context { 44 ctx, cancel := context.WithCancel(context.Background()) 45 cancel() 46 return ctx 47 }(), 48 assert: assert.Error, 49 }, 50 } 51 52 for _, tt := range tests { 53 t.Run(tt.name, func(t *testing.T) { 54 tt.assert(t, regenerator.WaitForClusterMeshIPIdentitiesSync(tt.ctx)) 55 }) 56 } 57 }