This repository has been archived by the owner on Nov 8, 2021. It is now read-only.
forked from rustwasm/wasm-pack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstamps.rs
71 lines (60 loc) · 1.48 KB
/
stamps.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
use std::{fs, panic};
use wasm_pack::stamps;
fn run_test<T>(test: T) -> ()
where
T: FnOnce() -> () + panic::UnwindSafe,
{
before();
let result = panic::catch_unwind(|| test());
after();
assert!(result.is_ok())
}
fn before() {
remove_stamps_file()
}
fn after() {
remove_stamps_file()
}
fn remove_stamps_file() {
let stamps_file_path = stamps::get_stamps_file_path().unwrap();
if stamps_file_path.exists() {
fs::remove_file(stamps_file_path).unwrap();
}
}
#[test]
#[should_panic]
#[serial]
fn load_stamp_from_non_existent_file() {
run_test(|| {
// ACT
let json = stamps::read_stamps_file_to_json().unwrap();
stamps::get_stamp_value("Foo", &json).unwrap();
})
}
#[test]
#[serial]
fn load_stamp() {
run_test(|| {
// ARRANGE
stamps::save_stamp_value("Foo", "Bar").unwrap();
// ACT
let json = stamps::read_stamps_file_to_json().unwrap();
let stamp_value = stamps::get_stamp_value("Foo", &json).unwrap();
// ASSERT
assert_eq!(stamp_value, "Bar");
})
}
#[test]
#[serial]
fn update_stamp() {
run_test(|| {
// ARRANGE
stamps::save_stamp_value("Foo", "Bar").unwrap();
// ACT
stamps::save_stamp_value("Foo", "John").unwrap();
// ASSERT
let json = stamps::read_stamps_file_to_json().unwrap();
let stamp_value = stamps::get_stamp_value("Foo", &json).unwrap();
assert_eq!(stamp_value, "John");
})
}