gcp-lite-rs 0.1.1

Lightweight HTTP client for Google Cloud Platform APIs
Documentation
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
//! MockClient helpers for BigQuery 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 BigQuery helpers.
#[cfg(any(test, feature = "test-support"))]
pub trait BigqueryMockHelpers {
    /// Helper to expect `get_dataset`: Returns the dataset specified by datasetID.
    fn expect_get_dataset(&mut self, project_id: &str, dataset_id: &str) -> ExpectationBuilder<'_>;

    /// Helper to expect `list_datasets`: Lists all datasets in the specified project to which the
    /// user has been granted the READER dataset role.
    fn expect_list_datasets(
        &mut self,
        project_id: &str,
        all: &str,
        filter: &str,
        max_results: &str,
        page_token: &str,
    ) -> ExpectationBuilder<'_>;

    /// Helper to expect `create_dataset`: Creates a new empty dataset.
    fn expect_create_dataset(&mut self, project_id: &str) -> ExpectationBuilder<'_>;

    /// Helper to expect `delete_dataset`: Deletes the dataset specified by the datasetId value.
    /// Before you can delete a dataset, you must delete all its tables, either manually or by
    /// specifying deleteContents. Immediately after deletion, you can create another dataset with
    /// the same name.
    fn expect_delete_dataset(
        &mut self,
        project_id: &str,
        dataset_id: &str,
        delete_contents: &str,
    ) -> ExpectationBuilder<'_>;

    /// Helper to expect `patch_dataset`: Updates information in an existing dataset. The update
    /// method replaces the entire dataset resource, whereas the patch method only replaces fields
    /// that are provided in the submitted dataset resource. This method supports RFC5789 patch
    /// semantics.
    fn expect_patch_dataset(
        &mut self,
        project_id: &str,
        dataset_id: &str,
    ) -> ExpectationBuilder<'_>;

    /// Helper to expect `get_table`: Gets the specified table resource by table ID. This method
    /// does not return the data in the table, it only returns the table resource, which describes
    /// the structure of this table.
    fn expect_get_table(
        &mut self,
        project_id: &str,
        dataset_id: &str,
        table_id: &str,
    ) -> ExpectationBuilder<'_>;

    /// Helper to expect `list_tables`: Lists all tables in the specified dataset. Requires the
    /// READER dataset role.
    fn expect_list_tables(
        &mut self,
        project_id: &str,
        dataset_id: &str,
        max_results: &str,
        page_token: &str,
    ) -> ExpectationBuilder<'_>;

    /// Helper to expect `create_table`: Creates a new, empty table in the dataset.
    fn expect_create_table(&mut self, project_id: &str, dataset_id: &str)
    -> ExpectationBuilder<'_>;

    /// Helper to expect `delete_table`: Deletes the table specified by tableId from the dataset. If
    /// the table contains data, all the data will be deleted.
    fn expect_delete_table(
        &mut self,
        project_id: &str,
        dataset_id: &str,
        table_id: &str,
    ) -> ExpectationBuilder<'_>;

    /// Helper to expect `patch_table`: Updates information in an existing table. The update method
    /// replaces the entire table resource, whereas the patch method only replaces fields that are
    /// provided in the submitted table resource. This method supports RFC5789 patch semantics.
    fn expect_patch_table(
        &mut self,
        project_id: &str,
        dataset_id: &str,
        table_id: &str,
    ) -> ExpectationBuilder<'_>;

    /// Helper to expect `query_jobs`: Runs a BigQuery SQL query synchronously and returns query
    /// results if the query completes within a specified timeout.
    fn expect_query_jobs(&mut self, project_id: &str) -> ExpectationBuilder<'_>;

    /// Helper to expect `insert_job`: Starts a new asynchronous job. This API has two different
    /// kinds of endpoint URIs, as this method supports a variety of use cases.
    /// * The *Metadata* URI is used for most interactions, as it accepts the job configuration
    ///   directly.
    /// * The *Upload* URI is ONLY for the case when you're sending both a load job configuration
    ///   and a data stream together. In this case, the Upload URI accepts the job configuration and
    ///   the data as two distinct multipart MIME parts.
    fn expect_insert_job(&mut self, project_id: &str) -> ExpectationBuilder<'_>;

    /// Helper to expect `get_job`: Returns information about a specific job. Job information is
    /// available for a six month period after creation. Requires that you're the person who ran the
    /// job, or have the Is Owner project role.
    fn expect_get_job(
        &mut self,
        project_id: &str,
        job_id: &str,
        location: &str,
    ) -> ExpectationBuilder<'_>;

    /// Helper to expect `list_jobs`: Lists all jobs that you started in the specified project. Job
    /// information is available for a six month period after creation. The job list is sorted in
    /// reverse chronological order, by job creation time. Requires the Can View project role, or
    /// the Is Owner project role if you set the allUsers property.
    #[allow(clippy::too_many_arguments)]
    fn expect_list_jobs(
        &mut self,
        project_id: &str,
        all_users: &str,
        state_filter: &[&str],
        max_results: &str,
        page_token: &str,
        projection: &str,
        parent_job_id: &str,
        min_creation_time: &str,
        max_creation_time: &str,
    ) -> ExpectationBuilder<'_>;

    /// Helper to expect `cancel_job`: Requests that a job be cancelled. This call will return
    /// immediately, and the client will need to poll for the job status to see if the cancel
    /// completed successfully. Cancelled jobs may still incur costs.
    fn expect_cancel_job(
        &mut self,
        project_id: &str,
        job_id: &str,
        location: &str,
    ) -> ExpectationBuilder<'_>;

    /// Helper to expect `delete_job`: Requests the deletion of the metadata of a job. This call
    /// returns when the job's metadata is deleted.
    fn expect_delete_job(
        &mut self,
        project_id: &str,
        job_id: &str,
        location: &str,
    ) -> ExpectationBuilder<'_>;
}

#[cfg(any(test, feature = "test-support"))]
impl BigqueryMockHelpers for MockClient {
    /// Helper to expect `get_dataset`: Returns the dataset specified by datasetID.
    fn expect_get_dataset(
        &mut self,
        project_id: &str,
        dataset_id: &str,
    ) -> crate::mock_client::ExpectationBuilder<'_> {
        let path = format!("/bigquery/v2/projects/{project_id}/datasets/{dataset_id}");
        self.expect_get(&path)
    }

    /// Helper to expect `list_datasets`: Lists all datasets in the specified project to which the
    /// user has been granted the READER dataset role.
    fn expect_list_datasets(
        &mut self,
        project_id: &str,
        all: &str,
        filter: &str,
        max_results: &str,
        page_token: &str,
    ) -> crate::mock_client::ExpectationBuilder<'_> {
        let mut path = format!("/bigquery/v2/projects/{project_id}/datasets");
        let mut __qp: Vec<String> = Vec::new();
        if !all.is_empty() {
            __qp.push(format!("all={}", all));
        }
        if !filter.is_empty() {
            __qp.push(format!("filter={}", filter));
        }
        if !max_results.is_empty() {
            __qp.push(format!("maxResults={}", max_results));
        }
        if !page_token.is_empty() {
            __qp.push(format!("pageToken={}", page_token));
        }
        if !__qp.is_empty() {
            path = format!("{}?{}", path, __qp.join("&"));
        }
        self.expect_get(&path)
    }

    /// Helper to expect `create_dataset`: Creates a new empty dataset.
    fn expect_create_dataset(
        &mut self,
        project_id: &str,
    ) -> crate::mock_client::ExpectationBuilder<'_> {
        let path = format!("/bigquery/v2/projects/{project_id}/datasets");
        self.expect_post(&path)
    }

    /// Helper to expect `delete_dataset`: Deletes the dataset specified by the datasetId value.
    /// Before you can delete a dataset, you must delete all its tables, either manually or by
    /// specifying deleteContents. Immediately after deletion, you can create another dataset with
    /// the same name.
    fn expect_delete_dataset(
        &mut self,
        project_id: &str,
        dataset_id: &str,
        delete_contents: &str,
    ) -> crate::mock_client::ExpectationBuilder<'_> {
        let mut path = format!("/bigquery/v2/projects/{project_id}/datasets/{dataset_id}");
        let mut __qp: Vec<String> = Vec::new();
        if !delete_contents.is_empty() {
            __qp.push(format!("deleteContents={}", delete_contents));
        }
        if !__qp.is_empty() {
            path = format!("{}?{}", path, __qp.join("&"));
        }
        self.expect_delete(&path)
    }

    /// Helper to expect `patch_dataset`: Updates information in an existing dataset. The update
    /// method replaces the entire dataset resource, whereas the patch method only replaces fields
    /// that are provided in the submitted dataset resource. This method supports RFC5789 patch
    /// semantics.
    fn expect_patch_dataset(
        &mut self,
        project_id: &str,
        dataset_id: &str,
    ) -> crate::mock_client::ExpectationBuilder<'_> {
        let path = format!("/bigquery/v2/projects/{project_id}/datasets/{dataset_id}");
        self.expect_patch(&path)
    }

    /// Helper to expect `get_table`: Gets the specified table resource by table ID. This method
    /// does not return the data in the table, it only returns the table resource, which describes
    /// the structure of this table.
    fn expect_get_table(
        &mut self,
        project_id: &str,
        dataset_id: &str,
        table_id: &str,
    ) -> crate::mock_client::ExpectationBuilder<'_> {
        let path =
            format!("/bigquery/v2/projects/{project_id}/datasets/{dataset_id}/tables/{table_id}");
        self.expect_get(&path)
    }

    /// Helper to expect `list_tables`: Lists all tables in the specified dataset. Requires the
    /// READER dataset role.
    fn expect_list_tables(
        &mut self,
        project_id: &str,
        dataset_id: &str,
        max_results: &str,
        page_token: &str,
    ) -> crate::mock_client::ExpectationBuilder<'_> {
        let mut path = format!("/bigquery/v2/projects/{project_id}/datasets/{dataset_id}/tables");
        let mut __qp: Vec<String> = Vec::new();
        if !max_results.is_empty() {
            __qp.push(format!("maxResults={}", max_results));
        }
        if !page_token.is_empty() {
            __qp.push(format!("pageToken={}", page_token));
        }
        if !__qp.is_empty() {
            path = format!("{}?{}", path, __qp.join("&"));
        }
        self.expect_get(&path)
    }

    /// Helper to expect `create_table`: Creates a new, empty table in the dataset.
    fn expect_create_table(
        &mut self,
        project_id: &str,
        dataset_id: &str,
    ) -> crate::mock_client::ExpectationBuilder<'_> {
        let path = format!("/bigquery/v2/projects/{project_id}/datasets/{dataset_id}/tables");
        self.expect_post(&path)
    }

    /// Helper to expect `delete_table`: Deletes the table specified by tableId from the dataset. If
    /// the table contains data, all the data will be deleted.
    fn expect_delete_table(
        &mut self,
        project_id: &str,
        dataset_id: &str,
        table_id: &str,
    ) -> crate::mock_client::ExpectationBuilder<'_> {
        let path =
            format!("/bigquery/v2/projects/{project_id}/datasets/{dataset_id}/tables/{table_id}");
        self.expect_delete(&path)
    }

    /// Helper to expect `patch_table`: Updates information in an existing table. The update method
    /// replaces the entire table resource, whereas the patch method only replaces fields that are
    /// provided in the submitted table resource. This method supports RFC5789 patch semantics.
    fn expect_patch_table(
        &mut self,
        project_id: &str,
        dataset_id: &str,
        table_id: &str,
    ) -> crate::mock_client::ExpectationBuilder<'_> {
        let path =
            format!("/bigquery/v2/projects/{project_id}/datasets/{dataset_id}/tables/{table_id}");
        self.expect_patch(&path)
    }

    /// Helper to expect `query_jobs`: Runs a BigQuery SQL query synchronously and returns query
    /// results if the query completes within a specified timeout.
    fn expect_query_jobs(
        &mut self,
        project_id: &str,
    ) -> crate::mock_client::ExpectationBuilder<'_> {
        let path = format!("/bigquery/v2/projects/{project_id}/queries");
        self.expect_post(&path)
    }

    /// Helper to expect `insert_job`: Starts a new asynchronous job. This API has two different
    /// kinds of endpoint URIs, as this method supports a variety of use cases.
    /// * The *Metadata* URI is used for most interactions, as it accepts the job configuration
    ///   directly.
    /// * The *Upload* URI is ONLY for the case when you're sending both a load job configuration
    ///   and a data stream together. In this case, the Upload URI accepts the job configuration and
    ///   the data as two distinct multipart MIME parts.
    fn expect_insert_job(
        &mut self,
        project_id: &str,
    ) -> crate::mock_client::ExpectationBuilder<'_> {
        let path = format!("/bigquery/v2/projects/{project_id}/jobs");
        self.expect_post(&path)
    }

    /// Helper to expect `get_job`: Returns information about a specific job. Job information is
    /// available for a six month period after creation. Requires that you're the person who ran the
    /// job, or have the Is Owner project role.
    fn expect_get_job(
        &mut self,
        project_id: &str,
        job_id: &str,
        location: &str,
    ) -> crate::mock_client::ExpectationBuilder<'_> {
        let mut path = format!("/bigquery/v2/projects/{project_id}/jobs/{job_id}");
        let mut __qp: Vec<String> = Vec::new();
        if !location.is_empty() {
            __qp.push(format!("location={}", location));
        }
        if !__qp.is_empty() {
            path = format!("{}?{}", path, __qp.join("&"));
        }
        self.expect_get(&path)
    }

    /// Helper to expect `list_jobs`: Lists all jobs that you started in the specified project. Job
    /// information is available for a six month period after creation. The job list is sorted in
    /// reverse chronological order, by job creation time. Requires the Can View project role, or
    /// the Is Owner project role if you set the allUsers property.
    #[allow(clippy::too_many_arguments)]
    fn expect_list_jobs(
        &mut self,
        project_id: &str,
        all_users: &str,
        state_filter: &[&str],
        max_results: &str,
        page_token: &str,
        projection: &str,
        parent_job_id: &str,
        min_creation_time: &str,
        max_creation_time: &str,
    ) -> crate::mock_client::ExpectationBuilder<'_> {
        let mut path = format!("/bigquery/v2/projects/{project_id}/jobs");
        let mut __qp: Vec<String> = Vec::new();
        if !all_users.is_empty() {
            __qp.push(format!("allUsers={}", all_users));
        }
        for __v in state_filter {
            __qp.push(format!("stateFilter={}", __v));
        }
        if !max_results.is_empty() {
            __qp.push(format!("maxResults={}", max_results));
        }
        if !page_token.is_empty() {
            __qp.push(format!("pageToken={}", page_token));
        }
        if !projection.is_empty() {
            __qp.push(format!("projection={}", projection));
        }
        if !parent_job_id.is_empty() {
            __qp.push(format!("parentJobId={}", parent_job_id));
        }
        if !min_creation_time.is_empty() {
            __qp.push(format!("minCreationTime={}", min_creation_time));
        }
        if !max_creation_time.is_empty() {
            __qp.push(format!("maxCreationTime={}", max_creation_time));
        }
        if !__qp.is_empty() {
            path = format!("{}?{}", path, __qp.join("&"));
        }
        self.expect_get(&path)
    }

    /// Helper to expect `cancel_job`: Requests that a job be cancelled. This call will return
    /// immediately, and the client will need to poll for the job status to see if the cancel
    /// completed successfully. Cancelled jobs may still incur costs.
    fn expect_cancel_job(
        &mut self,
        project_id: &str,
        job_id: &str,
        location: &str,
    ) -> crate::mock_client::ExpectationBuilder<'_> {
        let mut path = format!("/bigquery/v2/projects/{project_id}/jobs/{job_id}/cancel");
        let mut __qp: Vec<String> = Vec::new();
        if !location.is_empty() {
            __qp.push(format!("location={}", location));
        }
        if !__qp.is_empty() {
            path = format!("{}?{}", path, __qp.join("&"));
        }
        self.expect_post(&path)
    }

    /// Helper to expect `delete_job`: Requests the deletion of the metadata of a job. This call
    /// returns when the job's metadata is deleted.
    fn expect_delete_job(
        &mut self,
        project_id: &str,
        job_id: &str,
        location: &str,
    ) -> crate::mock_client::ExpectationBuilder<'_> {
        let mut path = format!("/bigquery/v2/projects/{project_id}/jobs/{job_id}/delete");
        let mut __qp: Vec<String> = Vec::new();
        if !location.is_empty() {
            __qp.push(format!("location={}", location));
        }
        if !__qp.is_empty() {
            path = format!("{}?{}", path, __qp.join("&"));
        }
        self.expect_delete(&path)
    }
}