@@ -135,7 +135,7 @@ func TestDeployRequest_EditCmdNoFlags(t *testing.T) {
135135 cmd .SetArgs ([]string {db , strconv .FormatUint (number , 10 )})
136136 err := cmd .Execute ()
137137
138- c .Assert (err , qt .ErrorMatches , "must specify either --enable-auto-apply or --disable-auto-apply" )
138+ c .Assert (err , qt .ErrorMatches , "must specify either --enable-auto-apply, --disable-auto-apply, or - -auto-apply" )
139139}
140140
141141func TestDeployRequest_EditCmdBothFlags (t * testing.T ) {
@@ -166,3 +166,144 @@ func TestDeployRequest_EditCmdBothFlags(t *testing.T) {
166166
167167 c .Assert (err , qt .ErrorMatches , "cannot use both --enable-auto-apply and --disable-auto-apply flags together" )
168168}
169+
170+ func TestDeployRequest_EditCmdDeprecatedAutoApplyEnable (t * testing.T ) {
171+ c := qt .New (t )
172+
173+ var buf bytes.Buffer
174+ format := printer .JSON
175+ p := printer .NewPrinter (& format )
176+ p .SetResourceOutput (& buf )
177+
178+ org := "planetscale"
179+ db := "planetscale"
180+ number := uint64 (10 )
181+ enable := true
182+
183+ svc := & mock.DeployRequestsService {
184+ AutoApplyFn : func (ctx context.Context , req * ps.AutoApplyDeployRequestRequest ) (* ps.DeployRequest , error ) {
185+ c .Assert (req .Number , qt .Equals , number )
186+ c .Assert (req .Database , qt .Equals , db )
187+ c .Assert (req .Organization , qt .Equals , org )
188+ c .Assert (req .Enable , qt .Equals , enable )
189+
190+ return & ps.DeployRequest {Number : number }, nil
191+ },
192+ }
193+
194+ ch := & cmdutil.Helper {
195+ Printer : p ,
196+ Config : & config.Config {
197+ Organization : org ,
198+ },
199+ Client : func () (* ps.Client , error ) {
200+ return & ps.Client {
201+ DeployRequests : svc ,
202+ }, nil
203+ },
204+ }
205+
206+ cmd := EditCmd (ch )
207+ cmd .SetArgs ([]string {db , strconv .FormatUint (number , 10 ), "--auto-apply=enable" })
208+ err := cmd .Execute ()
209+
210+ c .Assert (err , qt .IsNil )
211+ c .Assert (svc .AutoApplyFnInvoked , qt .IsTrue )
212+
213+ res := & ps.DeployRequest {Number : number }
214+ c .Assert (buf .String (), qt .JSONEquals , res )
215+ }
216+
217+ func TestDeployRequest_EditCmdDeprecatedAutoApplyDisable (t * testing.T ) {
218+ c := qt .New (t )
219+
220+ var buf bytes.Buffer
221+ format := printer .JSON
222+ p := printer .NewPrinter (& format )
223+ p .SetResourceOutput (& buf )
224+
225+ org := "planetscale"
226+ db := "planetscale"
227+ number := uint64 (10 )
228+ enable := false
229+
230+ svc := & mock.DeployRequestsService {
231+ AutoApplyFn : func (ctx context.Context , req * ps.AutoApplyDeployRequestRequest ) (* ps.DeployRequest , error ) {
232+ c .Assert (req .Number , qt .Equals , number )
233+ c .Assert (req .Database , qt .Equals , db )
234+ c .Assert (req .Organization , qt .Equals , org )
235+ c .Assert (req .Enable , qt .Equals , enable )
236+
237+ return & ps.DeployRequest {Number : number }, nil
238+ },
239+ }
240+
241+ ch := & cmdutil.Helper {
242+ Printer : p ,
243+ Config : & config.Config {
244+ Organization : org ,
245+ },
246+ Client : func () (* ps.Client , error ) {
247+ return & ps.Client {
248+ DeployRequests : svc ,
249+ }, nil
250+ },
251+ }
252+
253+ cmd := EditCmd (ch )
254+ cmd .SetArgs ([]string {db , strconv .FormatUint (number , 10 ), "--auto-apply=disable" })
255+ err := cmd .Execute ()
256+
257+ c .Assert (err , qt .IsNil )
258+ c .Assert (svc .AutoApplyFnInvoked , qt .IsTrue )
259+
260+ res := & ps.DeployRequest {Number : number }
261+ c .Assert (buf .String (), qt .JSONEquals , res )
262+ }
263+
264+ func TestDeployRequest_EditCmdMixedFlags (t * testing.T ) {
265+ c := qt .New (t )
266+
267+ var buf bytes.Buffer
268+ format := printer .JSON
269+ p := printer .NewPrinter (& format )
270+ p .SetResourceOutput (& buf )
271+
272+ org := "planetscale"
273+ db := "planetscale"
274+ number := uint64 (10 )
275+ enable := true // Should use --enable-auto-apply and ignore --auto-apply
276+
277+ svc := & mock.DeployRequestsService {
278+ AutoApplyFn : func (ctx context.Context , req * ps.AutoApplyDeployRequestRequest ) (* ps.DeployRequest , error ) {
279+ c .Assert (req .Number , qt .Equals , number )
280+ c .Assert (req .Database , qt .Equals , db )
281+ c .Assert (req .Organization , qt .Equals , org )
282+ c .Assert (req .Enable , qt .Equals , enable )
283+
284+ return & ps.DeployRequest {Number : number }, nil
285+ },
286+ }
287+
288+ ch := & cmdutil.Helper {
289+ Printer : p ,
290+ Config : & config.Config {
291+ Organization : org ,
292+ },
293+ Client : func () (* ps.Client , error ) {
294+ return & ps.Client {
295+ DeployRequests : svc ,
296+ }, nil
297+ },
298+ }
299+
300+ cmd := EditCmd (ch )
301+ cmd .SetArgs ([]string {db , strconv .FormatUint (number , 10 ), "--enable-auto-apply" , "--auto-apply=disable" })
302+ err := cmd .Execute ()
303+
304+ c .Assert (err , qt .IsNil )
305+ c .Assert (svc .AutoApplyFnInvoked , qt .IsTrue )
306+
307+ res := & ps.DeployRequest {Number : number }
308+ c .Assert (buf .String (), qt .JSONEquals , res )
309+ }
0 commit comments