Skip to content

Commit

Permalink
Expose Delete and Create object store calls for Go Plugins
Browse files Browse the repository at this point in the history
- [vmware-archive#1599]

Signed-off-by: vikram yadav <[email protected]>
  • Loading branch information
vikram yadav committed Mar 31, 2021
1 parent 9b658f6 commit a443128
Show file tree
Hide file tree
Showing 10 changed files with 357 additions and 125 deletions.
28 changes: 28 additions & 0 deletions pkg/plugin/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,16 @@ func TestAPI(t *testing.T) {
Kind: "Deployment",
Name: "deployment",
}

object := testutil.ToUnstructured(t, testutil.CreateDeployment("deployment"))

deleteKey := store.Key{
Namespace: "default",
APIVersion: "apps/v1",
Kind: "Deployment",
Name: "foo",
}

pfRequest := api.PortForwardRequest{
Namespace: "default",
PodName: "pod",
Expand Down Expand Up @@ -158,6 +166,26 @@ func TestAPI(t *testing.T) {
assert.Equal(t, expected, got)
},
},
{
name: "delete",
initFunc: func(t *testing.T, mocks *apiMocks) {
mocks.objectStore.EXPECT().
Delete(contextType, storeKeyType).
Return(nil).
Do(func(ctx context.Context, _ store.Key) {
require.Equal(t, "bar", ctx.Value(api.DashboardMetadataKey("foo")))
})
},
doFunc: func(t *testing.T, client *api.Client) {
clientCtx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()

clientCtx = metadata.AppendToOutgoingContext(clientCtx, "x-octant-foo", "bar")
err := client.Delete(clientCtx, deleteKey)

require.NoError(t, err)
},
},
{
name: "port forward",
initFunc: func(t *testing.T, mocks *apiMocks) {
Expand Down
14 changes: 14 additions & 0 deletions pkg/plugin/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,20 @@ func (c *Client) Create(ctx context.Context, object *unstructured.Unstructured)

}

// Delete deletes an object from the dashboard's objectStore.
func (c *Client) Delete(ctx context.Context, key store.Key) error {
client := c.DashboardConnection.Client()

keyRequest, err := convertFromKey(key)
if err != nil {
return err
}

_, err = client.Delete(ctx, keyRequest)

return err
}

// PortForward creates a port forward.
func (c *Client) PortForward(ctx context.Context, req PortForwardRequest) (PortForwardResponse, error) {
client := c.DashboardConnection.Client()
Expand Down
14 changes: 14 additions & 0 deletions pkg/plugin/api/fake/mock_dash_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions pkg/plugin/api/fake/mock_dashboard_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a443128

Please sign in to comment.