Skip to content

Commit 038eca9

Browse files
authored
Merge branch 'main' into nickvanw/vtctld-get-workflows-include-logs
2 parents 3e3ae69 + 04bd267 commit 038eca9

10 files changed

Lines changed: 213 additions & 58 deletions

File tree

internal/cmd/branch/vtctld/keyspaces.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55

66
"github.com/planetscale/cli/internal/cmdutil"
7-
"github.com/planetscale/cli/internal/printer"
87
ps "github.com/planetscale/planetscale-go/planetscale"
98
"github.com/spf13/cobra"
109
)
@@ -28,8 +27,8 @@ func ListKeyspacesCmd(ch *cmdutil.Helper) *cobra.Command {
2827
}
2928

3029
end := ch.Printer.PrintProgress(
31-
fmt.Sprintf("Fetching keyspaces for %s/%s\u2026",
32-
printer.BoldBlue(database), printer.BoldBlue(branch)))
30+
fmt.Sprintf("Fetching keyspaces for %s\u2026",
31+
progressTarget(ch.Config.Organization, database, branch)))
3332
defer end()
3433

3534
data, err := client.Vtctld.ListKeyspaces(ctx, &ps.VtctldListKeyspacesRequest{

internal/cmd/branch/vtctld/lookup_vindex.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ func LookupVindexCreateCmd(ch *cmdutil.Helper) *cobra.Command {
5656
}
5757

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

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

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

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

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

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

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

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

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

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

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

348348
data, err := client.LookupVindex.Complete(ctx, &ps.LookupVindexCompleteRequest{

internal/cmd/branch/vtctld/materialize.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ func MaterializeCreateCmd(ch *cmdutil.Helper) *cobra.Command {
5656
}
5757

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

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

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

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

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

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

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

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

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

304304
req := &ps.MaterializeCancelRequest{

internal/cmd/branch/vtctld/move_tables.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ func MoveTablesCreateCmd(ch *cmdutil.Helper) *cobra.Command {
6969
}
7070

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

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

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

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

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

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

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

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

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

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

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

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

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

471471
req := &ps.MoveTablesCompleteRequest{
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
package vtctld
2+
3+
import (
4+
"bytes"
5+
"context"
6+
"encoding/json"
7+
"io"
8+
"testing"
9+
10+
qt "github.com/frankban/quicktest"
11+
12+
"github.com/planetscale/cli/internal/cmdutil"
13+
"github.com/planetscale/cli/internal/config"
14+
"github.com/planetscale/cli/internal/mock"
15+
"github.com/planetscale/cli/internal/printer"
16+
ps "github.com/planetscale/planetscale-go/planetscale"
17+
)
18+
19+
func setNonTTYProgress(t *testing.T) {
20+
t.Helper()
21+
22+
previous := printer.IsTTY
23+
printer.IsTTY = false
24+
25+
t.Cleanup(func() {
26+
printer.IsTTY = previous
27+
})
28+
}
29+
30+
func newHumanProgressHelper(org string, humanOut io.Writer, client *ps.Client) *cmdutil.Helper {
31+
format := printer.Human
32+
p := printer.NewPrinter(&format)
33+
p.SetHumanOutput(humanOut)
34+
p.SetResourceOutput(io.Discard)
35+
36+
return &cmdutil.Helper{
37+
Printer: p,
38+
Config: &config.Config{Organization: org},
39+
Client: func() (*ps.Client, error) {
40+
return client, nil
41+
},
42+
}
43+
}
44+
45+
func TestListWorkflowsProgressIncludesOrganization(t *testing.T) {
46+
c := qt.New(t)
47+
setNonTTYProgress(t)
48+
49+
org := "my-org"
50+
db := "my-db"
51+
branch := "my-branch"
52+
53+
svc := &mock.VtctldService{
54+
ListWorkflowsFn: func(ctx context.Context, req *ps.VtctldListWorkflowsRequest) (json.RawMessage, error) {
55+
return json.RawMessage(`{"workflows":[]}`), nil
56+
},
57+
}
58+
59+
var progress bytes.Buffer
60+
ch := newHumanProgressHelper(org, &progress, &ps.Client{Vtctld: svc})
61+
62+
cmd := ListWorkflowsCmd(ch)
63+
cmd.SetArgs([]string{db, branch, "--keyspace", "my-keyspace"})
64+
65+
err := cmd.Execute()
66+
c.Assert(err, qt.IsNil)
67+
c.Assert(progress.String(), qt.Contains, "Fetching workflows for my-org/my-db/my-branch…")
68+
}
69+
70+
func TestStartWorkflowProgressIncludesOrganization(t *testing.T) {
71+
c := qt.New(t)
72+
setNonTTYProgress(t)
73+
74+
org := "my-org"
75+
db := "my-db"
76+
branch := "my-branch"
77+
78+
svc := &mock.VtctldService{
79+
StartWorkflowFn: func(ctx context.Context, req *ps.VtctldStartWorkflowRequest) (json.RawMessage, error) {
80+
return json.RawMessage(`{"summary":"started"}`), nil
81+
},
82+
}
83+
84+
var progress bytes.Buffer
85+
ch := newHumanProgressHelper(org, &progress, &ps.Client{Vtctld: svc})
86+
87+
cmd := StartWorkflowCmd(ch)
88+
cmd.SetArgs([]string{db, branch, "my-workflow", "--keyspace", "my-keyspace"})
89+
90+
err := cmd.Execute()
91+
c.Assert(err, qt.IsNil)
92+
c.Assert(progress.String(), qt.Contains, "Starting workflow my-workflow on my-org/my-db/my-branch…")
93+
}
94+
95+
func TestMoveTablesShowProgressIncludesOrganization(t *testing.T) {
96+
c := qt.New(t)
97+
setNonTTYProgress(t)
98+
99+
org := "my-org"
100+
db := "my-db"
101+
branch := "my-branch"
102+
103+
svc := &mock.MoveTablesService{
104+
ShowFn: func(ctx context.Context, req *ps.MoveTablesShowRequest) (json.RawMessage, error) {
105+
return json.RawMessage(`{"workflow":"my-workflow"}`), nil
106+
},
107+
}
108+
109+
var progress bytes.Buffer
110+
ch := newHumanProgressHelper(org, &progress, &ps.Client{MoveTables: svc})
111+
112+
cmd := MoveTablesCmd(ch)
113+
cmd.SetArgs([]string{"show", db, branch, "--workflow", "my-workflow", "--target-keyspace", "target-ks"})
114+
115+
err := cmd.Execute()
116+
c.Assert(err, qt.IsNil)
117+
c.Assert(progress.String(), qt.Contains, "Fetching MoveTables workflow my-workflow on my-org/my-db/my-branch…")
118+
}
119+
120+
func TestVDiffListProgressIncludesOrganization(t *testing.T) {
121+
c := qt.New(t)
122+
setNonTTYProgress(t)
123+
124+
org := "my-org"
125+
db := "my-db"
126+
branch := "my-branch"
127+
128+
svc := &mock.VDiffService{
129+
ListFn: func(ctx context.Context, req *ps.VDiffListRequest) (json.RawMessage, error) {
130+
return json.RawMessage(`{"vdiffs":[]}`), nil
131+
},
132+
}
133+
134+
var progress bytes.Buffer
135+
ch := newHumanProgressHelper(org, &progress, &ps.Client{VDiff: svc})
136+
137+
cmd := VDiffCmd(ch)
138+
cmd.SetArgs([]string{"list", db, branch, "--workflow", "my-workflow", "--target-keyspace", "target-ks"})
139+
140+
err := cmd.Execute()
141+
c.Assert(err, qt.IsNil)
142+
c.Assert(progress.String(), qt.Contains, "Fetching VDiffs for workflow my-workflow on my-org/my-db/my-branch…")
143+
}

internal/cmd/branch/vtctld/start_workflow.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ func StartWorkflowCmd(ch *cmdutil.Helper) *cobra.Command {
2828
}
2929

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

3535
data, err := client.Vtctld.StartWorkflow(ctx, &ps.VtctldStartWorkflowRequest{

internal/cmd/branch/vtctld/stop_workflow.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ func StopWorkflowCmd(ch *cmdutil.Helper) *cobra.Command {
2828
}
2929

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

3535
data, err := client.Vtctld.StopWorkflow(ctx, &ps.VtctldStopWorkflowRequest{
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package vtctld
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/planetscale/cli/internal/printer"
7+
)
8+
9+
func progressTarget(organization, database, branch string) string {
10+
return fmt.Sprintf("%s/%s/%s",
11+
printer.BoldBlue(organization),
12+
printer.BoldBlue(database),
13+
printer.BoldBlue(branch))
14+
}

0 commit comments

Comments
 (0)