Skip to content

Commit

Permalink
Use ConfigBuilder in env.rs tests
Browse files Browse the repository at this point in the history
  • Loading branch information
szarykott committed May 8, 2021
1 parent 09498fc commit acc048e
Show file tree
Hide file tree
Showing 3 changed files with 399 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;
use std::fmt::Debug;

use builder::ConfigBuilder;
use crate::builder::ConfigBuilder;
use serde::de::Deserialize;
use serde::ser::Serialize;

Expand Down
96 changes: 48 additions & 48 deletions tests/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ fn test_parse_int() {
env::set_var("INT_VAL", "42");

let environment = Environment::new().try_parsing(true);
let mut config = Config::default();

config.set("tag", "Int").unwrap();

config.merge(environment).unwrap();
let config = Config::builder()
.set_default("tag", "Int").unwrap()
.add_source(environment)
.build().unwrap();

let config: TestIntEnum = config.try_into().unwrap();

Expand All @@ -135,11 +135,11 @@ fn test_parse_float() {
env::set_var("FLOAT_VAL", "42.3");

let environment = Environment::new().try_parsing(true);
let mut config = Config::default();

config.set("tag", "Float").unwrap();

config.merge(environment).unwrap();
let config = Config::builder()
.set_default("tag", "Float").unwrap()
.add_source(environment)
.build().unwrap();

let config: TestFloatEnum = config.try_into().unwrap();

Expand Down Expand Up @@ -168,11 +168,11 @@ fn test_parse_bool() {
env::set_var("BOOL_VAL", "true");

let environment = Environment::new().try_parsing(true);
let mut config = Config::default();

config.set("tag", "Bool").unwrap();

config.merge(environment).unwrap();
let config = Config::builder()
.set_default("tag", "Bool").unwrap()
.add_source(environment)
.build().unwrap();

let config: TestBoolEnum = config.try_into().unwrap();

Expand Down Expand Up @@ -202,11 +202,11 @@ fn test_parse_off_int() {
env::set_var("INT_VAL_1", "42");

let environment = Environment::new().try_parsing(false);
let mut config = Config::default();

config.set("tag", "Int").unwrap();

config.merge(environment).unwrap();

let config = Config::builder()
.set_default("tag", "Int").unwrap()
.add_source(environment)
.build().unwrap();

env::remove_var("INT_VAL_1");

Expand All @@ -231,11 +231,11 @@ fn test_parse_off_float() {
env::set_var("FLOAT_VAL_1", "42.3");

let environment = Environment::new().try_parsing(false);
let mut config = Config::default();

config.set("tag", "Float").unwrap();

config.merge(environment).unwrap();

let config = Config::builder()
.set_default("tag", "Float").unwrap()
.add_source(environment)
.build().unwrap();

env::remove_var("FLOAT_VAL_1");

Expand All @@ -260,11 +260,11 @@ fn test_parse_off_bool() {
env::set_var("BOOL_VAL_1", "true");

let environment = Environment::new().try_parsing(false);
let mut config = Config::default();

config.set("tag", "Bool").unwrap();

config.merge(environment).unwrap();
let config = Config::builder()
.set_default("tag", "Bool").unwrap()
.add_source(environment)
.build().unwrap();

env::remove_var("BOOL_VAL_1");

Expand All @@ -289,11 +289,11 @@ fn test_parse_int_fail() {
env::set_var("INT_VAL_2", "not an int");

let environment = Environment::new().try_parsing(true);
let mut config = Config::default();

config.set("tag", "Int").unwrap();

config.merge(environment).unwrap();
let config = Config::builder()
.set_default("tag", "Int").unwrap()
.add_source(environment)
.build().unwrap();

env::remove_var("INT_VAL_2");

Expand All @@ -318,11 +318,11 @@ fn test_parse_float_fail() {
env::set_var("FLOAT_VAL_2", "not a float");

let environment = Environment::new().try_parsing(true);
let mut config = Config::default();

config.set("tag", "Float").unwrap();

config.merge(environment).unwrap();
let config = Config::builder()
.set_default("tag", "Float").unwrap()
.add_source(environment)
.build().unwrap();

env::remove_var("FLOAT_VAL_2");

Expand All @@ -347,11 +347,11 @@ fn test_parse_bool_fail() {
env::set_var("BOOL_VAL_2", "not a bool");

let environment = Environment::new().try_parsing(true);
let mut config = Config::default();

config.set("tag", "Bool").unwrap();

config.merge(environment).unwrap();

let config = Config::builder()
.set_default("tag", "Bool").unwrap()
.add_source(environment)
.build().unwrap();

env::remove_var("BOOL_VAL_2");

Expand All @@ -375,11 +375,11 @@ fn test_parse_string() {
env::set_var("STRING_VAL", "test string");

let environment = Environment::new().try_parsing(true);
let mut config = Config::default();

config.set("tag", "String").unwrap();

config.merge(environment).unwrap();

let config = Config::builder()
.set_default("tag", "String").unwrap()
.add_source(environment)
.build().unwrap();

let config: TestStringEnum = config.try_into().unwrap();

Expand Down Expand Up @@ -409,11 +409,11 @@ fn test_parse_off_string() {
env::set_var("STRING_VAL_1", "test string");

let environment = Environment::new().try_parsing(false);
let mut config = Config::default();

config.set("tag", "String").unwrap();

config.merge(environment).unwrap();
let config = Config::builder()
.set_default("tag", "String").unwrap()
.add_source(environment)
.build().unwrap();

let config: TestStringEnum = config.try_into().unwrap();

Expand Down

0 comments on commit acc048e

Please sign in to comment.