-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinks.rs
82 lines (65 loc) · 2.18 KB
/
links.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use mystuff::datastore::memory::MemoryDataStore;
use mystuff::datastore::DataStore;
use mystuff::links::add_link;
#[test]
fn should_create_a_link() {
let new_url = String::from("http://www.example.com");
let new_description = String::from("description");
let new_tags = vec![String::from("tag1"), String::from("tag2")];
let created_link = add_link(
&mut MemoryDataStore::new(),
new_url.clone(),
new_tags.clone(),
Some(new_description.clone()),
);
assert_eq!(created_link.url, new_url);
assert_eq!(created_link.description, new_description);
for tag in new_tags {
assert!(created_link.tags.contains(&tag.clone()));
}
}
#[test]
fn should_store_link_in_datastore() {
let mut datastore = MemoryDataStore::new();
let new_url = String::from("http://www.example.com");
let new_description = String::from("description");
let new_tags = vec![String::from("tag1"), String::from("tag2")];
add_link(
&mut datastore,
new_url.clone(),
new_tags.clone(),
Some(new_description.clone()),
);
let links = datastore.get_links();
assert!(links.contains_key(&new_url));
let stored_url = links.get(&new_url).unwrap();
assert_eq!(stored_url.url, new_url);
assert_eq!(stored_url.description, new_description);
for tag in new_tags {
assert!(stored_url.tags.contains(&tag.clone()));
}
}
#[test]
fn should_return_an_existing_link_because_already_exists() {
let mut datastore = MemoryDataStore::new();
let new_url = String::from("http://www.example.com");
let new_description = String::from("description");
let new_tags = vec![String::from("tag1"), String::from("tag2")];
add_link(
&mut datastore,
new_url.clone(),
new_tags.clone(),
Some(new_description.clone()),
);
let existing_link = add_link(
&mut datastore,
new_url.clone(),
new_tags.clone(),
Some(new_description.clone()),
);
assert_eq!(existing_link.url, new_url);
assert_eq!(existing_link.description, new_description);
for tag in new_tags {
assert!(existing_link.tags.contains(&tag.clone()));
}
}