@@ -32,6 +32,7 @@ func TestDatabase_CreateCmd(t *testing.T) {
3232 c .Assert (req .Organization , qt .Equals , org )
3333 c .Assert (req .Name , qt .Equals , db )
3434 c .Assert (req .Region , qt .Equals , "us-east" )
35+ c .Assert (req .Replicas , qt .IsNil ) // Should be nil when not set
3536
3637 return res , nil
3738 },
@@ -66,6 +67,60 @@ func TestDatabase_CreateCmd(t *testing.T) {
6667 c .Assert (buf .String (), qt .JSONEquals , res )
6768}
6869
70+ func TestDatabase_CreateCmdWithReplicasZero (t * testing.T ) {
71+ c := qt .New (t )
72+
73+ var buf bytes.Buffer
74+ format := printer .JSON
75+ p := printer .NewPrinter (& format )
76+ p .SetResourceOutput (& buf )
77+
78+ org := "planetscale"
79+ db := "planetscale"
80+
81+ res := & ps.Database {Name : "foo" }
82+
83+ svc := & mock.DatabaseService {
84+ CreateFn : func (ctx context.Context , req * ps.CreateDatabaseRequest ) (* ps.Database , error ) {
85+ c .Assert (req .Organization , qt .Equals , org )
86+ c .Assert (req .Name , qt .Equals , db )
87+ c .Assert (req .Region , qt .Equals , "us-east" )
88+ c .Assert (req .Replicas , qt .IsNotNil ) // Should be set when explicitly passed
89+ c .Assert (* req .Replicas , qt .Equals , 0 ) // Should be 0
90+
91+ return res , nil
92+ },
93+ }
94+
95+ ch := & cmdutil.Helper {
96+ Printer : p ,
97+ Config : & config.Config {
98+ Organization : org ,
99+ },
100+ Client : func () (* ps.Client , error ) {
101+ return & ps.Client {
102+ Databases : svc ,
103+ Organizations : & mock.OrganizationsService {
104+ GetFn : func (ctx context.Context , request * ps.GetOrganizationRequest ) (* ps.Organization , error ) {
105+ return & ps.Organization {
106+ RemainingFreeDatabases : 1 ,
107+ Name : request .Organization ,
108+ }, nil
109+ },
110+ },
111+ }, nil
112+ },
113+ }
114+
115+ cmd := CreateCmd (ch )
116+ cmd .SetArgs ([]string {db , "--region" , "us-east" , "--replicas" , "0" })
117+ err := cmd .Execute ()
118+
119+ c .Assert (err , qt .IsNil )
120+ c .Assert (svc .CreateFnInvoked , qt .IsTrue )
121+ c .Assert (buf .String (), qt .JSONEquals , res )
122+ }
123+
69124func TestDatabase_CreateCmdPostgres (t * testing.T ) {
70125 c := qt .New (t )
71126
@@ -118,3 +173,57 @@ func TestDatabase_CreateCmdPostgres(t *testing.T) {
118173 c .Assert (svc .CreateFnInvoked , qt .IsTrue )
119174 c .Assert (buf .String (), qt .JSONEquals , res )
120175}
176+
177+ func TestDatabase_CreateCmdWithReplicas (t * testing.T ) {
178+ c := qt .New (t )
179+
180+ var buf bytes.Buffer
181+ format := printer .JSON
182+ p := printer .NewPrinter (& format )
183+ p .SetResourceOutput (& buf )
184+
185+ org := "planetscale"
186+ db := "planetscale"
187+
188+ res := & ps.Database {Name : "foo" }
189+
190+ svc := & mock.DatabaseService {
191+ CreateFn : func (ctx context.Context , req * ps.CreateDatabaseRequest ) (* ps.Database , error ) {
192+ c .Assert (req .Organization , qt .Equals , org )
193+ c .Assert (req .Name , qt .Equals , db )
194+ c .Assert (req .Region , qt .Equals , "us-east" )
195+ c .Assert (req .Replicas , qt .IsNotNil )
196+ c .Assert (* req .Replicas , qt .Equals , 3 )
197+
198+ return res , nil
199+ },
200+ }
201+
202+ ch := & cmdutil.Helper {
203+ Printer : p ,
204+ Config : & config.Config {
205+ Organization : org ,
206+ },
207+ Client : func () (* ps.Client , error ) {
208+ return & ps.Client {
209+ Databases : svc ,
210+ Organizations : & mock.OrganizationsService {
211+ GetFn : func (ctx context.Context , request * ps.GetOrganizationRequest ) (* ps.Organization , error ) {
212+ return & ps.Organization {
213+ RemainingFreeDatabases : 1 ,
214+ Name : request .Organization ,
215+ }, nil
216+ },
217+ },
218+ }, nil
219+ },
220+ }
221+
222+ cmd := CreateCmd (ch )
223+ cmd .SetArgs ([]string {db , "--region" , "us-east" , "--replicas" , "3" })
224+ err := cmd .Execute ()
225+
226+ c .Assert (err , qt .IsNil )
227+ c .Assert (svc .CreateFnInvoked , qt .IsTrue )
228+ c .Assert (buf .String (), qt .JSONEquals , res )
229+ }
0 commit comments