Skip to content

Commit fa4e8a8

Browse files
committed
Fix e2e tests
1 parent b784040 commit fa4e8a8

File tree

9 files changed

+114
-148
lines changed

9 files changed

+114
-148
lines changed

sdk/data_cosmos/tests/attachment_00.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#![cfg(all(test, feature = "test_e2e"))]
2-
use azure_core::Context;
32
use azure_data_cosmos::prelude::*;
43
use serde::{Deserialize, Serialize};
5-
use std::borrow::Cow;
64

75
mod setup;
86

@@ -13,18 +11,18 @@ mod setup;
1311
// We do not need to define the "id" field here, it will be
1412
// specified in the Document struct below.
1513
#[derive(Serialize, Deserialize, Clone, Debug)]
16-
struct MySampleStruct<'a> {
17-
id: Cow<'a, str>,
18-
a_string: Cow<'a, str>,
14+
struct MySampleStruct {
15+
id: String,
16+
a_string: String,
1917
a_number: u64,
2018
a_timestamp: i64,
2119
}
2220

23-
impl<'a> azure_data_cosmos::CosmosEntity<'a> for MySampleStruct<'a> {
24-
type Entity = &'a str;
21+
impl azure_data_cosmos::CosmosEntity for MySampleStruct {
22+
type Entity = String;
2523

26-
fn partition_key(&'a self) -> Self::Entity {
27-
self.id.as_ref()
24+
fn partition_key(&self) -> Self::Entity {
25+
self.id.clone()
2826
}
2927
}
3028

@@ -64,11 +62,11 @@ async fn attachment() -> Result<(), azure_data_cosmos::Error> {
6462
excluded_paths: vec![],
6563
};
6664

67-
let options = CreateCollectionOptions::new("/id")
68-
.offer(Offer::Throughput(400))
69-
.indexing_policy(ip);
7065
database_client
71-
.create_collection(Context::new(), COLLECTION_NAME, options)
66+
.create_collection(COLLECTION_NAME, "/id")
67+
.offer(Offer::Throughput(400))
68+
.indexing_policy(ip)
69+
.into_future()
7270
.await
7371
.unwrap()
7472
};
@@ -80,15 +78,16 @@ async fn attachment() -> Result<(), azure_data_cosmos::Error> {
8078
let id = format!("unique_id{}", 100);
8179

8280
let doc = MySampleStruct {
83-
id: Cow::Borrowed(&id),
84-
a_string: Cow::Borrowed("Something here"),
81+
id: id.clone(),
82+
a_string: "Something here".into(),
8583
a_number: 100,
8684
a_timestamp: chrono::Utc::now().timestamp(),
8785
};
8886

8987
// let's add an entity.
9088
let session_token: ConsistencyLevel = collection_client
91-
.create_document(Context::new(), &doc, CreateDocumentOptions::new())
89+
.create_document(doc.clone())
90+
.into_future()
9291
.await?
9392
.into();
9493

@@ -175,9 +174,7 @@ async fn attachment() -> Result<(), azure_data_cosmos::Error> {
175174
assert_eq!(1, ret.attachments.len());
176175

177176
// delete the database
178-
database_client
179-
.delete_database(Context::new(), DeleteDatabaseOptions::new())
180-
.await?;
177+
database_client.delete_database().into_future().await?;
181178

182179
Ok(())
183180
}

sdk/data_cosmos/tests/cosmos_collection.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,8 @@ async fn create_and_delete_collection() {
2323

2424
// create a new collection
2525
let collection = database_client
26-
.create_collection(
27-
Context::new(),
28-
COLLECTION_NAME,
29-
CreateCollectionOptions::new("/id"),
30-
)
26+
.create_collection(COLLECTION_NAME, "/id")
27+
.into_future()
3128
.await
3229
.unwrap();
3330
let collections =
@@ -58,7 +55,8 @@ async fn create_and_delete_collection() {
5855

5956
// delete the collection
6057
collection_client
61-
.delete_collection(Context::new(), DeleteCollectionOptions::new())
58+
.delete_collection()
59+
.into_future()
6260
.await
6361
.unwrap();
6462
let collections =
@@ -70,7 +68,8 @@ async fn create_and_delete_collection() {
7068
assert!(collections.collections.len() == 0);
7169

7270
database_client
73-
.delete_database(Context::new(), DeleteDatabaseOptions::new())
71+
.delete_database()
72+
.into_future()
7473
.await
7574
.unwrap();
7675
}
@@ -96,11 +95,12 @@ async fn replace_collection() {
9695
included_paths: vec![],
9796
excluded_paths: vec![],
9897
};
99-
let options = CreateCollectionOptions::new("/id")
100-
.offer(Offer::S2)
101-
.indexing_policy(indexing_policy);
98+
10299
let collection = database_client
103-
.create_collection(Context::new(), COLLECTION_NAME, options)
100+
.create_collection(COLLECTION_NAME, "/id")
101+
.offer(Offer::S2)
102+
.indexing_policy(indexing_policy)
103+
.into_future()
104104
.await
105105
.unwrap();
106106

@@ -167,7 +167,8 @@ async fn replace_collection() {
167167
assert!(eps.len() > 0);
168168

169169
database_client
170-
.delete_database(Context::new(), DeleteDatabaseOptions::new())
170+
.delete_database()
171+
.into_future()
171172
.await
172173
.unwrap();
173174
}

sdk/data_cosmos/tests/cosmos_database.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ async fn create_and_delete_database() {
4848
client
4949
.clone()
5050
.into_database_client(DATABASE_NAME)
51-
.delete_database(Context::new(), DeleteDatabaseOptions::new())
51+
.delete_database()
52+
.into_future()
5253
.await
5354
.unwrap();
5455

sdk/data_cosmos/tests/cosmos_document.rs

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#![cfg(all(test, feature = "test_e2e"))]
22
use azure_core::Context;
3-
use azure_data_cosmos::prelude::{
4-
CreateDocumentBuilder, DeleteDatabaseBuilder, GetDocumentOptions,
5-
};
3+
use azure_data_cosmos::prelude::GetDocumentOptions;
64
use serde::{Deserialize, Serialize};
75

86
mod setup;
@@ -11,17 +9,17 @@ use azure_core::prelude::*;
119
use azure_data_cosmos::prelude::*;
1210
use collection::*;
1311

14-
#[derive(Serialize, Deserialize, Debug, PartialEq)]
12+
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
1513
struct MyDocument {
1614
id: String,
1715
hello: u32,
1816
}
1917

20-
impl<'a> azure_data_cosmos::CosmosEntity<'a> for MyDocument {
21-
type Entity = &'a str;
18+
impl azure_data_cosmos::CosmosEntity for MyDocument {
19+
type Entity = String;
2220

23-
fn partition_key(&'a self) -> Self::Entity {
24-
self.id.as_ref()
21+
fn partition_key(&self) -> Self::Entity {
22+
self.id.clone()
2523
}
2624
}
2725

@@ -49,11 +47,11 @@ async fn create_and_delete_document() {
4947
excluded_paths: vec![],
5048
};
5149

52-
let options = CreateCollectionOptions::new("/id")
53-
.offer(Offer::Throughput(400))
54-
.indexing_policy(indexing_policy);
5550
database_client
56-
.create_collection(Context::new(), COLLECTION_NAME, options)
51+
.create_collection(COLLECTION_NAME, "/id")
52+
.offer(Offer::Throughput(400))
53+
.indexing_policy(indexing_policy)
54+
.into_future()
5755
.await
5856
.unwrap();
5957

@@ -67,7 +65,8 @@ async fn create_and_delete_document() {
6765
hello: 42,
6866
};
6967
collection_client
70-
.create_document(Context::new(), &document_data, CreateDocumentOptions::new())
68+
.create_document(document_data.clone())
69+
.into_future()
7170
.await
7271
.unwrap();
7372

@@ -98,7 +97,8 @@ async fn create_and_delete_document() {
9897

9998
// delete document
10099
document_client
101-
.delete_document(Context::new(), DeleteDocumentOptions::new())
100+
.delete_document()
101+
.into_future()
102102
.await
103103
.unwrap();
104104

@@ -111,7 +111,8 @@ async fn create_and_delete_document() {
111111
assert!(documents.len() == 0);
112112

113113
database_client
114-
.delete_database(Context::new(), DeleteDatabaseOptions::new())
114+
.delete_database()
115+
.into_future()
115116
.await
116117
.unwrap();
117118
}
@@ -139,11 +140,11 @@ async fn query_documents() {
139140
excluded_paths: vec![],
140141
};
141142

142-
let options = CreateCollectionOptions::new("/id")
143-
.indexing_policy(indexing_policy)
144-
.offer(Offer::S2);
145143
database_client
146-
.create_collection(Context::new(), COLLECTION_NAME, options)
144+
.create_collection(COLLECTION_NAME, "/id")
145+
.indexing_policy(indexing_policy)
146+
.offer(Offer::S2)
147+
.into_future()
147148
.await
148149
.unwrap();
149150

@@ -157,7 +158,8 @@ async fn query_documents() {
157158
hello: 42,
158159
};
159160
collection_client
160-
.create_document(Context::new(), &document_data, CreateDocumentOptions::new())
161+
.create_document(document_data.clone())
162+
.into_future()
161163
.await
162164
.unwrap();
163165

@@ -185,7 +187,8 @@ async fn query_documents() {
185187
assert_eq!(query_result[0].result, document_data);
186188

187189
database_client
188-
.delete_database(Context::new(), DeleteDatabaseOptions::new())
190+
.delete_database()
191+
.into_future()
189192
.await
190193
.unwrap();
191194
}
@@ -213,11 +216,11 @@ async fn replace_document() {
213216
excluded_paths: vec![],
214217
};
215218

216-
let options = CreateCollectionOptions::new("/id")
217-
.indexing_policy(indexing_policy)
218-
.offer(Offer::S2);
219219
database_client
220-
.create_collection(Context::new(), COLLECTION_NAME, options)
220+
.create_collection(COLLECTION_NAME, "/id")
221+
.indexing_policy(indexing_policy)
222+
.offer(Offer::S2)
223+
.into_future()
221224
.await
222225
.unwrap();
223226

@@ -231,7 +234,8 @@ async fn replace_document() {
231234
hello: 42,
232235
};
233236
collection_client
234-
.create_document(Context::new(), &document_data, CreateDocumentOptions::new())
237+
.create_document(document_data.clone())
238+
.into_future()
235239
.await
236240
.unwrap();
237241

@@ -279,7 +283,8 @@ async fn replace_document() {
279283
}
280284

281285
database_client
282-
.delete_database(Context::new(), DeleteDatabaseOptions::new())
286+
.delete_database()
287+
.into_future()
283288
.await
284289
.unwrap();
285290
}

sdk/data_cosmos/tests/permission.rs

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![cfg(all(test, feature = "test_e2e"))]
2-
use azure_core::Context;
32
use azure_data_cosmos::prelude::*;
43

54
mod setup;
@@ -26,23 +25,14 @@ async fn permissions() {
2625

2726
// create two users
2827
let user1_client = database_client.clone().into_user_client(USER_NAME1);
29-
let _create_user_response = user1_client
30-
.create_user(Context::new(), CreateUserOptions::new())
31-
.await
32-
.unwrap();
28+
let _create_user_response = user1_client.create_user().into_future().await.unwrap();
3329
let user2_client = database_client.clone().into_user_client(USER_NAME2);
34-
let _create_user_response = user2_client
35-
.create_user(Context::new(), CreateUserOptions::new())
36-
.await
37-
.unwrap();
30+
let _create_user_response = user2_client.create_user().into_future().await.unwrap();
3831

3932
// create a temp collection
4033
let create_collection_response = database_client
41-
.create_collection(
42-
Context::new(),
43-
COLLECTION_NAME,
44-
CreateCollectionOptions::new("/id"),
45-
)
34+
.create_collection(COLLECTION_NAME, "/id")
35+
.into_future()
4636
.await
4737
.unwrap();
4838

@@ -51,20 +41,16 @@ async fn permissions() {
5141
let permission_client_user2 = user2_client.clone().into_permission_client(PERMISSION2);
5242

5343
let _create_permission_user1_response = permission_client_user1
54-
.create_permission(
55-
Context::new(),
56-
CreatePermissionOptions::new().expiry_seconds(18000u64), // 5 hours, max!
57-
&create_collection_response.collection.all_permission(),
58-
)
44+
.create_permission(create_collection_response.collection.all_permission())
45+
.expiry_seconds(18000u64) // 5 hours, max!
46+
.into_future()
5947
.await
6048
.unwrap();
6149

6250
let _create_permission_user2_response = permission_client_user2
63-
.create_permission(
64-
Context::new(),
65-
CreatePermissionOptions::new().expiry_seconds(18000u64), // 5 hours, max!
66-
&create_collection_response.collection.read_permission(),
67-
)
51+
.create_permission(create_collection_response.collection.read_permission())
52+
.expiry_seconds(18000u64) // 5 hours, max!
53+
.into_future()
6854
.await
6955
.unwrap();
7056

@@ -76,7 +62,8 @@ async fn permissions() {
7662

7763
// delete the database
7864
database_client
79-
.delete_database(Context::new(), DeleteDatabaseOptions::new())
65+
.delete_database()
66+
.into_future()
8067
.await
8168
.unwrap();
8269
}

0 commit comments

Comments
 (0)