Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 38 additions & 3 deletions client/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package client
import (
"context"

"github.com/pkg/errors"
"github.com/replicatedhq/replicated/pkg/kotsclient"
"github.com/replicatedhq/replicated/pkg/platformclient"
"github.com/replicatedhq/replicated/pkg/types"
)

Expand Down Expand Up @@ -49,13 +52,45 @@ func (c *Client) ListApps(excludeChannels bool) ([]types.AppAndChannels, error)
}

func (c *Client) GetApp(appID string) (interface{}, error) {
return nil, nil
app, _, err := c.GetAppType(context.TODO(), appID, true)
if err != nil {
return nil, err
}
return app, nil
}

func (c *Client) CreateApp(appOptions interface{}) (interface{}, error) {
return nil, nil
switch opts := appOptions.(type) {
case kotsclient.CreateKOTSAppRequest:
return c.KotsClient.CreateKOTSApp(context.TODO(), opts.Name)
case *kotsclient.CreateKOTSAppRequest:
if opts == nil {
return nil, errors.New("create app options cannot be nil")
}
return c.KotsClient.CreateKOTSApp(context.TODO(), opts.Name)
case platformclient.AppOptions:
return c.PlatformClient.CreateApp(&opts)
case *platformclient.AppOptions:
if opts == nil {
return nil, errors.New("create app options cannot be nil")
}
return c.PlatformClient.CreateApp(opts)
default:
return nil, errors.Errorf("unsupported app options type %T", appOptions)
}
}

func (c *Client) DeleteApp(appID string) error {
return nil
app, appType, err := c.GetAppType(context.TODO(), appID, true)
if err != nil {
return err
}

if appType == "platform" {
return c.PlatformClient.DeleteApp(app.ID)
} else if appType == "kots" {
return c.KotsClient.DeleteKOTSApp(context.TODO(), app.ID)
}

return errors.Errorf("unknown app type %q", appType)
}
47 changes: 47 additions & 0 deletions client/app_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package client

import (
"testing"

"github.com/replicatedhq/replicated/pkg/kotsclient"
"github.com/replicatedhq/replicated/pkg/platformclient"
"github.com/stretchr/testify/require"
)

func newTestClient(origin string) Client {
platformHTTPClient := platformclient.NewHTTPClient(origin, "fake-api-key")
return Client{
PlatformClient: platformHTTPClient,
KotsClient: &kotsclient.VendorV3Client{HTTPClient: *platformHTTPClient},
}
}

func TestClientGetAppReturnsBackendError(t *testing.T) {
c := newTestClient("http://%")

app, err := c.GetApp("app-id")
require.Nil(t, app)
require.Error(t, err)
}

func TestClientCreateAppRejectsUnsupportedOptions(t *testing.T) {
c := newTestClient("http://127.0.0.1")

app, err := c.CreateApp(struct{}{})
require.Nil(t, app)
require.ErrorContains(t, err, "unsupported app options type")
}

func TestClientCreateAppRejectsNilOptions(t *testing.T) {
c := newTestClient("http://127.0.0.1")

app, err := c.CreateApp((*platformclient.AppOptions)(nil))
require.Nil(t, app)
require.ErrorContains(t, err, "create app options cannot be nil")
}

func TestClientDeleteAppReturnsLookupError(t *testing.T) {
c := newTestClient("http://%")

require.Error(t, c.DeleteApp("app-id"))
}