sagiegurari / cargo-make
1
use super::*;
2
use semver::Version;
3

4
#[test]
5 8
fn print_notification_simple() {
6 8
    print_notification("1");
7 8
}
8

9
#[test]
10 8
fn get_version_from_output_empty() {
11 8
    let version = get_version_from_output("");
12

13 8
    assert!(version.is_none());
14 8
}
15

16
#[test]
17 8
fn get_version_from_output_few_args() {
18 8
    let version = get_version_from_output("1 2");
19

20 8
    assert!(version.is_none());
21 8
}
22

23
#[test]
24 8
fn get_version_from_output_found() {
25 8
    let version = get_version_from_output("1 2 \"1.2.3\" 4 5 6");
26

27 8
    assert_eq!(version.unwrap(), "1.2.3");
28 8
}
29

30
#[test]
31 8
fn is_newer_found_same() {
32 8
    let current = env!("CARGO_PKG_VERSION");
33 8
    let newer = is_newer_found(current);
34

35 8
    assert!(!newer);
36 8
}
37

38
#[test]
39 8
fn is_newer_found_newer_major() {
40 8
    let current = env!("CARGO_PKG_VERSION");
41 8
    let version = Version::parse(current).unwrap();
42 8
    let version_string = (version.major + 1).to_string()
43 8
        + "."
44 8
        + &version.minor.to_string()
45 8
        + "."
46 8
        + &version.patch.to_string();
47

48 8
    let newer = is_newer_found(&version_string);
49

50 8
    assert!(newer);
51 8
}
52

53
#[test]
54 8
fn is_newer_found_newer_minor() {
55 8
    let current = env!("CARGO_PKG_VERSION");
56 8
    let version = Version::parse(current).unwrap();
57 8
    let version_string = version.major.to_string()
58 8
        + "."
59 8
        + &(version.minor + 1).to_string()
60 8
        + "."
61 8
        + &version.patch.to_string();
62

63 8
    let newer = is_newer_found(&version_string);
64

65 8
    assert!(newer);
66 8
}
67

68
#[test]
69 8
fn is_newer_found_newer_patch() {
70 8
    let current = env!("CARGO_PKG_VERSION");
71 8
    let version = Version::parse(current).unwrap();
72 8
    let version_string = version.major.to_string()
73 8
        + "."
74 8
        + &version.minor.to_string()
75 8
        + "."
76 8
        + &(version.patch + 1).to_string();
77

78 8
    let newer = is_newer_found(&version_string);
79

80 8
    assert!(newer);
81 8
}
82

83
#[test]
84 8
fn is_newer_found_older_major_newer_minor() {
85 8
    let current = env!("CARGO_PKG_VERSION");
86 8
    let version = Version::parse(current).unwrap();
87 8
    let version_string = (version.major as i64 - 1).to_string()
88 8
        + "."
89 8
        + &(version.minor + 1).to_string()
90 8
        + "."
91 8
        + &version.patch.to_string();
92

93 8
    let newer = is_newer_found(&version_string);
94

95 8
    assert!(!newer);
96 8
}
97

98
#[test]
99 8
fn is_newer_found_older_major_newer_patch() {
100 8
    let current = env!("CARGO_PKG_VERSION");
101 8
    let version = Version::parse(current).unwrap();
102 8
    let version_string = (version.major as i64 - 1).to_string()
103 8
        + "."
104 8
        + &version.minor.to_string()
105 8
        + "."
106 8
        + &(version.patch + 1).to_string();
107

108 8
    let newer = is_newer_found(&version_string);
109

110 8
    assert!(!newer);
111 8
}
112

113
#[test]
114 8
fn is_newer_found_older_minor_newer_patch() {
115 8
    let current = env!("CARGO_PKG_VERSION");
116 8
    let version = Version::parse(current).unwrap();
117 8
    let version_string = version.major.to_string()
118 8
        + "."
119 8
        + &(version.minor as i64 - 1).to_string()
120 8
        + "."
121 8
        + &(version.patch + 1).to_string();
122

123 8
    let newer = is_newer_found(&version_string);
124

125 8
    assert!(!newer);
126 8
}
127

128
#[test]
129 8
fn check_full() {
130 8
    check();
131 8
}
132

133
#[test]
134 8
fn get_now_as_seconds_valid() {
135 8
    let now = get_now_as_seconds();
136 8
    assert!(now > 0);
137 8
}
138

139
#[test]
140 8
fn has_amount_of_days_passed_from_last_check_zero_days() {
141 8
    let passed = has_amount_of_days_passed_from_last_check(0, 1);
142 8
    assert!(passed);
143 8
}
144

145
#[test]
146 8
fn has_amount_of_days_passed_from_last_check_false() {
147 8
    let last_check = get_now_as_seconds();
148 8
    let passed = has_amount_of_days_passed_from_last_check(1, last_check);
149 8
    assert!(!passed);
150 8
}
151

152
#[test]
153 8
fn has_amount_of_days_passed_from_last_check_true_by_day() {
154 8
    let last_check = get_now_as_seconds() - (4 * 24 * 60 * 60);
155 8
    let passed = has_amount_of_days_passed_from_last_check(3, last_check);
156 8
    assert!(passed);
157 8
}
158

159
#[test]
160 8
fn has_amount_of_days_passed_from_last_check_true_by_second() {
161 8
    let last_check = get_now_as_seconds() - (24 * 60 * 60) - 1;
162 8
    let passed = has_amount_of_days_passed_from_last_check(1, last_check);
163 8
    assert!(passed);
164 8
}
165

166
#[test]
167 8
fn has_amount_of_days_passed_from_last_check_false_by_second() {
168 8
    let last_check = get_now_as_seconds() - (24 * 60 * 60) + 1;
169 8
    let passed = has_amount_of_days_passed_from_last_check(1, last_check);
170 8
    assert!(!passed);
171 8
}
172

173
#[test]
174 8
fn has_amount_of_days_passed_none() {
175 8
    let cache = Cache::new();
176 8
    let passed = has_amount_of_days_passed(300, &cache);
177 8
    assert!(passed);
178 8
}
179

180
#[test]
181 8
fn has_amount_of_days_passed_zero_days() {
182 8
    let last_check = get_now_as_seconds();
183 8
    let mut cache = Cache::new();
184 8
    cache.last_update_check = Some(last_check);
185 8
    let passed = has_amount_of_days_passed(0, &cache);
186 8
    assert!(passed);
187 8
}
188

189
#[test]
190 8
fn has_amount_of_days_passed_false() {
191 8
    let last_check = get_now_as_seconds();
192 8
    let mut cache = Cache::new();
193 8
    cache.last_update_check = Some(last_check);
194 8
    let passed = has_amount_of_days_passed(1, &cache);
195 8
    assert!(!passed);
196 8
}
197

198
#[test]
199 8
fn has_amount_of_days_passed_true_by_day() {
200 8
    let last_check = get_now_as_seconds() - (4 * 24 * 60 * 60);
201 8
    let mut cache = Cache::new();
202 8
    cache.last_update_check = Some(last_check);
203 8
    let passed = has_amount_of_days_passed(3, &cache);
204 8
    assert!(passed);
205 8
}
206

207
#[test]
208 8
fn has_amount_of_days_passed_true_by_second() {
209 8
    let last_check = get_now_as_seconds() - (24 * 60 * 60) - 1;
210 8
    let mut cache = Cache::new();
211 8
    cache.last_update_check = Some(last_check);
212 8
    let passed = has_amount_of_days_passed(1, &cache);
213 8
    assert!(passed);
214 8
}
215

216
#[test]
217 8
fn has_amount_of_days_passed_false_by_second() {
218 8
    let last_check = get_now_as_seconds() - (24 * 60 * 60) + 1;
219 8
    let mut cache = Cache::new();
220 8
    cache.last_update_check = Some(last_check);
221 8
    let passed = has_amount_of_days_passed(1, &cache);
222 8
    assert!(!passed);
223 8
}
224

225
#[test]
226 8
fn get_days_none() {
227 8
    let global_config = GlobalConfig::new();
228 8
    let days = get_days(&global_config);
229 8
    assert_eq!(days, 7);
230 8
}
231

232
#[test]
233 8
fn get_days_always() {
234 8
    let mut global_config = GlobalConfig::new();
235 8
    global_config.update_check_minimum_interval = Some("always".to_string());
236 8
    let days = get_days(&global_config);
237 8
    assert_eq!(days, 0);
238 8
}
239

240
#[test]
241 8
fn get_days_daily() {
242 8
    let mut global_config = GlobalConfig::new();
243 8
    global_config.update_check_minimum_interval = Some("daily".to_string());
244 8
    let days = get_days(&global_config);
245 8
    assert_eq!(days, 1);
246 8
}
247

248
#[test]
249 8
fn get_days_weekly() {
250 8
    let mut global_config = GlobalConfig::new();
251 8
    global_config.update_check_minimum_interval = Some("weekly".to_string());
252 8
    let days = get_days(&global_config);
253 8
    assert_eq!(days, 7);
254 8
}
255

256
#[test]
257 8
fn get_days_monthly() {
258 8
    let mut global_config = GlobalConfig::new();
259 8
    global_config.update_check_minimum_interval = Some("monthly".to_string());
260 8
    let days = get_days(&global_config);
261 8
    assert_eq!(days, 30);
262 8
}
263

264
#[test]
265 8
fn get_days_unknown() {
266 8
    let mut global_config = GlobalConfig::new();
267 8
    global_config.update_check_minimum_interval = Some("bad123".to_string());
268 8
    let days = get_days(&global_config);
269 8
    assert_eq!(days, 7);
270 8
}
271

272
#[test]
273 8
fn should_check_none() {
274 8
    let global_config = GlobalConfig::new();
275 8
    should_check(&global_config);
276 8
}
277

278
#[test]
279 8
fn should_check_always() {
280 8
    let mut global_config = GlobalConfig::new();
281 8
    global_config.update_check_minimum_interval = Some("always".to_string());
282 8
    let check = should_check(&global_config);
283 8
    assert!(check);
284 8
}
285

286
#[test]
287 8
fn should_check_other() {
288 8
    let mut global_config = GlobalConfig::new();
289 8
    global_config.update_check_minimum_interval = Some("weekly".to_string());
290 8
    should_check(&global_config);
291 8
}

Read our documentation on viewing source code .

Loading