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
3 changes: 3 additions & 0 deletions internal/cmd/database/read_only_regions.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ func ReadOnlyRegionsListCmd(ch *cmdutil.Helper) *cobra.Command {
if err != nil {
return err
}
if err := requireVitessDatabase(cmd.Context(), ch, client, database, "read-only regions"); err != nil {
return err
}

end := ch.Printer.PrintProgress(fmt.Sprintf("Fetching read-only regions for database %s...", printer.BoldBlue(database)))
defer end()
Expand Down
30 changes: 28 additions & 2 deletions internal/cmd/database/regions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ func TestDatabase_RegionsListCmdHuman(t *testing.T) {
func TestDatabase_ReadOnlyRegionsListCmd(t *testing.T) {
c := qt.New(t)
var out bytes.Buffer
databases := &mock.DatabaseService{
GetFn: func(context.Context, *ps.GetDatabaseRequest) (*ps.Database, error) {
return &ps.Database{Name: "app", Kind: ps.DatabaseEngineMySQL}, nil
},
}
regions := []*ps.ReadOnlyRegion{{
ID: "ror123",
DisplayName: "Europe West",
Expand All @@ -105,7 +110,7 @@ func TestDatabase_ReadOnlyRegionsListCmd(t *testing.T) {
},
}

cmd := ReadOnlyRegionsListCmd(databaseRegionsTestHelper(printer.JSON, &out, nil, svc))
cmd := ReadOnlyRegionsListCmd(databaseRegionsTestHelper(printer.JSON, &out, databases, svc))
cmd.SetArgs([]string{"app", "--page", "3", "--per-page", "10"})
c.Assert(cmd.Execute(), qt.IsNil)
c.Assert(svc.ListFnInvoked, qt.IsTrue)
Expand All @@ -116,6 +121,11 @@ func TestDatabase_ReadOnlyRegionsListCmd(t *testing.T) {
func TestDatabase_ReadOnlyRegionsListCmdHuman(t *testing.T) {
c := qt.New(t)
var out bytes.Buffer
databases := &mock.DatabaseService{
GetFn: func(context.Context, *ps.GetDatabaseRequest) (*ps.Database, error) {
return &ps.Database{Name: "app", Kind: ps.DatabaseEngineMySQL}, nil
},
}
svc := &mock.ReadOnlyRegionsService{
ListFn: func(context.Context, *ps.ListReadOnlyRegionsRequest, ...ps.ListOption) ([]*ps.ReadOnlyRegion, error) {
return []*ps.ReadOnlyRegion{{
Expand All @@ -130,14 +140,30 @@ func TestDatabase_ReadOnlyRegionsListCmdHuman(t *testing.T) {
},
}

cmd := ReadOnlyRegionsListCmd(databaseRegionsTestHelper(printer.Human, &out, nil, svc))
cmd := ReadOnlyRegionsListCmd(databaseRegionsTestHelper(printer.Human, &out, databases, svc))
cmd.SetArgs([]string{"app"})
c.Assert(cmd.Execute(), qt.IsNil)
c.Assert(out.String(), qt.Contains, "ror123")
c.Assert(out.String(), qt.Contains, "eu-west")
c.Assert(out.String(), qt.Contains, "Europe West")
}

func TestDatabase_ReadOnlyRegionsListCmdRejectsPostgres(t *testing.T) {
c := qt.New(t)
databases := &mock.DatabaseService{
GetFn: func(context.Context, *ps.GetDatabaseRequest) (*ps.Database, error) {
return &ps.Database{Name: "app", Kind: ps.DatabaseEnginePostgres}, nil
},
}
regions := &mock.ReadOnlyRegionsService{}

cmd := ReadOnlyRegionsListCmd(databaseRegionsTestHelper(printer.JSON, &bytes.Buffer{}, databases, regions))
cmd.SetArgs([]string{"app"})

c.Assert(cmd.Execute(), qt.ErrorMatches, `.*only available for Vitess .* databases; app is postgresql`)
c.Assert(regions.ListFnInvoked, qt.IsFalse)
}

func TestDatabase_RegionCommandsRegistered(t *testing.T) {
c := qt.New(t)
ch := databaseRegionsTestHelper(printer.JSON, &bytes.Buffer{}, &mock.DatabaseService{}, &mock.ReadOnlyRegionsService{})
Expand Down
15 changes: 14 additions & 1 deletion internal/cmd/org/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"strings"
"time"

"github.com/planetscale/cli/internal/cmdutil"
ps "github.com/planetscale/cli/internal/planetscale"
Expand Down Expand Up @@ -101,7 +102,19 @@ func toOrganizationTeamMembers(members []*ps.OrganizationTeamMembership) []*orga
}

func (m *organizationTeamMember) MarshalJSON() ([]byte, error) {
return json.MarshalIndent(m.orig, "", " ")
return json.MarshalIndent(struct {
ID string `json:"id"`
User ps.OrganizationTeamUser `json:"user"`
Actor ps.OrganizationTeamActor `json:"actor"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}{
ID: m.orig.ID,
User: m.orig.User,
Actor: m.orig.Actor,
CreatedAt: m.orig.CreatedAt,
UpdatedAt: m.orig.UpdatedAt,
}, "", " ")
}

func (m *organizationTeamMember) MarshalCSVValue() interface{} {
Expand Down
4 changes: 4 additions & 0 deletions internal/cmd/org/team_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org
import (
"bytes"
"context"
"encoding/json"
"net/url"
"testing"

Expand Down Expand Up @@ -35,6 +36,7 @@ func testTeamMember() *ps.OrganizationTeamMembership {
Name: "Ada",
Email: "ada@example.com",
},
Passwords: []json.RawMessage{json.RawMessage(`{"id":"password-1","name":"production"}`)},
}
}

Expand Down Expand Up @@ -184,6 +186,8 @@ func TestOrg_TeamMemberListCmd(t *testing.T) {
cmd.SetArgs([]string{"platform", "--page", "3", "--per-page", "50"})
c.Assert(cmd.Execute(), qt.IsNil)
c.Assert(buf.String(), qt.Contains, `"email": "ada@example.com"`)
c.Assert(buf.String(), qt.Not(qt.Contains), `"passwords"`)
c.Assert(buf.String(), qt.Not(qt.Contains), `"password-1"`)
}

func TestOrg_TeamMemberListCmd_EmptyPage(t *testing.T) {
Expand Down