Update API codes (#336)

This commit is contained in:
Jeff Mitchell authored and GitHub committed 2020-09-08 23:57:26 -04:00
1 parent 99d5456d7a
commit f94f21fd97
74 files changed
+1557 -1802

No files matched your search

+8 -6
View File
@@ -5,6 +5,7 @@ import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"time"
@@ -219,18 +220,19 @@ func (c *Client) Delete(ctx context.Context, targetId string, opt ...Option) (bo
return false, nil, fmt.Errorf("error performing client request during Delete call: %w", err)
}
type deleteResponse struct {
Existed bool
}
target := &deleteResponse{}
apiErr, err := resp.Decode(target)
apiErr, err := resp.Decode(nil)
if err != nil {
return false, nil, fmt.Errorf("error decoding Delete response: %w", err)
}
if apiErr != nil {
// We don't treat a 404 in this case as failure, in order for deletes to
// be idempotent
if apiErr.Status == http.StatusNotFound {
return false, nil, nil
}
return false, apiErr, nil
}
return target.Existed, apiErr, nil
return true, nil, nil
}
func (c *Client) List(ctx context.Context, scopeId string, opt ...Option) ([]*Target, *api.Error, error) {
+3 -3
View File
@@ -164,8 +164,8 @@ func TestCrud(t *testing.T) {
existed, apiErr, err = tarClient.Delete(tc.Context(), tar.Id)
assert.NoError(err)
assert.NotNil(apiErr)
assert.EqualValues(apiErr.Status, http.StatusForbidden)
assert.Nil(apiErr)
assert.False(existed)
}
// TODO: Get better coverage for expected errors and error formats.
@@ -193,7 +193,7 @@ func TestSet_Errors(t *testing.T) {
_, apiErr, err = tarClient.Read(tc.Context(), target.TcpTargetPrefix+"_doesntexis")
require.NoError(err)
assert.NotNil(apiErr)
assert.EqualValues(http.StatusForbidden, apiErr.Status)
assert.EqualValues(http.StatusNotFound, apiErr.Status)
_, apiErr, err = tarClient.Read(tc.Context(), "invalid id")
require.NoError(err)