-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Allan Zhang
committed
Aug 23, 2022
1 parent
22beeb4
commit 269a343
Showing
11 changed files
with
101 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,22 @@ | ||
mod common; | ||
|
||
use dotenvy::*; | ||
use std::{env, fs}; | ||
use std::{env, error::Error, fs, result::Result}; | ||
|
||
use crate::common::*; | ||
|
||
#[test] | ||
fn test_child_dir() { | ||
let dir = make_test_dotenv().unwrap(); | ||
fn test_child_dir() -> Result<(), Box<dyn Error>> { | ||
let dir = make_test_dotenv()?; | ||
|
||
fs::create_dir("child").unwrap(); | ||
fs::create_dir("child")?; | ||
|
||
env::set_current_dir("child").unwrap(); | ||
env::set_current_dir("child")?; | ||
|
||
dotenv().ok(); | ||
assert_eq!(env::var("TESTKEY").unwrap(), "test_val"); | ||
dotenv()?; | ||
assert_eq!(env::var("TESTKEY")?, "test_val"); | ||
|
||
env::set_current_dir(dir.path().parent().unwrap()).unwrap(); | ||
dir.close().unwrap(); | ||
env::set_current_dir(dir.path().parent().unwrap())?; | ||
dir.close()?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
mod common; | ||
|
||
use dotenvy::*; | ||
use std::env; | ||
|
||
use std::{env, error::Error, result::Result}; | ||
|
||
use crate::common::*; | ||
|
||
#[test] | ||
fn test_default_location() { | ||
let dir = make_test_dotenv().unwrap(); | ||
fn test_default_location() -> Result<(), Box<dyn Error>> { | ||
let dir = make_test_dotenv()?; | ||
|
||
dotenv().ok(); | ||
assert_eq!(env::var("TESTKEY").unwrap(), "test_val"); | ||
dotenv()?; | ||
assert_eq!(env::var("TESTKEY")?, "test_val"); | ||
|
||
env::set_current_dir(dir.path().parent().unwrap()).unwrap(); | ||
dir.close().unwrap(); | ||
env::set_current_dir(dir.path().parent().unwrap())?; | ||
dir.close()?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,21 @@ | ||
mod common; | ||
|
||
use dotenvy::*; | ||
use std::env; | ||
use std::{env, error::Error, result::Result}; | ||
|
||
use crate::common::*; | ||
|
||
#[test] | ||
fn test_dotenv_iter() { | ||
let dir = make_test_dotenv().unwrap(); | ||
|
||
let iter = dotenv_iter().unwrap(); | ||
fn test_dotenv_iter() -> Result<(), Box<dyn Error>> { | ||
let dir = make_test_dotenv()?; | ||
|
||
let iter = dotenv_iter()?; | ||
assert!(env::var("TESTKEY").is_err()); | ||
|
||
iter.load().ok(); | ||
|
||
assert_eq!(env::var("TESTKEY").unwrap(), "test_val"); | ||
iter.load()?; | ||
assert_eq!(env::var("TESTKEY")?, "test_val"); | ||
|
||
env::set_current_dir(dir.path().parent().unwrap()).unwrap(); | ||
dir.close().unwrap(); | ||
env::set_current_dir(dir.path().parent().unwrap())?; | ||
dir.close()?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
mod common; | ||
|
||
use dotenvy::*; | ||
use std::env; | ||
use std::{env, error::Error, result::Result}; | ||
|
||
use crate::common::*; | ||
|
||
#[test] | ||
fn test_from_filename_iter() { | ||
let dir = make_test_dotenv().unwrap(); | ||
fn test_from_filename_iter() -> Result<(), Box<dyn Error>> { | ||
let dir = make_test_dotenv()?; | ||
|
||
let iter = from_filename_iter(".env").unwrap(); | ||
let iter = from_filename_iter(".env")?; | ||
|
||
assert!(env::var("TESTKEY").is_err()); | ||
|
||
iter.load().ok(); | ||
iter.load()?; | ||
|
||
assert_eq!(env::var("TESTKEY").unwrap(), "test_val"); | ||
|
||
env::set_current_dir(dir.path().parent().unwrap()).unwrap(); | ||
dir.close().unwrap(); | ||
env::set_current_dir(dir.path().parent().unwrap())?; | ||
dir.close()?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
mod common; | ||
|
||
use dotenvy::*; | ||
use std::env; | ||
use std::{env, error::Error, result::Result}; | ||
|
||
use crate::common::*; | ||
|
||
#[test] | ||
fn test_from_filename() { | ||
let dir = make_test_dotenv().unwrap(); | ||
fn test_from_filename() -> Result<(), Box<dyn Error>> { | ||
let dir = make_test_dotenv()?; | ||
|
||
from_filename(".env").ok(); | ||
from_filename(".env")?; | ||
|
||
assert_eq!(env::var("TESTKEY").unwrap(), "test_val"); | ||
assert_eq!(env::var("TESTKEY")?, "test_val"); | ||
|
||
env::set_current_dir(dir.path().parent().unwrap()).unwrap(); | ||
dir.close().unwrap(); | ||
env::set_current_dir(dir.path().parent().unwrap())?; | ||
dir.close()?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,26 @@ | ||
mod common; | ||
|
||
use dotenvy::*; | ||
use std::env; | ||
use std::{env, error::Error, result::Result}; | ||
|
||
use crate::common::*; | ||
|
||
#[test] | ||
fn test_from_path_iter() { | ||
let dir = make_test_dotenv().unwrap(); | ||
fn test_from_path_iter() -> Result<(), Box<dyn Error>> { | ||
let dir = make_test_dotenv()?; | ||
|
||
let mut path = env::current_dir().unwrap(); | ||
let mut path = env::current_dir()?; | ||
path.push(".env"); | ||
|
||
let iter = from_path_iter(&path).unwrap(); | ||
let iter = from_path_iter(&path)?; | ||
|
||
assert!(env::var("TESTKEY").is_err()); | ||
|
||
iter.load().ok(); | ||
iter.load()?; | ||
|
||
assert_eq!(env::var("TESTKEY").unwrap(), "test_val"); | ||
assert_eq!(env::var("TESTKEY")?, "test_val"); | ||
|
||
env::set_current_dir(dir.path().parent().unwrap()).unwrap(); | ||
dir.close().unwrap(); | ||
env::set_current_dir(dir.path().parent().unwrap())?; | ||
dir.close()?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
mod common; | ||
|
||
use dotenvy::*; | ||
use std::env; | ||
|
||
use crate::common::*; | ||
use dotenvy::*; | ||
use std::{env, error::Error, result::Result}; | ||
|
||
#[test] | ||
fn test_from_path() { | ||
let dir = make_test_dotenv().unwrap(); | ||
fn test_from_path() -> Result<(), Box<dyn Error>> { | ||
let dir = make_test_dotenv()?; | ||
|
||
let mut path = env::current_dir().unwrap(); | ||
let mut path = env::current_dir()?; | ||
path.push(".env"); | ||
|
||
from_path(&path).ok(); | ||
from_path(&path)?; | ||
|
||
assert_eq!(env::var("TESTKEY").unwrap(), "test_val"); | ||
assert_eq!(env::var("TESTKEY")?, "test_val"); | ||
|
||
env::set_current_dir(dir.path().parent().unwrap()).unwrap(); | ||
dir.close().unwrap(); | ||
env::set_current_dir(dir.path().parent().unwrap())?; | ||
dir.close()?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
mod common; | ||
|
||
use std::env; | ||
|
||
use dotenvy::*; | ||
use std::{env, error::Error, result::Result}; | ||
|
||
use crate::common::*; | ||
|
||
#[test] | ||
fn test_var() { | ||
let dir = make_test_dotenv().unwrap(); | ||
fn test_var() -> Result<(), Box<dyn Error>> { | ||
let dir = make_test_dotenv()?; | ||
|
||
assert_eq!(var("TESTKEY").unwrap(), "test_val"); | ||
assert_eq!(var("TESTKEY")?, "test_val"); | ||
|
||
env::set_current_dir(dir.path().parent().unwrap()).unwrap(); | ||
dir.close().unwrap(); | ||
env::set_current_dir(dir.path().parent().unwrap())?; | ||
dir.close()?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
mod common; | ||
|
||
use std::collections::HashMap; | ||
use std::env; | ||
use std::{collections::HashMap, env, error::Error, result::Result}; | ||
|
||
use dotenvy::*; | ||
|
||
use crate::common::*; | ||
|
||
#[test] | ||
fn test_vars() { | ||
let dir = make_test_dotenv().unwrap(); | ||
fn test_vars() -> Result<(), Box<dyn Error>> { | ||
let dir = make_test_dotenv()?; | ||
|
||
let vars: HashMap<String, String> = vars().collect(); | ||
|
||
assert_eq!(vars["TESTKEY"], "test_val"); | ||
|
||
env::set_current_dir(dir.path().parent().unwrap()).unwrap(); | ||
dir.close().unwrap(); | ||
env::set_current_dir(dir.path().parent().unwrap())?; | ||
dir.close()?; | ||
Ok(()) | ||
} |