Skip to content

Commit

Permalink
Fix for IP create error handling. (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 authored Aug 22, 2022
1 parent 59e8404 commit 38a96fb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cmd/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (c ipCmd) Create(rq *ipAllocateRequest) (*models.V1IPResponse, error) {
resp, err := c.client.IP().AllocateIP(ip.NewAllocateIPParams().WithBody(rq.V1IPAllocateRequest), nil)
if err != nil {
var r *ip.AllocateIPDefault // FIXME: API should define to return conflict
if errors.As(err, &r) && r.Code() == http.StatusConflict {
if errors.As(err, &r) && r.Code() == http.StatusUnprocessableEntity {
return nil, genericcli.AlreadyExistsError()
}
return nil, err
Expand All @@ -142,7 +142,7 @@ func (c ipCmd) Create(rq *ipAllocateRequest) (*models.V1IPResponse, error) {
resp, err := c.client.IP().AllocateSpecificIP(ip.NewAllocateSpecificIPParams().WithIP(rq.SpecificIP).WithBody(rq.V1IPAllocateRequest), nil)
if err != nil {
var r *ip.AllocateSpecificIPDefault // FIXME: API should define to return conflict
if errors.As(err, &r) && r.Code() == http.StatusConflict {
if errors.As(err, &r) && r.Code() == http.StatusUnprocessableEntity {
return nil, genericcli.AlreadyExistsError()
}
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion cmd/ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ IP ALLOCATION UUID DESCRIPTION NAME NETWORK PROJECT TYPE
},
mocks: &client.MetalMockFns{
IP: func(mock *mock.Mock) {
mock.On("AllocateSpecificIP", testcommon.MatchIgnoreContext(t, ip.NewAllocateSpecificIPParams().WithBody(ipResponseToCreate(ip1).V1IPAllocateRequest).WithIP(*ip1.Ipaddress)), nil).Return(nil, ip.NewAllocateSpecificIPDefault(http.StatusConflict)).Once()
mock.On("AllocateSpecificIP", testcommon.MatchIgnoreContext(t, ip.NewAllocateSpecificIPParams().WithBody(ipResponseToCreate(ip1).V1IPAllocateRequest).WithIP(*ip1.Ipaddress)), nil).Return(nil, ip.NewAllocateSpecificIPDefault(http.StatusUnprocessableEntity)).Once()
mock.On("UpdateIP", testcommon.MatchIgnoreContext(t, ip.NewUpdateIPParams().WithBody(ipResponseToUpdate(ip1))), nil).Return(&ip.UpdateIPOK{
Payload: ip1,
}, nil)
Expand Down

0 comments on commit 38a96fb

Please sign in to comment.