我正在编写一个服务,从文件中读取内容,该文件的位置是从环境变量FILE_LOCATION
读取的。
fn my_function(){
let path = match env::var("FILE_LOCATION") {
...
let contents = match fs::read(&path) {
}
我有一个测试文件 test_file.json
,位于:
proj
resources
test
test_file.json
src
main.rs
tests
unit_tests.rs
在测试中,我可以设置
FILE_LOCATION
:env::set_var("FILE_LOCATION", "path/to/test/file");
问题是
path/to/test/file
的值应该是什么?换句话说:
如何在Rust测试中访问外部文件?