Skip to content

Commit bce4a15

Browse files
committed
Add tests
1 parent 1e65a57 commit bce4a15

File tree

7 files changed

+66
-28
lines changed

7 files changed

+66
-28
lines changed

src/adapter/http/tests/tests/test_routing.rs

+26
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,32 @@ async fn test_routing_dataset_name() {
209209
await_client_server_flow!(server, client);
210210
}
211211

212+
#[test_log::test(tokio::test)]
213+
async fn test_routing_dataset_name_case_insensetive() {
214+
let repo = setup_repo().await;
215+
216+
let server = setup_server(
217+
repo.catalog,
218+
"/:dataset_name",
219+
|Path(p): Path<DatasetByName>| DatasetAlias::new(None, p.dataset_name).into_local_ref(),
220+
);
221+
222+
let dataset_url = url::Url::parse(&format!(
223+
"http://{}/{}/",
224+
server.local_addr(),
225+
repo.created_dataset
226+
.dataset_handle
227+
.alias
228+
.dataset_name
229+
.to_ascii_uppercase()
230+
))
231+
.unwrap();
232+
233+
let client = setup_client(dataset_url, repo.created_dataset.head);
234+
235+
await_client_server_flow!(server, client);
236+
}
237+
212238
/////////////////////////////////////////////////////////////////////////////////////////
213239

214240
#[allow(dead_code)]

src/app/cli/src/services/accounts/account_service.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,9 @@ impl AccountService {
120120
RelatedAccountIndication::new(target_account)
121121
}
122122

123-
fn find_account_info_impl(&self, account_name: &String) -> Option<AccountInfo> {
123+
fn find_account_info_impl(&self, account_name: &AccountName) -> Option<AccountInfo> {
124124
// The account might be predefined in the configuration
125-
self.predefined_accounts
126-
.get(&account_name.to_ascii_lowercase())
127-
.cloned()
125+
self.predefined_accounts.get(account_name.as_str()).cloned()
128126
}
129127

130128
fn get_account_info_impl(
@@ -231,7 +229,7 @@ impl auth::AuthenticationProvider for AccountService {
231229
&'a self,
232230
account_name: &'a AccountName,
233231
) -> Result<Option<AccountInfo>, InternalError> {
234-
Ok(self.find_account_info_impl(&account_name.into()))
232+
Ok(self.find_account_info_impl(account_name))
235233
}
236234
}
237235

src/domain/opendatafabric/src/identity/dataset_identity.rs

+5-15
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ use like::ILike;
112112

113113
macro_rules! newtype_istr {
114114
($typ:ident, $parse:expr, $visitor:ident) => {
115-
#[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)]
115+
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
116116
pub struct $typ(Arc<str>);
117117

118118
impl $typ {
@@ -132,7 +132,7 @@ macro_rules! newtype_istr {
132132
Self(s)
133133
}
134134

135-
pub fn into_lowercase<'a>(s: &'a str) -> Cow<'a, str> {
135+
pub fn into_lowercase(s: &str) -> Cow<'_, str> {
136136
let bytes = s.as_bytes();
137137
if !bytes.iter().any(u8::is_ascii_uppercase) {
138138
Cow::Borrowed(s)
@@ -268,20 +268,10 @@ impl DatasetAliasPattern {
268268
}
269269

270270
pub fn matches(&self, dataset_handle: &DatasetHandle) -> bool {
271-
if self.account_name.is_some() && dataset_handle.alias.account_name.is_none()
272-
|| self.account_name.is_none() && dataset_handle.alias.account_name.is_some()
273-
{
274-
return false;
275-
}
276-
if self.account_name.as_ref().unwrap()
277-
== dataset_handle.alias.account_name.as_ref().unwrap()
271+
self.account_name == dataset_handle.alias.account_name
278272
&& self
279273
.dataset_name_pattern
280274
.matches(&dataset_handle.alias.dataset_name)
281-
{
282-
return true;
283-
}
284-
false
285275
}
286276
}
287277

@@ -332,7 +322,7 @@ newtype_istr!(RepoName, Grammar::match_repo_name, RepoNameSerdeVisitor);
332322

333323
////////////////////////////////////////////////////////////////////////////////
334324

335-
#[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)]
325+
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
336326
pub struct DatasetAlias {
337327
pub account_name: Option<AccountName>,
338328
pub dataset_name: DatasetName,
@@ -409,7 +399,7 @@ impl_serde!(DatasetAlias, DatasetAliasSerdeVisitor);
409399

410400
////////////////////////////////////////////////////////////////////////////////
411401

412-
#[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)]
402+
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
413403
pub struct DatasetAliasRemote {
414404
pub repo_name: RepoName,
415405
pub account_name: Option<AccountName>,

src/domain/opendatafabric/tests/tests/test_dataset_identity.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ fn test_dataset_remote_alias_eq() {
276276
DatasetAliasRemote::from_str("repository/account/net.example.com").unwrap(),
277277
DatasetAliasRemote::from_str("repository/AccOuNt/net.ExaMplE.coM").unwrap(),
278278
);
279-
assert_ne!(
279+
assert_eq!(
280280
DatasetAliasRemote::from_str("repository/net.example.com").unwrap(),
281281
DatasetAliasRemote::from_str("rEpoSitOry/net.ExaMplE.coM").unwrap(),
282282
);

src/domain/opendatafabric/tests/tests/test_dataset_refs.rs

+12
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,18 @@ fn test_dataset_ref_pattern_match() {
169169
},
170170
};
171171
assert!(pattern.matches(&dataset_handle));
172+
173+
let expression = "nEt.eXample%";
174+
let dataset_name = "net.example.com";
175+
let pattern = DatasetRefPattern::from_str(expression).unwrap();
176+
let dataset_handle = DatasetHandle {
177+
id: default_dataset_id.clone(),
178+
alias: DatasetAlias {
179+
account_name: None,
180+
dataset_name: DatasetName::from_str(dataset_name).unwrap(),
181+
},
182+
};
183+
assert!(pattern.matches(&dataset_handle));
172184
}
173185

174186
#[test]

src/infra/core/tests/tests/repos/test_dataset_repository_s3.rs

+16
Original file line numberDiff line numberDiff line change
@@ -311,3 +311,19 @@ async fn test_create_and_get_case_insensetive_dataset() {
311311
}
312312

313313
/////////////////////////////////////////////////////////////////////////////////////////
314+
315+
#[test_group::group(containerized)]
316+
#[tokio::test]
317+
async fn test_create_and_get_case_insensetive_dataset_multi_tenant() {
318+
let s3 = LocalS3Server::new().await;
319+
let harness =
320+
S3RepoHarness::create(&s3, auth::AlwaysHappyDatasetActionAuthorizer::new(), true).await;
321+
322+
test_dataset_repository_shared::test_create_and_get_case_insensetive_dataset(
323+
harness.dataset_repo.as_ref(),
324+
Some(AccountName::new_unchecked(auth::DEFAULT_ACCOUNT_NAME)),
325+
)
326+
.await;
327+
}
328+
329+
/////////////////////////////////////////////////////////////////////////////////////////

src/infra/core/tests/tests/repos/test_dataset_repository_shared.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,9 @@ pub async fn test_create_and_get_case_insensetive_dataset(
8787

8888
assert_eq!(create_result.dataset_handle.alias, dataset_alias_to_create);
8989

90-
let account_name_uppercase = if account_name.is_some() {
91-
Some(AccountName::new_unchecked(
92-
&account_name.unwrap().to_ascii_uppercase(),
93-
))
94-
} else {
95-
None
96-
};
90+
let account_name_uppercase = account_name.map(|account_name_value| {
91+
AccountName::new_unchecked(&account_name_value.to_ascii_uppercase())
92+
});
9793

9894
let dataset_alias_in_another_registry =
9995
DatasetAlias::new(account_name_uppercase, DatasetName::new_unchecked("foO"));

0 commit comments

Comments
 (0)