@@ -33,6 +33,7 @@ func TestBackup_CreateCmd(t *testing.T) {
3333 c .Assert (req .Organization , qt .Equals , org )
3434 c .Assert (req .Database , qt .Equals , db )
3535 c .Assert (req .Branch , qt .Equals , branch )
36+ c .Assert (req .Name , qt .Equals , "" )
3637
3738 return res , nil
3839 },
@@ -58,3 +59,50 @@ func TestBackup_CreateCmd(t *testing.T) {
5859 c .Assert (svc .CreateFnInvoked , qt .IsTrue )
5960 c .Assert (buf .String (), qt .JSONEquals , res )
6061}
62+
63+ func TestBackup_CreateCmdWithName (t * testing.T ) {
64+ c := qt .New (t )
65+
66+ var buf bytes.Buffer
67+ format := printer .JSON
68+ p := printer .NewPrinter (& format )
69+ p .SetResourceOutput (& buf )
70+
71+ org := "planetscale"
72+ db := "planetscale"
73+ branch := "development"
74+ name := "my-backup"
75+
76+ res := & ps.Backup {Name : "foo" }
77+
78+ svc := & mock.BackupsService {
79+ CreateFn : func (ctx context.Context , req * ps.CreateBackupRequest ) (* ps.Backup , error ) {
80+ c .Assert (req .Organization , qt .Equals , org )
81+ c .Assert (req .Database , qt .Equals , db )
82+ c .Assert (req .Branch , qt .Equals , branch )
83+ c .Assert (req .Name , qt .Equals , name )
84+
85+ return res , nil
86+ },
87+ }
88+
89+ ch := & cmdutil.Helper {
90+ Printer : p ,
91+ Config : & config.Config {
92+ Organization : org ,
93+ },
94+ Client : func () (* ps.Client , error ) {
95+ return & ps.Client {
96+ Backups : svc ,
97+ }, nil
98+ },
99+ }
100+
101+ cmd := CreateCmd (ch )
102+ cmd .SetArgs ([]string {db , branch , "--name" , name })
103+ err := cmd .Execute ()
104+
105+ c .Assert (err , qt .IsNil )
106+ c .Assert (svc .CreateFnInvoked , qt .IsTrue )
107+ c .Assert (buf .String (), qt .JSONEquals , res )
108+ }
0 commit comments