@@ -186,6 +186,25 @@ func TestLocal_AllocWorker_ParentCancelContext(t *testing.T) {
186186 assert .False (t , ok )
187187}
188188
189+ func TestLocal_AllocWorker_UpdateCache (t * testing.T ) {
190+ local := NewLocalTest (& daemon.ENI {ID : "eni-1" }, nil , & types.PoolConfig {
191+ EnableIPv4 : true ,
192+ }, "" )
193+ cni := & daemon.CNI {PodID : "pod-1" }
194+
195+ ctx , cancel := context .WithCancel (context .Background ())
196+ defer cancel ()
197+ respCh := make (chan * AllocResp )
198+
199+ req := NewLocalIPRequest ()
200+ req .NoCache = true
201+ go local .allocWorker (ctx , cni , req , respCh )
202+ req .cancel ()
203+ result , ok := <- respCh
204+ assert .True (t , ok )
205+ assert .NotNil (t , result )
206+ }
207+
189208func TestLocal_Dispose (t * testing.T ) {
190209 local := NewLocalTest (& daemon.ENI {ID : "eni-1" }, nil , & types.PoolConfig {}, "" )
191210 local .status = statusInUse
@@ -229,6 +248,19 @@ func TestLocal_Allocate_NoCache(t *testing.T) {
229248 assert .Equal (t , 1 , len (resp ))
230249}
231250
251+ func TestLocal_DisposeFailWhenAllocatingIsNotEmpty (t * testing.T ) {
252+ local := NewLocalTest (& daemon.ENI {ID : "eni-1" }, nil , & types.PoolConfig {}, "" )
253+ local .status = statusInUse
254+ local .ipv4 .Add (NewValidIP (netip .MustParseAddr ("192.0.2.1" ), true ))
255+ local .ipv6 .Add (NewValidIP (netip .MustParseAddr ("fd00:46dd:e::1" ), false ))
256+
257+ local .allocatingV4 = append (local .allocatingV4 , NewLocalIPRequest ())
258+ n := local .Dispose (1 )
259+
260+ assert .Equal (t , 1 , n )
261+ assert .Equal (t , statusInUse , local .status )
262+ }
263+
232264func TestLocal_Allocate_NoCache_AllocSuccess (t * testing.T ) {
233265 local := NewLocalTest (& daemon.ENI {ID : "eni-1" }, nil , & types.PoolConfig {
234266 MaxIPPerENI : 10 , EnableIPv4 : true , EnableIPv6 : true }, "" )
0 commit comments