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
5 changes: 2 additions & 3 deletions internal/cmd/branch/vtctld/keyspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"

"github.com/planetscale/cli/internal/cmdutil"
"github.com/planetscale/cli/internal/printer"
ps "github.com/planetscale/planetscale-go/planetscale"
"github.com/spf13/cobra"
)
Expand All @@ -28,8 +27,8 @@ func ListKeyspacesCmd(ch *cmdutil.Helper) *cobra.Command {
}

end := ch.Printer.PrintProgress(
fmt.Sprintf("Fetching keyspaces for %s/%s\u2026",
printer.BoldBlue(database), printer.BoldBlue(branch)))
fmt.Sprintf("Fetching keyspaces for %s\u2026",
progressTarget(ch.Config.Organization, database, branch)))
defer end()

data, err := client.Vtctld.ListKeyspaces(ctx, &ps.VtctldListKeyspacesRequest{
Expand Down
24 changes: 12 additions & 12 deletions internal/cmd/branch/vtctld/lookup_vindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ func LookupVindexCreateCmd(ch *cmdutil.Helper) *cobra.Command {
}

end := ch.Printer.PrintProgress(
fmt.Sprintf("Creating Lookup Vindex %s on %s/%s\u2026",
printer.BoldBlue(flags.name), printer.BoldBlue(database), printer.BoldBlue(branch)))
fmt.Sprintf("Creating Lookup Vindex %s on %s\u2026",
printer.BoldBlue(flags.name), progressTarget(ch.Config.Organization, database, branch)))
defer end()

req := &ps.LookupVindexCreateRequest{
Expand Down Expand Up @@ -134,8 +134,8 @@ func LookupVindexShowCmd(ch *cmdutil.Helper) *cobra.Command {
}

end := ch.Printer.PrintProgress(
fmt.Sprintf("Fetching Lookup Vindex %s on %s/%s\u2026",
printer.BoldBlue(flags.name), printer.BoldBlue(database), printer.BoldBlue(branch)))
fmt.Sprintf("Fetching Lookup Vindex %s on %s\u2026",
printer.BoldBlue(flags.name), progressTarget(ch.Config.Organization, database, branch)))
defer end()

data, err := client.LookupVindex.Show(ctx, &ps.LookupVindexShowRequest{
Expand Down Expand Up @@ -184,8 +184,8 @@ func LookupVindexExternalizeCmd(ch *cmdutil.Helper) *cobra.Command {
}

end := ch.Printer.PrintProgress(
fmt.Sprintf("Externalizing Lookup Vindex %s on %s/%s\u2026",
printer.BoldBlue(flags.name), printer.BoldBlue(database), printer.BoldBlue(branch)))
fmt.Sprintf("Externalizing Lookup Vindex %s on %s\u2026",
printer.BoldBlue(flags.name), progressTarget(ch.Config.Organization, database, branch)))
defer end()

req := &ps.LookupVindexExternalizeRequest{
Expand Down Expand Up @@ -242,8 +242,8 @@ func LookupVindexInternalizeCmd(ch *cmdutil.Helper) *cobra.Command {
}

end := ch.Printer.PrintProgress(
fmt.Sprintf("Internalizing Lookup Vindex %s on %s/%s\u2026",
printer.BoldBlue(flags.name), printer.BoldBlue(database), printer.BoldBlue(branch)))
fmt.Sprintf("Internalizing Lookup Vindex %s on %s\u2026",
printer.BoldBlue(flags.name), progressTarget(ch.Config.Organization, database, branch)))
defer end()

data, err := client.LookupVindex.Internalize(ctx, &ps.LookupVindexInternalizeRequest{
Expand Down Expand Up @@ -292,8 +292,8 @@ func LookupVindexCancelCmd(ch *cmdutil.Helper) *cobra.Command {
}

end := ch.Printer.PrintProgress(
fmt.Sprintf("Canceling Lookup Vindex %s on %s/%s\u2026",
printer.BoldBlue(flags.name), printer.BoldBlue(database), printer.BoldBlue(branch)))
fmt.Sprintf("Canceling Lookup Vindex %s on %s\u2026",
printer.BoldBlue(flags.name), progressTarget(ch.Config.Organization, database, branch)))
defer end()

data, err := client.LookupVindex.Cancel(ctx, &ps.LookupVindexCancelRequest{
Expand Down Expand Up @@ -341,8 +341,8 @@ func LookupVindexCompleteCmd(ch *cmdutil.Helper) *cobra.Command {
}

end := ch.Printer.PrintProgress(
fmt.Sprintf("Completing Lookup Vindex %s on %s/%s\u2026",
printer.BoldBlue(flags.name), printer.BoldBlue(database), printer.BoldBlue(branch)))
fmt.Sprintf("Completing Lookup Vindex %s on %s\u2026",
printer.BoldBlue(flags.name), progressTarget(ch.Config.Organization, database, branch)))
defer end()

data, err := client.LookupVindex.Complete(ctx, &ps.LookupVindexCompleteRequest{
Expand Down
20 changes: 10 additions & 10 deletions internal/cmd/branch/vtctld/materialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ func MaterializeCreateCmd(ch *cmdutil.Helper) *cobra.Command {
}

end := ch.Printer.PrintProgress(
fmt.Sprintf("Creating Materialize workflow %s on %s/%s\u2026",
printer.BoldBlue(flags.workflow), printer.BoldBlue(database), printer.BoldBlue(branch)))
fmt.Sprintf("Creating Materialize workflow %s on %s\u2026",
printer.BoldBlue(flags.workflow), progressTarget(ch.Config.Organization, database, branch)))
defer end()

req := &ps.MaterializeCreateRequest{
Expand Down Expand Up @@ -141,8 +141,8 @@ func MaterializeShowCmd(ch *cmdutil.Helper) *cobra.Command {
}

end := ch.Printer.PrintProgress(
fmt.Sprintf("Fetching Materialize workflow %s on %s/%s\u2026",
printer.BoldBlue(flags.workflow), printer.BoldBlue(database), printer.BoldBlue(branch)))
fmt.Sprintf("Fetching Materialize workflow %s on %s\u2026",
printer.BoldBlue(flags.workflow), progressTarget(ch.Config.Organization, database, branch)))
defer end()

req := &ps.MaterializeShowRequest{
Expand Down Expand Up @@ -197,8 +197,8 @@ func MaterializeStartCmd(ch *cmdutil.Helper) *cobra.Command {
}

end := ch.Printer.PrintProgress(
fmt.Sprintf("Starting Materialize workflow %s on %s/%s\u2026",
printer.BoldBlue(flags.workflow), printer.BoldBlue(database), printer.BoldBlue(branch)))
fmt.Sprintf("Starting Materialize workflow %s on %s\u2026",
printer.BoldBlue(flags.workflow), progressTarget(ch.Config.Organization, database, branch)))
defer end()

data, err := client.Materialize.Start(ctx, &ps.MaterializeStartRequest{
Expand Down Expand Up @@ -246,8 +246,8 @@ func MaterializeStopCmd(ch *cmdutil.Helper) *cobra.Command {
}

end := ch.Printer.PrintProgress(
fmt.Sprintf("Stopping Materialize workflow %s on %s/%s\u2026",
printer.BoldBlue(flags.workflow), printer.BoldBlue(database), printer.BoldBlue(branch)))
fmt.Sprintf("Stopping Materialize workflow %s on %s\u2026",
printer.BoldBlue(flags.workflow), progressTarget(ch.Config.Organization, database, branch)))
defer end()

data, err := client.Materialize.Stop(ctx, &ps.MaterializeStopRequest{
Expand Down Expand Up @@ -297,8 +297,8 @@ func MaterializeCancelCmd(ch *cmdutil.Helper) *cobra.Command {
}

end := ch.Printer.PrintProgress(
fmt.Sprintf("Canceling Materialize workflow %s on %s/%s\u2026",
printer.BoldBlue(flags.workflow), printer.BoldBlue(database), printer.BoldBlue(branch)))
fmt.Sprintf("Canceling Materialize workflow %s on %s\u2026",
printer.BoldBlue(flags.workflow), progressTarget(ch.Config.Organization, database, branch)))
defer end()

req := &ps.MaterializeCancelRequest{
Expand Down
28 changes: 14 additions & 14 deletions internal/cmd/branch/vtctld/move_tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ func MoveTablesCreateCmd(ch *cmdutil.Helper) *cobra.Command {
}

end := ch.Printer.PrintProgress(
fmt.Sprintf("Creating MoveTables workflow %s on %s/%s\u2026",
printer.BoldBlue(flags.workflow), printer.BoldBlue(database), printer.BoldBlue(branch)))
fmt.Sprintf("Creating MoveTables workflow %s on %s\u2026",
printer.BoldBlue(flags.workflow), progressTarget(ch.Config.Organization, database, branch)))
defer end()

req := &ps.MoveTablesCreateRequest{
Expand Down Expand Up @@ -160,8 +160,8 @@ func MoveTablesShowCmd(ch *cmdutil.Helper) *cobra.Command {
}

end := ch.Printer.PrintProgress(
fmt.Sprintf("Fetching MoveTables workflow %s on %s/%s\u2026",
printer.BoldBlue(flags.workflow), printer.BoldBlue(database), printer.BoldBlue(branch)))
fmt.Sprintf("Fetching MoveTables workflow %s on %s\u2026",
printer.BoldBlue(flags.workflow), progressTarget(ch.Config.Organization, database, branch)))
defer end()

data, err := client.MoveTables.Show(ctx, &ps.MoveTablesShowRequest{
Expand Down Expand Up @@ -208,8 +208,8 @@ func MoveTablesStatusCmd(ch *cmdutil.Helper) *cobra.Command {
}

end := ch.Printer.PrintProgress(
fmt.Sprintf("Fetching MoveTables workflow status for %s on %s/%s\u2026",
printer.BoldBlue(flags.workflow), printer.BoldBlue(database), printer.BoldBlue(branch)))
fmt.Sprintf("Fetching MoveTables workflow status for %s on %s\u2026",
printer.BoldBlue(flags.workflow), progressTarget(ch.Config.Organization, database, branch)))
defer end()

data, err := client.MoveTables.Status(ctx, &ps.MoveTablesStatusRequest{
Expand Down Expand Up @@ -260,8 +260,8 @@ func MoveTablesSwitchTrafficCmd(ch *cmdutil.Helper) *cobra.Command {
}

end := ch.Printer.PrintProgress(
fmt.Sprintf("Switching traffic for MoveTables workflow %s on %s/%s\u2026",
printer.BoldBlue(flags.workflow), printer.BoldBlue(database), printer.BoldBlue(branch)))
fmt.Sprintf("Switching traffic for MoveTables workflow %s on %s\u2026",
printer.BoldBlue(flags.workflow), progressTarget(ch.Config.Organization, database, branch)))
defer end()

req := &ps.MoveTablesSwitchTrafficRequest{
Expand Down Expand Up @@ -333,8 +333,8 @@ func MoveTablesReverseTrafficCmd(ch *cmdutil.Helper) *cobra.Command {
}

end := ch.Printer.PrintProgress(
fmt.Sprintf("Reversing traffic for MoveTables workflow %s on %s/%s\u2026",
printer.BoldBlue(flags.workflow), printer.BoldBlue(database), printer.BoldBlue(branch)))
fmt.Sprintf("Reversing traffic for MoveTables workflow %s on %s\u2026",
printer.BoldBlue(flags.workflow), progressTarget(ch.Config.Organization, database, branch)))
defer end()

req := &ps.MoveTablesReverseTrafficRequest{
Expand Down Expand Up @@ -401,8 +401,8 @@ func MoveTablesCancelCmd(ch *cmdutil.Helper) *cobra.Command {
}

end := ch.Printer.PrintProgress(
fmt.Sprintf("Canceling MoveTables workflow %s on %s/%s\u2026",
printer.BoldBlue(flags.workflow), printer.BoldBlue(database), printer.BoldBlue(branch)))
fmt.Sprintf("Canceling MoveTables workflow %s on %s\u2026",
printer.BoldBlue(flags.workflow), progressTarget(ch.Config.Organization, database, branch)))
defer end()

req := &ps.MoveTablesCancelRequest{
Expand Down Expand Up @@ -464,8 +464,8 @@ func MoveTablesCompleteCmd(ch *cmdutil.Helper) *cobra.Command {
}

end := ch.Printer.PrintProgress(
fmt.Sprintf("Completing MoveTables workflow %s on %s/%s\u2026",
printer.BoldBlue(flags.workflow), printer.BoldBlue(database), printer.BoldBlue(branch)))
fmt.Sprintf("Completing MoveTables workflow %s on %s\u2026",
printer.BoldBlue(flags.workflow), progressTarget(ch.Config.Organization, database, branch)))
defer end()

req := &ps.MoveTablesCompleteRequest{
Expand Down
143 changes: 143 additions & 0 deletions internal/cmd/branch/vtctld/progress_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package vtctld

import (
"bytes"
"context"
"encoding/json"
"io"
"testing"

qt "github.com/frankban/quicktest"

"github.com/planetscale/cli/internal/cmdutil"
"github.com/planetscale/cli/internal/config"
"github.com/planetscale/cli/internal/mock"
"github.com/planetscale/cli/internal/printer"
ps "github.com/planetscale/planetscale-go/planetscale"
)

func setNonTTYProgress(t *testing.T) {
t.Helper()

previous := printer.IsTTY
printer.IsTTY = false

t.Cleanup(func() {
printer.IsTTY = previous
})
}

func newHumanProgressHelper(org string, humanOut io.Writer, client *ps.Client) *cmdutil.Helper {
format := printer.Human
p := printer.NewPrinter(&format)
p.SetHumanOutput(humanOut)
p.SetResourceOutput(io.Discard)

return &cmdutil.Helper{
Printer: p,
Config: &config.Config{Organization: org},
Client: func() (*ps.Client, error) {
return client, nil
},
}
}

func TestListWorkflowsProgressIncludesOrganization(t *testing.T) {
c := qt.New(t)
setNonTTYProgress(t)

org := "my-org"
db := "my-db"
branch := "my-branch"

svc := &mock.VtctldService{
ListWorkflowsFn: func(ctx context.Context, req *ps.VtctldListWorkflowsRequest) (json.RawMessage, error) {
return json.RawMessage(`{"workflows":[]}`), nil
},
}

var progress bytes.Buffer
ch := newHumanProgressHelper(org, &progress, &ps.Client{Vtctld: svc})

cmd := ListWorkflowsCmd(ch)
cmd.SetArgs([]string{db, branch, "--keyspace", "my-keyspace"})

err := cmd.Execute()
c.Assert(err, qt.IsNil)
c.Assert(progress.String(), qt.Contains, "Fetching workflows for my-org/my-db/my-branch…")
}

func TestStartWorkflowProgressIncludesOrganization(t *testing.T) {
c := qt.New(t)
setNonTTYProgress(t)

org := "my-org"
db := "my-db"
branch := "my-branch"

svc := &mock.VtctldService{
StartWorkflowFn: func(ctx context.Context, req *ps.VtctldStartWorkflowRequest) (json.RawMessage, error) {
return json.RawMessage(`{"summary":"started"}`), nil
},
}

var progress bytes.Buffer
ch := newHumanProgressHelper(org, &progress, &ps.Client{Vtctld: svc})

cmd := StartWorkflowCmd(ch)
cmd.SetArgs([]string{db, branch, "my-workflow", "--keyspace", "my-keyspace"})

err := cmd.Execute()
c.Assert(err, qt.IsNil)
c.Assert(progress.String(), qt.Contains, "Starting workflow my-workflow on my-org/my-db/my-branch…")
}

func TestMoveTablesShowProgressIncludesOrganization(t *testing.T) {
c := qt.New(t)
setNonTTYProgress(t)

org := "my-org"
db := "my-db"
branch := "my-branch"

svc := &mock.MoveTablesService{
ShowFn: func(ctx context.Context, req *ps.MoveTablesShowRequest) (json.RawMessage, error) {
return json.RawMessage(`{"workflow":"my-workflow"}`), nil
},
}

var progress bytes.Buffer
ch := newHumanProgressHelper(org, &progress, &ps.Client{MoveTables: svc})

cmd := MoveTablesCmd(ch)
cmd.SetArgs([]string{"show", db, branch, "--workflow", "my-workflow", "--target-keyspace", "target-ks"})

err := cmd.Execute()
c.Assert(err, qt.IsNil)
c.Assert(progress.String(), qt.Contains, "Fetching MoveTables workflow my-workflow on my-org/my-db/my-branch…")
}

func TestVDiffListProgressIncludesOrganization(t *testing.T) {
c := qt.New(t)
setNonTTYProgress(t)

org := "my-org"
db := "my-db"
branch := "my-branch"

svc := &mock.VDiffService{
ListFn: func(ctx context.Context, req *ps.VDiffListRequest) (json.RawMessage, error) {
return json.RawMessage(`{"vdiffs":[]}`), nil
},
}

var progress bytes.Buffer
ch := newHumanProgressHelper(org, &progress, &ps.Client{VDiff: svc})

cmd := VDiffCmd(ch)
cmd.SetArgs([]string{"list", db, branch, "--workflow", "my-workflow", "--target-keyspace", "target-ks"})

err := cmd.Execute()
c.Assert(err, qt.IsNil)
c.Assert(progress.String(), qt.Contains, "Fetching VDiffs for workflow my-workflow on my-org/my-db/my-branch…")
}
4 changes: 2 additions & 2 deletions internal/cmd/branch/vtctld/start_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func StartWorkflowCmd(ch *cmdutil.Helper) *cobra.Command {
}

end := ch.Printer.PrintProgress(
fmt.Sprintf("Starting workflow %s on %s/%s\u2026",
printer.BoldBlue(workflow), printer.BoldBlue(database), printer.BoldBlue(branch)))
fmt.Sprintf("Starting workflow %s on %s\u2026",
printer.BoldBlue(workflow), progressTarget(ch.Config.Organization, database, branch)))
defer end()

data, err := client.Vtctld.StartWorkflow(ctx, &ps.VtctldStartWorkflowRequest{
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/branch/vtctld/stop_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func StopWorkflowCmd(ch *cmdutil.Helper) *cobra.Command {
}

end := ch.Printer.PrintProgress(
fmt.Sprintf("Stopping workflow %s on %s/%s\u2026",
printer.BoldBlue(workflow), printer.BoldBlue(database), printer.BoldBlue(branch)))
fmt.Sprintf("Stopping workflow %s on %s\u2026",
printer.BoldBlue(workflow), progressTarget(ch.Config.Organization, database, branch)))
defer end()

data, err := client.Vtctld.StopWorkflow(ctx, &ps.VtctldStopWorkflowRequest{
Expand Down
14 changes: 14 additions & 0 deletions internal/cmd/branch/vtctld/target.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package vtctld

import (
"fmt"

"github.com/planetscale/cli/internal/printer"
)

func progressTarget(organization, database, branch string) string {
return fmt.Sprintf("%s/%s/%s",
printer.BoldBlue(organization),
printer.BoldBlue(database),
printer.BoldBlue(branch))
}
Loading
Loading