Skip to content

Commit 1cfae56

Browse files
committed
convert missing tests
1 parent beab9aa commit 1cfae56

13 files changed

+65
-77
lines changed

sdk/data_cosmos/examples/create_delete_database.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
4444

4545
// create collection!
4646
{
47-
let db_client = client.database(database_name.clone());
48-
let create_collection_response = db_client
47+
let database = client.database(database_name.clone());
48+
let create_collection_response = database
4949
.create_collection("panzadoro", "/id")
5050
.into_future()
5151
.await?;
@@ -55,12 +55,12 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
5555
create_collection_response
5656
);
5757

58-
let db_collection = db_client.collection("panzadoro");
58+
let db_collection = database.collection("panzadoro");
5959

6060
let get_collection_response = db_collection.get_collection().into_future().await?;
6161
println!("get_collection_response == {:#?}", get_collection_response);
6262

63-
let mut stream = db_client.list_collections().into_stream();
63+
let mut stream = database.list_collections().into_stream();
6464
while let Some(res) = stream.next().await {
6565
let res = res?;
6666
println!("res == {:#?}", res);

sdk/data_cosmos/examples/permission_00.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
3333

3434
let database = client.database(database_name);
3535
let collection = database.collection(collection_name);
36-
let collection2_client = database.collection(collection_name2);
36+
let collection2 = database.collection(collection_name2);
3737
let user = database.user(user_name);
3838

3939
let get_database_response = database.get_database().into_future().await?;
@@ -42,7 +42,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
4242
let get_collection_response = collection.get_collection().into_future().await?;
4343
println!("get_collection_response == {:#?}", get_collection_response);
4444

45-
let get_collection2_response = collection2_client.get_collection().into_future().await?;
45+
let get_collection2_response = collection2.get_collection().into_future().await?;
4646
println!(
4747
"get_collection2_response == {:#?}",
4848
get_collection2_response

sdk/data_cosmos/tests/attachment_00.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async fn attachment() -> Result<(), azure_data_cosmos::Error> {
4141
.await
4242
.unwrap();
4343

44-
let database = client.into_database(DATABASE_NAME);
44+
let database = client.database(DATABASE_NAME);
4545

4646
// create a temp collection
4747
let _create_collection_response = {
@@ -72,7 +72,7 @@ async fn attachment() -> Result<(), azure_data_cosmos::Error> {
7272
.unwrap()
7373
};
7474

75-
let collection = database.clone().into_collection(COLLECTION_NAME);
75+
let collection = database.collection(COLLECTION_NAME);
7676

7777
let id = format!("unique_id{}", 100);
7878

@@ -90,7 +90,7 @@ async fn attachment() -> Result<(), azure_data_cosmos::Error> {
9090
.await?
9191
.into();
9292

93-
let document = collection.into_document(id.clone(), &doc.id)?;
93+
let document = collection.document(id.clone(), &doc.id)?;
9494

9595
// list attachments, there must be none.
9696
let ret = document
@@ -103,7 +103,7 @@ async fn attachment() -> Result<(), azure_data_cosmos::Error> {
103103
assert_eq!(0, ret.attachments.len());
104104

105105
// create reference attachment
106-
let attachment = document.into_attachment("reference");
106+
let attachment = document.attachment("reference");
107107
let resp = attachment
108108
.create_attachment("https://www.bing.com", "image/jpeg")
109109
.consistency_level(&ret)
@@ -118,7 +118,7 @@ async fn attachment() -> Result<(), azure_data_cosmos::Error> {
118118
.await?;
119119

120120
// create slug attachment
121-
let attachment = document.into_attachment("slug");
121+
let attachment = document.attachment("slug");
122122
let resp = attachment
123123
.create_slug("something cool here".into())
124124
.consistency_level(&resp)
@@ -138,8 +138,7 @@ async fn attachment() -> Result<(), azure_data_cosmos::Error> {
138138

139139
// get reference attachment, it must have the updated media link
140140
let reference_attachment = document
141-
.clone()
142-
.into_attachment("reference")
141+
.attachment("reference")
143142
.get()
144143
.consistency_level(&ret)
145144
.into_future()
@@ -152,8 +151,7 @@ async fn attachment() -> Result<(), azure_data_cosmos::Error> {
152151
// get slug attachment, it must have the text/plain content type
153152
println!("getting slug attachment");
154153
let slug_attachment = document
155-
.clone()
156-
.into_attachment("slug")
154+
.attachment("slug")
157155
.get()
158156
.consistency_level(&reference_attachment)
159157
.into_future()

sdk/data_cosmos/tests/collection_operations.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ async fn collection_operations() -> Result<(), BoxedError> {
1818
client.create_database(database_name).into_future().await?;
1919

2020
// create collection!
21-
let db_client = client.clone().into_database(database_name.clone());
21+
let database = client.database(database_name.clone());
2222

2323
let collection_name = "sample_collection";
2424
log::info!("Creating a collection with name '{}'...", collection_name);
2525

26-
let create_collection_response = db_client
26+
let create_collection_response = database
2727
.create_collection(collection_name, "/id")
2828
.into_future()
2929
.await?;
@@ -36,7 +36,7 @@ async fn collection_operations() -> Result<(), BoxedError> {
3636
create_collection_response
3737
);
3838

39-
let collection = db_client.clone().into_collection(collection_name);
39+
let collection = database.collection(collection_name);
4040

4141
// get collection!
4242
let get_collection_response = collection.get_collection().into_future().await?;
@@ -112,7 +112,7 @@ async fn collection_operations() -> Result<(), BoxedError> {
112112
delete_collection_response
113113
);
114114

115-
db_client.delete_database().into_future().await.unwrap();
115+
database.delete_database().into_future().await.unwrap();
116116

117117
Ok(())
118118
}

sdk/data_cosmos/tests/cosmos_collection.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async fn create_and_delete_collection() {
1818
.await
1919
.unwrap();
2020

21-
let database = client.into_database(DATABASE_NAME);
21+
let database = client.database(DATABASE_NAME);
2222

2323
// create a new collection
2424
let collection = database
@@ -34,10 +34,11 @@ async fn create_and_delete_collection() {
3434
assert!(collections.collections.len() == 1);
3535

3636
// try to get the previously created collection
37-
let collection = database.clone().into_collection(COLLECTION_NAME);
37+
let rid = collection.collection.rid;
38+
let collection = database.collection(COLLECTION_NAME);
3839

3940
let collection_after_get = collection.get_collection().into_future().await.unwrap();
40-
assert!(collection.collection.rid == collection_after_get.collection.rid);
41+
assert!(rid == collection_after_get.collection.rid);
4142

4243
// check GetPartitionKeyRanges: https://docs.microsoft.com/rest/api/cosmos-db/get-partition-key-ranges
4344
collection
@@ -70,7 +71,7 @@ async fn replace_collection() {
7071
.await
7172
.unwrap();
7273

73-
let database = client.into_database(DATABASE_NAME);
74+
let database = client.database(DATABASE_NAME);
7475

7576
// create a new collection
7677
let indexing_policy = IndexingPolicy {
@@ -122,9 +123,8 @@ async fn replace_collection() {
122123
.excluded_paths
123124
.push("/\"excludeme\"/?".to_owned().into());
124125

125-
let collection = database.clone().into_collection(COLLECTION_NAME);
126-
127-
let _replace_collection_response = collection
126+
let _replace_collection_response = database
127+
.collection(COLLECTION_NAME)
128128
.replace_collection("/id")
129129
.indexing_policy(new_ip)
130130
.into_future()

sdk/data_cosmos/tests/cosmos_database.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ async fn create_and_delete_database() {
3636

3737
// get the previously created database
3838
let database_after_get = client
39-
.clone()
40-
.into_database(DATABASE_NAME)
39+
.database(DATABASE_NAME)
4140
.get_database()
4241
.into_future()
4342
.await
@@ -46,8 +45,7 @@ async fn create_and_delete_database() {
4645

4746
// delete the database
4847
client
49-
.clone()
50-
.into_database(DATABASE_NAME)
48+
.database(DATABASE_NAME)
5149
.delete_database()
5250
.into_future()
5351
.await

sdk/data_cosmos/tests/cosmos_document.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async fn create_and_delete_document() {
3636
.await
3737
.unwrap();
3838

39-
let database = client.into_database(DATABASE_NAME);
39+
let database = client.database(DATABASE_NAME);
4040

4141
// create a new collection
4242
let indexing_policy = IndexingPolicy {
@@ -54,7 +54,7 @@ async fn create_and_delete_document() {
5454
.await
5555
.unwrap();
5656

57-
let collection = database.clone().into_collection(COLLECTION_NAME);
57+
let collection = database.collection(COLLECTION_NAME);
5858

5959
// create a new document
6060
let document_data = MyDocument {
@@ -78,10 +78,7 @@ async fn create_and_delete_document() {
7878
assert!(documents.len() == 1);
7979

8080
// try to get the contents of the previously created document
81-
let document = collection
82-
.clone()
83-
.into_document(DOCUMENT_NAME, &DOCUMENT_NAME)
84-
.unwrap();
81+
let document = collection.document(DOCUMENT_NAME, &DOCUMENT_NAME).unwrap();
8582

8683
let document_after_get = document
8784
.get_document()
@@ -124,7 +121,7 @@ async fn query_documents() {
124121
.into_future()
125122
.await
126123
.unwrap();
127-
let database = client.into_database(DATABASE_NAME);
124+
let database = client.database(DATABASE_NAME);
128125

129126
// create a new collection
130127
let indexing_policy = IndexingPolicy {
@@ -142,7 +139,7 @@ async fn query_documents() {
142139
.await
143140
.unwrap();
144141

145-
let collection = database.clone().into_collection(COLLECTION_NAME);
142+
let collection = database.collection(COLLECTION_NAME);
146143

147144
// create a new document
148145
let document_data = MyDocument {
@@ -174,7 +171,7 @@ async fn query_documents() {
174171
.await
175172
.unwrap()
176173
.unwrap()
177-
.into_documents()
174+
.documents()
178175
.unwrap()
179176
.results;
180177

@@ -198,7 +195,7 @@ async fn replace_document() {
198195
.into_future()
199196
.await
200197
.unwrap();
201-
let database = client.into_database(DATABASE_NAME);
198+
let database = client.database(DATABASE_NAME);
202199

203200
// create a new collection
204201
let indexing_policy = IndexingPolicy {
@@ -216,7 +213,7 @@ async fn replace_document() {
216213
.await
217214
.unwrap();
218215

219-
let collection = database.clone().into_collection(COLLECTION_NAME);
216+
let collection = database.collection(COLLECTION_NAME);
220217

221218
// create a new document
222219
let mut document_data = MyDocument {
@@ -241,8 +238,7 @@ async fn replace_document() {
241238
// replace document with optimistic concurrency and session token
242239
document_data.hello = 190;
243240
collection
244-
.clone()
245-
.into_document(document_data.id.clone(), &document_data.id)
241+
.document(document_data.id.clone(), &document_data.id)
246242
.unwrap()
247243
.replace_document(document_data)
248244
.consistency_level(ConsistencyLevel::from(&documents))
@@ -257,9 +253,7 @@ async fn replace_document() {
257253
.unwrap();
258254

259255
// now get the replaced document
260-
let document = collection
261-
.into_document(DOCUMENT_NAME, &DOCUMENT_NAME)
262-
.unwrap();
256+
let document = collection.document(DOCUMENT_NAME, &DOCUMENT_NAME).unwrap();
263257
let document_after_get = document
264258
.get_document()
265259
.into_future::<MyDocument>()

sdk/data_cosmos/tests/create_database_and_collection.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ async fn create_database_and_collection() -> Result<(), BoxedError> {
2424
assert_eq!(db.database.id, database_name);
2525

2626
// create collection!
27-
let db_client = client.clone().into_database(database_name.clone());
27+
let database = client.database(database_name.clone());
2828
let collection_name = "panzadoro";
2929
log::info!("Creating a collection with name '{}'...", collection_name);
30-
let collection = db_client
30+
let collection = database
3131
.create_collection(collection_name, "/id")
3232
.into_future()
3333
.await?;
@@ -37,7 +37,7 @@ async fn create_database_and_collection() -> Result<(), BoxedError> {
3737

3838
// list collections!
3939
log::info!("Listing all collections...");
40-
let collections = Box::pin(db_client.list_collections().into_stream())
40+
let collections = Box::pin(database.list_collections().into_stream())
4141
.next()
4242
.await
4343
.expect("No collection page")?;
@@ -47,7 +47,7 @@ async fn create_database_and_collection() -> Result<(), BoxedError> {
4747

4848
// delete database
4949
log::info!("Deleting the database...");
50-
let deleted_database = db_client.delete_database().into_future().await?;
50+
let deleted_database = database.delete_database().into_future().await?;
5151
log::info!("Successfully deleted database");
5252
log::debug!("The delete_database response: {:#?}", deleted_database);
5353

sdk/data_cosmos/tests/permission.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ async fn permissions() {
2222
.await
2323
.unwrap();
2424

25-
let database = client.into_database(DATABASE_NAME);
25+
let database = client.database(DATABASE_NAME);
2626

2727
// create two users
28-
let user1_client = database.clone().into_user(USER_NAME1);
29-
let _create_user_response = user1_client.create_user().into_future().await.unwrap();
30-
let user2_client = database.clone().into_user(USER_NAME2);
31-
let _create_user_response = user2_client.create_user().into_future().await.unwrap();
28+
let user1 = database.user(USER_NAME1);
29+
let _create_user_response = user1.create_user().into_future().await.unwrap();
30+
let user2 = database.user(USER_NAME2);
31+
let _create_user_response = user2.create_user().into_future().await.unwrap();
3232

3333
// create a temp collection
3434
let create_collection_response = database
@@ -38,8 +38,8 @@ async fn permissions() {
3838
.unwrap();
3939

4040
// create two permissions
41-
let permission_user1 = user1_client.permission(PERMISSION1);
42-
let permission_user2 = user2_client.permission(PERMISSION2);
41+
let permission_user1 = user1.permission(PERMISSION1);
42+
let permission_user2 = user2.permission(PERMISSION2);
4343

4444
let _create_permission_user1_response = permission_user1
4545
.create_permission(create_collection_response.collection.all_permission())
@@ -55,7 +55,7 @@ async fn permissions() {
5555
.await
5656
.unwrap();
5757

58-
let list_permissions_response = user1_client
58+
let list_permissions_response = user1
5959
.list_permissions()
6060
.into_stream()
6161
.next()
@@ -64,7 +64,7 @@ async fn permissions() {
6464
.unwrap();
6565
assert_eq!(list_permissions_response.permissions.len(), 1);
6666

67-
let list_permissions_response = user2_client
67+
let list_permissions_response = user2
6868
.list_permissions()
6969
.into_stream()
7070
.next()

0 commit comments

Comments
 (0)