1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
//! MockClient helpers for Cloud SQL Admin API API.
//!
//! Auto-generated extension methods for ergonomic test setup.
//! **Do not edit manually** — modify the manifest and re-run codegen.
#[cfg(any(test, feature = "test-support"))]
use crate::mock_client::{ExpectationBuilder, MockClient};
/// Extension trait for MockClient with Cloud SQL Admin API helpers.
#[cfg(any(test, feature = "test-support"))]
pub trait SqladminMockHelpers {
/// Helper to expect `list_instances`: Lists instances under a given project.
fn expect_list_instances(&mut self, project: &str) -> ExpectationBuilder<'_>;
/// Helper to expect `get_instance`: Retrieves a resource containing information about a Cloud
/// SQL instance.
fn expect_get_instance(&mut self, project: &str, instance: &str) -> ExpectationBuilder<'_>;
/// Helper to expect `create_instance`: Creates a new Cloud SQL instance.
fn expect_create_instance(&mut self, project: &str) -> ExpectationBuilder<'_>;
/// Helper to expect `delete_instance`: Deletes a Cloud SQL instance.
fn expect_delete_instance(&mut self, project: &str, instance: &str) -> ExpectationBuilder<'_>;
/// Helper to expect `update_instance`: Partially updates settings of a Cloud SQL instance by
/// merging the request with the current configuration. This method supports patch semantics.
fn expect_update_instance(&mut self, project: &str, instance: &str) -> ExpectationBuilder<'_>;
/// Helper to expect `restart_instance`: Restarts a Cloud SQL instance.
fn expect_restart_instance(&mut self, project: &str, instance: &str) -> ExpectationBuilder<'_>;
/// Helper to expect `clone_instance`: Creates a Cloud SQL instance as a clone of the source
/// instance. Using this operation might cause your instance to restart.
fn expect_clone_instance(&mut self, project: &str, instance: &str) -> ExpectationBuilder<'_>;
/// Helper to expect `failover_instance`: Initiates a manual failover of a high availability
/// (HA) primary instance to a standby instance, which becomes the primary instance. Users are
/// then rerouted to the new primary. For more information, see the [Overview of high
/// availability](https://cloud.google.com/sql/docs/mysql/high-availability) page in the Cloud
/// SQL documentation. If using Legacy HA (MySQL only), this causes the instance to failover to
/// its failover replica instance.
fn expect_failover_instance(&mut self, project: &str, instance: &str)
-> ExpectationBuilder<'_>;
/// Helper to expect `promote_replica`: Promotes the read replica instance to be an independent
/// Cloud SQL primary instance. Using this operation might cause your instance to restart.
fn expect_promote_replica(&mut self, project: &str, instance: &str) -> ExpectationBuilder<'_>;
/// Helper to expect `reset_ssl_config`: Deletes all client certificates and generates a new
/// server SSL certificate for the instance.
fn expect_reset_ssl_config(&mut self, project: &str, instance: &str) -> ExpectationBuilder<'_>;
/// Helper to expect `add_server_ca`: Adds a new trusted Certificate Authority (CA) version for
/// the specified instance. Required to prepare for a certificate rotation. If a CA version was
/// previously added but never used in a certificate rotation, this operation replaces that
/// version. There cannot be more than one CA version waiting to be rotated in. For instances
/// that have enabled Certificate Authority Service (CAS) based server CA, use
/// AddServerCertificate to add a new server certificate.
fn expect_add_server_ca(&mut self, project: &str, instance: &str) -> ExpectationBuilder<'_>;
/// Helper to expect `rotate_server_ca`: Rotates the server certificate to one signed by the
/// Certificate Authority (CA) version previously added with the addServerCA method. For
/// instances that have enabled Certificate Authority Service (CAS) based server CA, use
/// RotateServerCertificate to rotate the server certificate.
fn expect_rotate_server_ca(&mut self, project: &str, instance: &str) -> ExpectationBuilder<'_>;
/// Helper to expect `import_instance`: Imports data into a Cloud SQL instance from a SQL dump
/// or CSV file in Cloud Storage.
fn expect_import_instance(&mut self, project: &str, instance: &str) -> ExpectationBuilder<'_>;
/// Helper to expect `export_instance`: Exports data from a Cloud SQL instance to a Cloud
/// Storage bucket as a SQL dump or CSV file.
fn expect_export_instance(&mut self, project: &str, instance: &str) -> ExpectationBuilder<'_>;
/// Helper to expect `create_backup_run`: Creates a new backup run on demand.
fn expect_create_backup_run(&mut self, project: &str, instance: &str)
-> ExpectationBuilder<'_>;
/// Helper to expect `list_databases`: Lists databases in the specified Cloud SQL instance.
fn expect_list_databases(&mut self, project: &str, instance: &str) -> ExpectationBuilder<'_>;
/// Helper to expect `get_database`: Retrieves a resource containing information about a
/// database inside a Cloud SQL instance.
fn expect_get_database(
&mut self,
project: &str,
instance: &str,
database: &str,
) -> ExpectationBuilder<'_>;
/// Helper to expect `create_database`: Inserts a resource containing information about a
/// database inside a Cloud SQL instance. **Note:** You can't modify the default character set
/// and collation.
fn expect_create_database(&mut self, project: &str, instance: &str) -> ExpectationBuilder<'_>;
/// Helper to expect `delete_database`: Deletes a database from a Cloud SQL instance.
fn expect_delete_database(
&mut self,
project: &str,
instance: &str,
database: &str,
) -> ExpectationBuilder<'_>;
/// Helper to expect `update_database`: Partially updates a resource containing information
/// about a database inside a Cloud SQL instance. This method supports patch semantics.
fn expect_update_database(
&mut self,
project: &str,
instance: &str,
database: &str,
) -> ExpectationBuilder<'_>;
/// Helper to expect `list_users`: Lists users in the specified Cloud SQL instance.
fn expect_list_users(&mut self, project: &str, instance: &str) -> ExpectationBuilder<'_>;
/// Helper to expect `get_user`: Retrieves a resource containing information about a user.
fn expect_get_user(
&mut self,
project: &str,
instance: &str,
name: &str,
) -> ExpectationBuilder<'_>;
/// Helper to expect `create_user`: Creates a new user in a Cloud SQL instance.
fn expect_create_user(&mut self, project: &str, instance: &str) -> ExpectationBuilder<'_>;
/// Helper to expect `delete_user`: Deletes a user from a Cloud SQL instance.
fn expect_delete_user(
&mut self,
project: &str,
instance: &str,
name: &str,
host: &str,
) -> ExpectationBuilder<'_>;
/// Helper to expect `update_user`: Updates an existing user in a Cloud SQL instance.
fn expect_update_user(
&mut self,
project: &str,
instance: &str,
name: &str,
host: &str,
) -> ExpectationBuilder<'_>;
/// Helper to expect `list_operations`: Lists all instance operations that have been performed
/// on the given Cloud SQL instance in the reverse chronological order of the start time.
fn expect_list_operations(&mut self, project: &str) -> ExpectationBuilder<'_>;
/// Helper to expect `get_operation`: Retrieves an instance operation that has been performed on
/// an instance.
fn expect_get_operation(&mut self, project: &str, operation: &str) -> ExpectationBuilder<'_>;
}
#[cfg(any(test, feature = "test-support"))]
impl SqladminMockHelpers for MockClient {
/// Helper to expect `list_instances`: Lists instances under a given project.
fn expect_list_instances(
&mut self,
project: &str,
) -> crate::mock_client::ExpectationBuilder<'_> {
let path = format!("/v1/projects/{project}/instances");
self.expect_get(&path)
}
/// Helper to expect `get_instance`: Retrieves a resource containing information about a Cloud
/// SQL instance.
fn expect_get_instance(
&mut self,
project: &str,
instance: &str,
) -> crate::mock_client::ExpectationBuilder<'_> {
let path = format!("/v1/projects/{project}/instances/{instance}");
self.expect_get(&path)
}
/// Helper to expect `create_instance`: Creates a new Cloud SQL instance.
fn expect_create_instance(
&mut self,
project: &str,
) -> crate::mock_client::ExpectationBuilder<'_> {
let path = format!("/v1/projects/{project}/instances");
self.expect_post(&path)
}
/// Helper to expect `delete_instance`: Deletes a Cloud SQL instance.
fn expect_delete_instance(
&mut self,
project: &str,
instance: &str,
) -> crate::mock_client::ExpectationBuilder<'_> {
let path = format!("/v1/projects/{project}/instances/{instance}");
self.expect_delete(&path)
}
/// Helper to expect `update_instance`: Partially updates settings of a Cloud SQL instance by
/// merging the request with the current configuration. This method supports patch semantics.
fn expect_update_instance(
&mut self,
project: &str,
instance: &str,
) -> crate::mock_client::ExpectationBuilder<'_> {
let path = format!("/v1/projects/{project}/instances/{instance}");
self.expect_patch(&path)
}
/// Helper to expect `restart_instance`: Restarts a Cloud SQL instance.
fn expect_restart_instance(
&mut self,
project: &str,
instance: &str,
) -> crate::mock_client::ExpectationBuilder<'_> {
let path = format!("/v1/projects/{project}/instances/{instance}/restart");
self.expect_post(&path)
}
/// Helper to expect `clone_instance`: Creates a Cloud SQL instance as a clone of the source
/// instance. Using this operation might cause your instance to restart.
fn expect_clone_instance(
&mut self,
project: &str,
instance: &str,
) -> crate::mock_client::ExpectationBuilder<'_> {
let path = format!("/v1/projects/{project}/instances/{instance}/clone");
self.expect_post(&path)
}
/// Helper to expect `failover_instance`: Initiates a manual failover of a high availability
/// (HA) primary instance to a standby instance, which becomes the primary instance. Users are
/// then rerouted to the new primary. For more information, see the [Overview of high
/// availability](https://cloud.google.com/sql/docs/mysql/high-availability) page in the Cloud
/// SQL documentation. If using Legacy HA (MySQL only), this causes the instance to failover to
/// its failover replica instance.
fn expect_failover_instance(
&mut self,
project: &str,
instance: &str,
) -> crate::mock_client::ExpectationBuilder<'_> {
let path = format!("/v1/projects/{project}/instances/{instance}/failover");
self.expect_post(&path)
}
/// Helper to expect `promote_replica`: Promotes the read replica instance to be an independent
/// Cloud SQL primary instance. Using this operation might cause your instance to restart.
fn expect_promote_replica(
&mut self,
project: &str,
instance: &str,
) -> crate::mock_client::ExpectationBuilder<'_> {
let path = format!("/v1/projects/{project}/instances/{instance}/promoteReplica");
self.expect_post(&path)
}
/// Helper to expect `reset_ssl_config`: Deletes all client certificates and generates a new
/// server SSL certificate for the instance.
fn expect_reset_ssl_config(
&mut self,
project: &str,
instance: &str,
) -> crate::mock_client::ExpectationBuilder<'_> {
let path = format!("/v1/projects/{project}/instances/{instance}/resetSslConfig");
self.expect_post(&path)
}
/// Helper to expect `add_server_ca`: Adds a new trusted Certificate Authority (CA) version for
/// the specified instance. Required to prepare for a certificate rotation. If a CA version was
/// previously added but never used in a certificate rotation, this operation replaces that
/// version. There cannot be more than one CA version waiting to be rotated in. For instances
/// that have enabled Certificate Authority Service (CAS) based server CA, use
/// AddServerCertificate to add a new server certificate.
fn expect_add_server_ca(
&mut self,
project: &str,
instance: &str,
) -> crate::mock_client::ExpectationBuilder<'_> {
let path = format!("/v1/projects/{project}/instances/{instance}/addServerCa");
self.expect_post(&path)
}
/// Helper to expect `rotate_server_ca`: Rotates the server certificate to one signed by the
/// Certificate Authority (CA) version previously added with the addServerCA method. For
/// instances that have enabled Certificate Authority Service (CAS) based server CA, use
/// RotateServerCertificate to rotate the server certificate.
fn expect_rotate_server_ca(
&mut self,
project: &str,
instance: &str,
) -> crate::mock_client::ExpectationBuilder<'_> {
let path = format!("/v1/projects/{project}/instances/{instance}/rotateServerCa");
self.expect_post(&path)
}
/// Helper to expect `import_instance`: Imports data into a Cloud SQL instance from a SQL dump
/// or CSV file in Cloud Storage.
fn expect_import_instance(
&mut self,
project: &str,
instance: &str,
) -> crate::mock_client::ExpectationBuilder<'_> {
let path = format!("/v1/projects/{project}/instances/{instance}/import");
self.expect_post(&path)
}
/// Helper to expect `export_instance`: Exports data from a Cloud SQL instance to a Cloud
/// Storage bucket as a SQL dump or CSV file.
fn expect_export_instance(
&mut self,
project: &str,
instance: &str,
) -> crate::mock_client::ExpectationBuilder<'_> {
let path = format!("/v1/projects/{project}/instances/{instance}/export");
self.expect_post(&path)
}
/// Helper to expect `create_backup_run`: Creates a new backup run on demand.
fn expect_create_backup_run(
&mut self,
project: &str,
instance: &str,
) -> crate::mock_client::ExpectationBuilder<'_> {
let path = format!("/v1/projects/{project}/instances/{instance}/backupRuns");
self.expect_post(&path)
}
/// Helper to expect `list_databases`: Lists databases in the specified Cloud SQL instance.
fn expect_list_databases(
&mut self,
project: &str,
instance: &str,
) -> crate::mock_client::ExpectationBuilder<'_> {
let path = format!("/v1/projects/{project}/instances/{instance}/databases");
self.expect_get(&path)
}
/// Helper to expect `get_database`: Retrieves a resource containing information about a
/// database inside a Cloud SQL instance.
fn expect_get_database(
&mut self,
project: &str,
instance: &str,
database: &str,
) -> crate::mock_client::ExpectationBuilder<'_> {
let path = format!("/v1/projects/{project}/instances/{instance}/databases/{database}");
self.expect_get(&path)
}
/// Helper to expect `create_database`: Inserts a resource containing information about a
/// database inside a Cloud SQL instance. **Note:** You can't modify the default character set
/// and collation.
fn expect_create_database(
&mut self,
project: &str,
instance: &str,
) -> crate::mock_client::ExpectationBuilder<'_> {
let path = format!("/v1/projects/{project}/instances/{instance}/databases");
self.expect_post(&path)
}
/// Helper to expect `delete_database`: Deletes a database from a Cloud SQL instance.
fn expect_delete_database(
&mut self,
project: &str,
instance: &str,
database: &str,
) -> crate::mock_client::ExpectationBuilder<'_> {
let path = format!("/v1/projects/{project}/instances/{instance}/databases/{database}");
self.expect_delete(&path)
}
/// Helper to expect `update_database`: Partially updates a resource containing information
/// about a database inside a Cloud SQL instance. This method supports patch semantics.
fn expect_update_database(
&mut self,
project: &str,
instance: &str,
database: &str,
) -> crate::mock_client::ExpectationBuilder<'_> {
let path = format!("/v1/projects/{project}/instances/{instance}/databases/{database}");
self.expect_patch(&path)
}
/// Helper to expect `list_users`: Lists users in the specified Cloud SQL instance.
fn expect_list_users(
&mut self,
project: &str,
instance: &str,
) -> crate::mock_client::ExpectationBuilder<'_> {
let path = format!("/v1/projects/{project}/instances/{instance}/users");
self.expect_get(&path)
}
/// Helper to expect `get_user`: Retrieves a resource containing information about a user.
fn expect_get_user(
&mut self,
project: &str,
instance: &str,
name: &str,
) -> crate::mock_client::ExpectationBuilder<'_> {
let path = format!("/v1/projects/{project}/instances/{instance}/users/{name}");
self.expect_get(&path)
}
/// Helper to expect `create_user`: Creates a new user in a Cloud SQL instance.
fn expect_create_user(
&mut self,
project: &str,
instance: &str,
) -> crate::mock_client::ExpectationBuilder<'_> {
let path = format!("/v1/projects/{project}/instances/{instance}/users");
self.expect_post(&path)
}
/// Helper to expect `delete_user`: Deletes a user from a Cloud SQL instance.
fn expect_delete_user(
&mut self,
project: &str,
instance: &str,
name: &str,
host: &str,
) -> crate::mock_client::ExpectationBuilder<'_> {
let mut path = format!("/v1/projects/{project}/instances/{instance}/users");
let mut __qp: Vec<String> = Vec::new();
if !name.is_empty() {
__qp.push(format!("name={}", name));
}
if !host.is_empty() {
__qp.push(format!("host={}", host));
}
if !__qp.is_empty() {
path = format!("{}?{}", path, __qp.join("&"));
}
self.expect_delete(&path)
}
/// Helper to expect `update_user`: Updates an existing user in a Cloud SQL instance.
fn expect_update_user(
&mut self,
project: &str,
instance: &str,
name: &str,
host: &str,
) -> crate::mock_client::ExpectationBuilder<'_> {
let mut path = format!("/v1/projects/{project}/instances/{instance}/users");
let mut __qp: Vec<String> = Vec::new();
if !name.is_empty() {
__qp.push(format!("name={}", name));
}
if !host.is_empty() {
__qp.push(format!("host={}", host));
}
if !__qp.is_empty() {
path = format!("{}?{}", path, __qp.join("&"));
}
self.expect_put(&path)
}
/// Helper to expect `list_operations`: Lists all instance operations that have been performed
/// on the given Cloud SQL instance in the reverse chronological order of the start time.
fn expect_list_operations(
&mut self,
project: &str,
) -> crate::mock_client::ExpectationBuilder<'_> {
let path = format!("/v1/projects/{project}/operations");
self.expect_get(&path)
}
/// Helper to expect `get_operation`: Retrieves an instance operation that has been performed on
/// an instance.
fn expect_get_operation(
&mut self,
project: &str,
operation: &str,
) -> crate::mock_client::ExpectationBuilder<'_> {
let path = format!("/v1/projects/{project}/operations/{operation}");
self.expect_get(&path)
}
}