Skip to content

Commit

Permalink
Fix e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rylev committed Feb 25, 2022
1 parent fcf8d18 commit 9cd597f
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 151 deletions.
3 changes: 1 addition & 2 deletions sdk/core/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ impl Context {
{
self.type_map
.get(&TypeId::of::<E>())
.map(|item| item.downcast_ref())
.flatten()
.and_then(|item| item.downcast_ref())
}

/// Returns the number of entities in the type map.
Expand Down
35 changes: 16 additions & 19 deletions sdk/data_cosmos/tests/attachment_00.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#![cfg(all(test, feature = "test_e2e"))]
use azure_core::Context;
use azure_data_cosmos::prelude::*;
use serde::{Deserialize, Serialize};
use std::borrow::Cow;

mod setup;

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

impl<'a> azure_data_cosmos::CosmosEntity<'a> for MySampleStruct<'a> {
type Entity = &'a str;
impl azure_data_cosmos::CosmosEntity for MySampleStruct {
type Entity = String;

fn partition_key(&'a self) -> Self::Entity {
self.id.as_ref()
fn partition_key(&self) -> Self::Entity {
self.id.clone()
}
}

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

let options = CreateCollectionOptions::new("/id")
.offer(Offer::Throughput(400))
.indexing_policy(ip);
database_client
.create_collection(Context::new(), COLLECTION_NAME, options)
.create_collection(COLLECTION_NAME, "/id")
.offer(Offer::Throughput(400))
.indexing_policy(ip)
.into_future()
.await
.unwrap()
};
Expand All @@ -80,15 +78,16 @@ async fn attachment() -> Result<(), azure_data_cosmos::Error> {
let id = format!("unique_id{}", 100);

let doc = MySampleStruct {
id: Cow::Borrowed(&id),
a_string: Cow::Borrowed("Something here"),
id: id.clone(),
a_string: "Something here".into(),
a_number: 100,
a_timestamp: chrono::Utc::now().timestamp(),
};

// let's add an entity.
let session_token: ConsistencyLevel = collection_client
.create_document(Context::new(), &doc, CreateDocumentOptions::new())
.create_document(doc.clone())
.into_future()
.await?
.into();

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

// delete the database
database_client
.delete_database(Context::new(), DeleteDatabaseOptions::new())
.await?;
database_client.delete_database().into_future().await?;

Ok(())
}
25 changes: 13 additions & 12 deletions sdk/data_cosmos/tests/cosmos_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ async fn create_and_delete_collection() {

// create a new collection
let collection = database_client
.create_collection(
Context::new(),
COLLECTION_NAME,
CreateCollectionOptions::new("/id"),
)
.create_collection(COLLECTION_NAME, "/id")
.into_future()
.await
.unwrap();
let collections =
Expand Down Expand Up @@ -58,7 +55,8 @@ async fn create_and_delete_collection() {

// delete the collection
collection_client
.delete_collection(Context::new(), DeleteCollectionOptions::new())
.delete_collection()
.into_future()
.await
.unwrap();
let collections =
Expand All @@ -70,7 +68,8 @@ async fn create_and_delete_collection() {
assert!(collections.collections.len() == 0);

database_client
.delete_database(Context::new(), DeleteDatabaseOptions::new())
.delete_database()
.into_future()
.await
.unwrap();
}
Expand All @@ -96,11 +95,12 @@ async fn replace_collection() {
included_paths: vec![],
excluded_paths: vec![],
};
let options = CreateCollectionOptions::new("/id")
.offer(Offer::S2)
.indexing_policy(indexing_policy);

let collection = database_client
.create_collection(Context::new(), COLLECTION_NAME, options)
.create_collection(COLLECTION_NAME, "/id")
.offer(Offer::S2)
.indexing_policy(indexing_policy)
.into_future()
.await
.unwrap();

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

database_client
.delete_database(Context::new(), DeleteDatabaseOptions::new())
.delete_database()
.into_future()
.await
.unwrap();
}
3 changes: 2 additions & 1 deletion sdk/data_cosmos/tests/cosmos_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ async fn create_and_delete_database() {
client
.clone()
.into_database_client(DATABASE_NAME)
.delete_database(Context::new(), DeleteDatabaseOptions::new())
.delete_database()
.into_future()
.await
.unwrap();

Expand Down
59 changes: 32 additions & 27 deletions sdk/data_cosmos/tests/cosmos_document.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#![cfg(all(test, feature = "test_e2e"))]
use azure_core::Context;
use azure_data_cosmos::prelude::{
CreateDocumentBuilder, DeleteDatabaseBuilder, GetDocumentOptions,
};
use azure_data_cosmos::prelude::GetDocumentOptions;
use serde::{Deserialize, Serialize};

mod setup;
Expand All @@ -11,17 +9,17 @@ use azure_core::prelude::*;
use azure_data_cosmos::prelude::*;
use collection::*;

#[derive(Serialize, Deserialize, Debug, PartialEq)]
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
struct MyDocument {
id: String,
hello: u32,
}

impl<'a> azure_data_cosmos::CosmosEntity<'a> for MyDocument {
type Entity = &'a str;
impl azure_data_cosmos::CosmosEntity for MyDocument {
type Entity = String;

fn partition_key(&'a self) -> Self::Entity {
self.id.as_ref()
fn partition_key(&self) -> Self::Entity {
self.id.clone()
}
}

Expand Down Expand Up @@ -49,11 +47,11 @@ async fn create_and_delete_document() {
excluded_paths: vec![],
};

let options = CreateCollectionOptions::new("/id")
.offer(Offer::Throughput(400))
.indexing_policy(indexing_policy);
database_client
.create_collection(Context::new(), COLLECTION_NAME, options)
.create_collection(COLLECTION_NAME, "/id")
.offer(Offer::Throughput(400))
.indexing_policy(indexing_policy)
.into_future()
.await
.unwrap();

Expand All @@ -67,7 +65,8 @@ async fn create_and_delete_document() {
hello: 42,
};
collection_client
.create_document(Context::new(), &document_data, CreateDocumentOptions::new())
.create_document(document_data.clone())
.into_future()
.await
.unwrap();

Expand Down Expand Up @@ -98,7 +97,8 @@ async fn create_and_delete_document() {

// delete document
document_client
.delete_document(Context::new(), DeleteDocumentOptions::new())
.delete_document()
.into_future()
.await
.unwrap();

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

database_client
.delete_database(Context::new(), DeleteDatabaseOptions::new())
.delete_database()
.into_future()
.await
.unwrap();
}
Expand Down Expand Up @@ -139,11 +140,11 @@ async fn query_documents() {
excluded_paths: vec![],
};

let options = CreateCollectionOptions::new("/id")
.indexing_policy(indexing_policy)
.offer(Offer::S2);
database_client
.create_collection(Context::new(), COLLECTION_NAME, options)
.create_collection(COLLECTION_NAME, "/id")
.indexing_policy(indexing_policy)
.offer(Offer::S2)
.into_future()
.await
.unwrap();

Expand All @@ -157,7 +158,8 @@ async fn query_documents() {
hello: 42,
};
collection_client
.create_document(Context::new(), &document_data, CreateDocumentOptions::new())
.create_document(document_data.clone())
.into_future()
.await
.unwrap();

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

database_client
.delete_database(Context::new(), DeleteDatabaseOptions::new())
.delete_database()
.into_future()
.await
.unwrap();
}
Expand Down Expand Up @@ -213,11 +216,11 @@ async fn replace_document() {
excluded_paths: vec![],
};

let options = CreateCollectionOptions::new("/id")
.indexing_policy(indexing_policy)
.offer(Offer::S2);
database_client
.create_collection(Context::new(), COLLECTION_NAME, options)
.create_collection(COLLECTION_NAME, "/id")
.indexing_policy(indexing_policy)
.offer(Offer::S2)
.into_future()
.await
.unwrap();

Expand All @@ -231,7 +234,8 @@ async fn replace_document() {
hello: 42,
};
collection_client
.create_document(Context::new(), &document_data, CreateDocumentOptions::new())
.create_document(document_data.clone())
.into_future()
.await
.unwrap();

Expand Down Expand Up @@ -279,7 +283,8 @@ async fn replace_document() {
}

database_client
.delete_database(Context::new(), DeleteDatabaseOptions::new())
.delete_database()
.into_future()
.await
.unwrap();
}
37 changes: 12 additions & 25 deletions sdk/data_cosmos/tests/permission.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![cfg(all(test, feature = "test_e2e"))]
use azure_core::Context;
use azure_data_cosmos::prelude::*;

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

// create two users
let user1_client = database_client.clone().into_user_client(USER_NAME1);
let _create_user_response = user1_client
.create_user(Context::new(), CreateUserOptions::new())
.await
.unwrap();
let _create_user_response = user1_client.create_user().into_future().await.unwrap();
let user2_client = database_client.clone().into_user_client(USER_NAME2);
let _create_user_response = user2_client
.create_user(Context::new(), CreateUserOptions::new())
.await
.unwrap();
let _create_user_response = user2_client.create_user().into_future().await.unwrap();

// create a temp collection
let create_collection_response = database_client
.create_collection(
Context::new(),
COLLECTION_NAME,
CreateCollectionOptions::new("/id"),
)
.create_collection(COLLECTION_NAME, "/id")
.into_future()
.await
.unwrap();

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

let _create_permission_user1_response = permission_client_user1
.create_permission(
Context::new(),
CreatePermissionOptions::new().expiry_seconds(18000u64), // 5 hours, max!
&create_collection_response.collection.all_permission(),
)
.create_permission(create_collection_response.collection.all_permission())
.expiry_seconds(18000u64) // 5 hours, max!
.into_future()
.await
.unwrap();

let _create_permission_user2_response = permission_client_user2
.create_permission(
Context::new(),
CreatePermissionOptions::new().expiry_seconds(18000u64), // 5 hours, max!
&create_collection_response.collection.read_permission(),
)
.create_permission(create_collection_response.collection.read_permission())
.expiry_seconds(18000u64) // 5 hours, max!
.into_future()
.await
.unwrap();

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

// delete the database
database_client
.delete_database(Context::new(), DeleteDatabaseOptions::new())
.delete_database()
.into_future()
.await
.unwrap();
}
Loading

0 comments on commit 9cd597f

Please sign in to comment.