Skip to content

Commit

Permalink
Add TestParseEndpointBatchErr to verify invalid endpoint batch error …
Browse files Browse the repository at this point in the history
…state.
  • Loading branch information
sawsa307 committed Jun 1, 2023
1 parent 79c6af9 commit dbf7247
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions pkg/neg/syncers/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1869,6 +1869,57 @@ func TestEnableDegradedMode(t *testing.T) {
})
}
}

func TestCheckEndpointBatchErr(t *testing.T) {
requestError := &googleapi.Error{
Code: http.StatusBadRequest,
}
serverError := &googleapi.Error{
Code: http.StatusInternalServerError,
}

testCases := []struct {
desc string
err error
endpointOperation transactionOp
expectErr error
}{
{
desc: "Not googleapi error",
err: errors.New("Not googleapi.Error"),
endpointOperation: attachOp,
expectErr: negtypes.ErrInvalidAPIResponse,
},
{
desc: "Server error, status code 500",
err: serverError,
endpointOperation: attachOp,
expectErr: serverError,
},
{
desc: "Invalid endpoint batch for endpoint attach, status code 400",
err: requestError,
endpointOperation: attachOp,
expectErr: negtypes.ErrInvalidEPAttach,
},
{
desc: "Invalid endpoint batch for endpoint detach, status code 400",
err: requestError,
endpointOperation: detachOp,
expectErr: negtypes.ErrInvalidEPDetach,
},
}

for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
endpointBatchErr := checkEndpointBatchErr(tc.err, tc.endpointOperation)
if !errors.Is(endpointBatchErr, tc.expectErr) {
t.Errorf("checkEndpointBatchErr() = %t, expected %t", endpointBatchErr, tc.expectErr)
}
})
}
}

func TestGetEndpointPodLabelMap(t *testing.T) {
testContext := negtypes.NewTestContext()
podLister := testContext.PodInformer.GetIndexer()
Expand Down

0 comments on commit dbf7247

Please sign in to comment.