forked from sdkman/sdkman-cli-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache.rs
More file actions
89 lines (73 loc) · 2.32 KB
/
cache.rs
File metadata and controls
89 lines (73 loc) · 2.32 KB
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
83
84
85
86
87
88
89
#[cfg(test)]
use std::env;
use std::fs;
use std::process::Command;
use assert_cmd::prelude::*;
use predicates::prelude::*;
use serial_test::serial;
use support::{prepare_sdkman_dir, write_file, VirtualEnv};
mod support;
#[test]
#[serial]
fn should_pass_with_valid_cache() -> Result<(), Box<dyn std::error::Error>> {
let sdkman_dir = support::virtual_env(VirtualEnv {
cli_version: "5.0.0".to_string(),
native_version: "0.1.0".to_string(),
candidates: vec![support::TestCandidate {
name: "java",
versions: vec!["17.0.0-tem"],
current_version: "17.0.0-tem",
}],
});
env::set_var("SDKMAN_DIR", sdkman_dir.path().as_os_str());
Command::new(assert_cmd::cargo::cargo_bin!("cache"))
.assert()
.success();
Ok(())
}
#[test]
#[serial]
fn should_fail_with_empty_cache() -> Result<(), Box<dyn std::error::Error>> {
let sdkman_dir = support::virtual_env(VirtualEnv {
cli_version: "5.0.0".to_string(),
native_version: "0.1.0".to_string(),
candidates: vec![],
});
env::set_var("SDKMAN_DIR", sdkman_dir.path().as_os_str());
let cache_path = sdkman_dir.path().join("var/candidates");
fs::write(&cache_path, "")?;
Command::new(assert_cmd::cargo::cargo_bin!("cache"))
.assert()
.failure()
.stderr(predicate::str::contains("Cache is corrupt"))
.stdout(predicate::str::contains("sdk update"));
Ok(())
}
#[test]
#[serial]
fn should_fail_with_missing_cache() -> Result<(), Box<dyn std::error::Error>> {
let sdkman_dir = prepare_sdkman_dir();
env::set_var("SDKMAN_DIR", sdkman_dir.path().as_os_str());
Command::new(assert_cmd::cargo::cargo_bin!("cache"))
.assert()
.failure()
.stderr(predicate::str::contains("Cache is corrupt"));
Ok(())
}
#[test]
#[serial]
fn should_fail_with_whitespace_only_cache() -> Result<(), Box<dyn std::error::Error>> {
let sdkman_dir = prepare_sdkman_dir();
env::set_var("SDKMAN_DIR", sdkman_dir.path().as_os_str());
write_file(
sdkman_dir.path(),
std::path::Path::new("var"),
"candidates",
" \n ".to_string(),
);
Command::new(assert_cmd::cargo::cargo_bin!("cache"))
.assert()
.failure()
.stderr(predicate::str::contains("Cache is corrupt"));
Ok(())
}