Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
SimranMakhija7 committed Apr 12, 2024
1 parent e37887c commit 954b5d2
Showing 1 changed file with 58 additions and 20 deletions.
78 changes: 58 additions & 20 deletions src/repository/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,63 +70,81 @@ mod tests {
use super::*;
use std::sync::{Arc, Mutex};
use tempfile::tempdir;

#[test]
fn test_list_all_namespaces() {
let db = Arc::new(Mutex::new(Database::open(tempdir().unwrap().path()).unwrap()));
let db = Arc::new(Mutex::new(
Database::open(tempdir().unwrap().path()).unwrap(),
));
let repo = NamespaceRepository::new(db);
assert_eq!(repo.list_all_namespaces().unwrap(), Vec::<String>::new());
}

#[test]
fn test_create_namespace() {
let db = Arc::new(Mutex::new(Database::open(tempdir().unwrap().path()).unwrap()));
let db = Arc::new(Mutex::new(
Database::open(tempdir().unwrap().path()).unwrap(),
));
let repo = NamespaceRepository::new(db);
assert!(repo.create_namespace("test".to_string(), None).is_ok());
}

#[test]
fn test_load_namespace() {
let db = Arc::new(Mutex::new(Database::open(tempdir().unwrap().path()).unwrap()));
let db = Arc::new(Mutex::new(
Database::open(tempdir().unwrap().path()).unwrap(),
));
let repo = NamespaceRepository::new(db);
repo.create_namespace("test".to_string(), None).unwrap();
assert!(repo.load_namespace("test").unwrap().is_some());
}

#[test]
fn test_namespace_exists() {
let db = Arc::new(Mutex::new(Database::open(tempdir().unwrap().path()).unwrap()));
let db = Arc::new(Mutex::new(
Database::open(tempdir().unwrap().path()).unwrap(),
));
let repo = NamespaceRepository::new(db);
repo.create_namespace("test".to_string(), None).unwrap();
assert!(repo.namespace_exists("test").unwrap());
}

#[test]
fn test_delete_namespace() {
let db = Arc::new(Mutex::new(Database::open(tempdir().unwrap().path()).unwrap()));
let db = Arc::new(Mutex::new(
Database::open(tempdir().unwrap().path()).unwrap(),
));
let repo = NamespaceRepository::new(db);
repo.create_namespace("test".to_string(), None).unwrap();
assert!(repo.delete_namespace("test").is_ok());
}

#[test]
fn test_set_namespace_properties() {
let db = Arc::new(Mutex::new(Database::open(tempdir().unwrap().path()).unwrap()));
let db = Arc::new(Mutex::new(
Database::open(tempdir().unwrap().path()).unwrap(),
));
let repo = NamespaceRepository::new(db);
repo.create_namespace("test".to_string(), None).unwrap();
assert!(repo.set_namespace_properties("test", json!({"property": "value"})).is_ok());
assert!(repo
.set_namespace_properties("test", json!({"property": "value"}))
.is_ok());
}

#[test]
fn test_load_namespace_not_found() {
let db = Arc::new(Mutex::new(Database::open(tempdir().unwrap().path()).unwrap()));
let db = Arc::new(Mutex::new(
Database::open(tempdir().unwrap().path()).unwrap(),
));
let repo = NamespaceRepository::new(db);
assert!(repo.load_namespace("nonexistent").unwrap().is_none());
}

#[test]
fn test_namespace_exists_not_found() {
let db = Arc::new(Mutex::new(Database::open(tempdir().unwrap().path()).unwrap()));
let db = Arc::new(Mutex::new(
Database::open(tempdir().unwrap().path()).unwrap(),
));
let repo = NamespaceRepository::new(db);
assert!(!repo.namespace_exists("nonexistent").unwrap());
}
Expand All @@ -140,9 +158,13 @@ mod tests {

#[test]
fn test_set_namespace_properties_not_found() {
let db = Arc::new(Mutex::new(Database::open(tempdir().unwrap().path()).unwrap()));
let db = Arc::new(Mutex::new(
Database::open(tempdir().unwrap().path()).unwrap(),
));
let repo = NamespaceRepository::new(db);
assert!(repo.set_namespace_properties("nonexistent", json!({"property": "value"})).is_err());
assert!(repo
.set_namespace_properties("nonexistent", json!({"property": "value"}))
.is_err());
}

// #[test]
Expand All @@ -162,9 +184,13 @@ mod tests {

#[test]
fn test_set_namespace_properties_empty_name() {
let db = Arc::new(Mutex::new(Database::open(tempdir().unwrap().path()).unwrap()));
let db = Arc::new(Mutex::new(
Database::open(tempdir().unwrap().path()).unwrap(),
));
let repo = NamespaceRepository::new(db);
assert!(repo.set_namespace_properties("", json!({"property": "value"})).is_err());
assert!(repo
.set_namespace_properties("", json!({"property": "value"}))
.is_err());
}

// #[test]
Expand All @@ -177,14 +203,18 @@ mod tests {

#[test]
fn test_load_namespace_empty_name() {
let db = Arc::new(Mutex::new(Database::open(tempdir().unwrap().path()).unwrap()));
let db = Arc::new(Mutex::new(
Database::open(tempdir().unwrap().path()).unwrap(),
));
let repo = NamespaceRepository::new(db);
assert!(repo.load_namespace("").unwrap().is_none());
}

#[test]
fn test_namespace_exists_empty_name() {
let db = Arc::new(Mutex::new(Database::open(tempdir().unwrap().path()).unwrap()));
let db = Arc::new(Mutex::new(
Database::open(tempdir().unwrap().path()).unwrap(),
));
let repo = NamespaceRepository::new(db);
assert!(!repo.namespace_exists("").unwrap());
}
Expand All @@ -198,22 +228,30 @@ mod tests {

#[test]
fn test_create_namespace_null_properties() {
let db = Arc::new(Mutex::new(Database::open(tempdir().unwrap().path()).unwrap()));
let db = Arc::new(Mutex::new(
Database::open(tempdir().unwrap().path()).unwrap(),
));
let repo = NamespaceRepository::new(db);
assert!(repo.create_namespace("test".to_string(), Some(json!(null))).is_ok());
assert!(repo
.create_namespace("test".to_string(), Some(json!(null)))
.is_ok());
}

#[test]
fn test_set_namespace_properties_null() {
let db = Arc::new(Mutex::new(Database::open(tempdir().unwrap().path()).unwrap()));
let db = Arc::new(Mutex::new(
Database::open(tempdir().unwrap().path()).unwrap(),
));
let repo = NamespaceRepository::new(db);
repo.create_namespace("test".to_string(), None).unwrap();
assert!(repo.set_namespace_properties("test", json!(null)).is_ok());
}

#[test]
fn test_set_namespace_properties_with_empty_json() {
let db = Arc::new(Mutex::new(Database::open(tempdir().unwrap().path()).unwrap()));
let db = Arc::new(Mutex::new(
Database::open(tempdir().unwrap().path()).unwrap(),
));
let repo = NamespaceRepository::new(db);
repo.create_namespace("test".to_string(), None).unwrap();
assert!(repo.set_namespace_properties("test", json!({})).is_ok());
Expand Down

0 comments on commit 954b5d2

Please sign in to comment.