@@ -2,6 +2,7 @@ package middlewares
22
33import (
44 "context"
5+ "errors"
56 "fmt"
67 "strings"
78 "testing"
@@ -203,17 +204,20 @@ func TestValidateMultitenantIPConfigsRequestFailure(t *testing.T) {
203204 _ , respCode , _ = middleware .GetPodInfoForIPConfigsRequest (context .TODO (), failReq )
204205 assert .Equal (t , respCode , types .UnexpectedError )
205206
207+ kubeletExpectedString := "network is not ready"
206208 // Failed to get MTPNC
207209 b , _ = testPod3Info .OrchestratorContext ()
208210 failReq .OrchestratorContext = b
209- _ , respCode , _ = middleware .GetPodInfoForIPConfigsRequest (context .TODO (), failReq )
211+ _ , respCode , msg : = middleware .GetPodInfoForIPConfigsRequest (context .TODO (), failReq )
210212 assert .Equal (t , respCode , types .UnexpectedError )
213+ assert .Assert (t , strings .Contains (msg , kubeletExpectedString ), "expected error message to be '%s', got '%s'" , kubeletExpectedString , msg )
211214
212215 // MTPNC not ready
213216 b , _ = testPod4Info .OrchestratorContext ()
214217 failReq .OrchestratorContext = b
215- _ , respCode , _ = middleware .GetPodInfoForIPConfigsRequest (context .TODO (), failReq )
218+ _ , respCode , msg = middleware .GetPodInfoForIPConfigsRequest (context .TODO (), failReq )
216219 assert .Equal (t , respCode , types .UnexpectedError )
220+ assert .Assert (t , strings .Contains (msg , kubeletExpectedString ), "expected error message to be '%s', got '%s'" , kubeletExpectedString , msg )
217221}
218222
219223func TestGetSWIFTv2IPConfigSuccess (t * testing.T ) {
@@ -232,27 +236,21 @@ func TestGetSWIFTv2IPConfigSuccess(t *testing.T) {
232236 assert .Equal (t , ipInfos [0 ].SkipDefaultRoutes , false )
233237}
234238
239+ // In AKS, for kubelet to retry faster it is particularly looking for "network is not ready" error string.
240+ // https://github.com/kubernetes/kubernetes/blob/efd2a0d1f514be96a2f012fc3cb40f7c872b4e67/pkg/kubelet/pod_workers.go#L1495C2-L1501C3
241+ // This test is to ensure that the error string contains "network is not ready"
235242func TestGetSWIFTv2IPConfigFailure (t * testing.T ) {
236243 middleware := K8sSWIFTv2Middleware {Cli : mock .NewClient ()}
237244
238245 // Pod's MTPNC doesn't exist in cache test
239246 _ , err := middleware .getIPConfig (context .TODO (), testPod3Info )
240- assert .ErrorContains (t , err , mock .ErrMTPNCNotFound .Error ())
247+ assert .Assert (t , errors .Is (err , errMTPNCNotFound ), "expected error to wrap errMTPNCNotFound, got: %v" , err )
248+ assert .ErrorContains (t , err , "network is not ready" )
241249
242250 // Pod's MTPNC is not ready test
243251 _ , err = middleware .getIPConfig (context .TODO (), testPod4Info )
244252 assert .Error (t , err , errMTPNCNotReady .Error ())
245- }
246-
247- // In AKS, for kubelet to retry faster it is particularly looking for "network is not ready" error string.
248- // https://github.com/kubernetes/kubernetes/blob/efd2a0d1f514be96a2f012fc3cb40f7c872b4e67/pkg/kubelet/pod_workers.go#L1495C2-L1501C3
249- // This test is to ensure that the error string errMTPNCNotReady contains "network is not ready"
250- func TestMTPNCNotReadyErrorMessage (t * testing.T ) {
251- middleware := K8sSWIFTv2Middleware {Cli : mock .NewClient ()}
252- // Pod's MTPNC is not ready test
253- _ , err := middleware .getIPConfig (context .TODO (), testPod4Info )
254-
255- assert .Equal (t , strings .Contains (err .Error (), "network is not ready" ), true )
253+ assert .ErrorContains (t , err , "network is not ready" )
256254}
257255
258256func TestSetRoutesSuccess (t * testing.T ) {
0 commit comments