api: IntentionUpdate API
This commit is contained in:
parent
f03fa81e6a
commit
a316ba7f39
|
@ -273,3 +273,20 @@ func (c *Connect) IntentionCreate(ixn *Intention, q *WriteOptions) (string, *Wri
|
||||||
}
|
}
|
||||||
return out.ID, wm, nil
|
return out.ID, wm, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IntentionUpdate will update an existing intention. The ID in the given
|
||||||
|
// structure must be non-empty.
|
||||||
|
func (c *Connect) IntentionUpdate(ixn *Intention, q *WriteOptions) (*WriteMeta, error) {
|
||||||
|
r := c.c.newRequest("PUT", "/v1/connect/intentions/"+ixn.ID)
|
||||||
|
r.setWriteOptions(q)
|
||||||
|
r.obj = ixn
|
||||||
|
rtt, resp, err := requireOK(c.c.doRequest(r))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
wm := &WriteMeta{}
|
||||||
|
wm.RequestTime = rtt
|
||||||
|
return wm, nil
|
||||||
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAPI_ConnectIntentionCreateListGetDelete(t *testing.T) {
|
func TestAPI_ConnectIntentionCreateListGetUpdateDelete(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
|
@ -39,6 +39,18 @@ func TestAPI_ConnectIntentionCreateListGetDelete(t *testing.T) {
|
||||||
require.Nil(err)
|
require.Nil(err)
|
||||||
require.Equal(ixn, actual)
|
require.Equal(ixn, actual)
|
||||||
|
|
||||||
|
// Update it
|
||||||
|
ixn.SourceNS = ixn.SourceNS + "-different"
|
||||||
|
_, err = connect.IntentionUpdate(ixn, nil)
|
||||||
|
require.NoError(err)
|
||||||
|
|
||||||
|
// Get it
|
||||||
|
actual, _, err = connect.IntentionGet(id, nil)
|
||||||
|
require.NoError(err)
|
||||||
|
ixn.UpdatedAt = actual.UpdatedAt
|
||||||
|
ixn.ModifyIndex = actual.ModifyIndex
|
||||||
|
require.Equal(ixn, actual)
|
||||||
|
|
||||||
// Delete it
|
// Delete it
|
||||||
_, err = connect.IntentionDelete(id, nil)
|
_, err = connect.IntentionDelete(id, nil)
|
||||||
require.Nil(err)
|
require.Nil(err)
|
||||||
|
|
Loading…
Reference in New Issue