mirror of https://github.com/status-im/consul.git
api: IntentionDelete + tests
This commit is contained in:
parent
272211e171
commit
f27711a319
|
@ -154,7 +154,7 @@ func (h *Connect) Intentions(q *QueryOptions) ([]*Intention, *QueryMeta, error)
|
||||||
func (h *Connect) IntentionGet(id string, q *QueryOptions) (*Intention, *QueryMeta, error) {
|
func (h *Connect) IntentionGet(id string, q *QueryOptions) (*Intention, *QueryMeta, error) {
|
||||||
r := h.c.newRequest("GET", "/v1/connect/intentions/"+id)
|
r := h.c.newRequest("GET", "/v1/connect/intentions/"+id)
|
||||||
r.setQueryOptions(q)
|
r.setQueryOptions(q)
|
||||||
rtt, resp, err := requireOK(h.c.doRequest(r))
|
rtt, resp, err := h.c.doRequest(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
@ -164,6 +164,12 @@ func (h *Connect) IntentionGet(id string, q *QueryOptions) (*Intention, *QueryMe
|
||||||
parseQueryMeta(resp, qm)
|
parseQueryMeta(resp, qm)
|
||||||
qm.RequestTime = rtt
|
qm.RequestTime = rtt
|
||||||
|
|
||||||
|
if resp.StatusCode == 404 {
|
||||||
|
return nil, qm, nil
|
||||||
|
} else if resp.StatusCode != 200 {
|
||||||
|
return nil, nil, fmt.Errorf("Unexpected response code: %d", resp.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
var out Intention
|
var out Intention
|
||||||
if err := decodeBody(resp, &out); err != nil {
|
if err := decodeBody(resp, &out); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
@ -171,6 +177,22 @@ func (h *Connect) IntentionGet(id string, q *QueryOptions) (*Intention, *QueryMe
|
||||||
return &out, qm, nil
|
return &out, qm, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IntentionDelete deletes a single intention.
|
||||||
|
func (h *Connect) IntentionDelete(id string, q *WriteOptions) (*WriteMeta, error) {
|
||||||
|
r := h.c.newRequest("DELETE", "/v1/connect/intentions/"+id)
|
||||||
|
r.setWriteOptions(q)
|
||||||
|
rtt, resp, err := requireOK(h.c.doRequest(r))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
qm := &WriteMeta{}
|
||||||
|
qm.RequestTime = rtt
|
||||||
|
|
||||||
|
return qm, nil
|
||||||
|
}
|
||||||
|
|
||||||
// IntentionMatch returns the list of intentions that match a given source
|
// IntentionMatch returns the list of intentions that match a given source
|
||||||
// or destination. The returned intentions are ordered by precedence where
|
// or destination. The returned intentions are ordered by precedence where
|
||||||
// result[0] is the highest precedence (if that matches, then that rule overrides
|
// result[0] is the highest precedence (if that matches, then that rule overrides
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAPI_ConnectIntentionCreateListGet(t *testing.T) {
|
func TestAPI_ConnectIntentionCreateListGetDelete(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
|
@ -38,6 +38,15 @@ func TestAPI_ConnectIntentionCreateListGet(t *testing.T) {
|
||||||
actual, _, err = connect.IntentionGet(id, nil)
|
actual, _, err = connect.IntentionGet(id, nil)
|
||||||
require.Nil(err)
|
require.Nil(err)
|
||||||
require.Equal(ixn, actual)
|
require.Equal(ixn, actual)
|
||||||
|
|
||||||
|
// Delete it
|
||||||
|
_, err = connect.IntentionDelete(id, nil)
|
||||||
|
require.Nil(err)
|
||||||
|
|
||||||
|
// Get it (should be gone)
|
||||||
|
actual, _, err = connect.IntentionGet(id, nil)
|
||||||
|
require.Nil(err)
|
||||||
|
require.Nil(actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAPI_ConnectIntentionMatch(t *testing.T) {
|
func TestAPI_ConnectIntentionMatch(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue