Skip to content

Commit c1b4ca2

Browse files
committed
test(ini): Reduce the scope of fixtures
1 parent ad1a4ea commit c1b4ca2

File tree

1 file changed

+68
-14
lines changed

1 file changed

+68
-14
lines changed

tests/testsuite/file_ini.rs

Lines changed: 68 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#![cfg(feature = "ini")]
22

3-
use std::path::PathBuf;
4-
53
use chrono::{DateTime, TimeZone, Utc};
64
use serde_derive::Deserialize;
75

@@ -26,7 +24,22 @@ fn test_file() {
2624
}
2725

2826
let c = Config::builder()
29-
.add_source(File::new("tests/Settings", FileFormat::Ini))
27+
.add_source(File::from_str(
28+
r#"
29+
debug = true
30+
production = false
31+
FOO = FOO should be overridden
32+
bar = I am bar
33+
[place]
34+
name = Torre di Pisa
35+
longitude = 43.7224985
36+
latitude = 10.3970522
37+
favorite = false
38+
reviews = 3866
39+
rating = 4.5
40+
"#,
41+
FileFormat::Ini,
42+
))
3043
.build()
3144
.unwrap();
3245
let s: Settings = c.try_deserialize().unwrap();
@@ -49,18 +62,19 @@ fn test_file() {
4962
#[test]
5063
fn test_error_parse() {
5164
let res = Config::builder()
52-
.add_source(File::new("tests/Settings-invalid", FileFormat::Ini))
65+
.add_source(File::from_str(
66+
r#"
67+
ok : true,
68+
error
69+
"#,
70+
FileFormat::Ini,
71+
))
5372
.build();
5473

55-
let path: PathBuf = ["tests", "Settings-invalid.ini"].iter().collect();
56-
5774
assert!(res.is_err());
5875
assert_eq!(
5976
res.unwrap_err().to_string(),
60-
format!(
61-
r#"3:1 expecting "[Some('='), Some(':')]" but found EOF. in {}"#,
62-
path.display()
63-
)
77+
format!(r#"4:1 expecting "[Some('='), Some(':')]" but found EOF."#,)
6478
);
6579
}
6680

@@ -81,7 +95,22 @@ fn test_override_uppercase_value_for_struct() {
8195
std::env::set_var("APP_FOO", "I HAVE BEEN OVERRIDDEN_WITH_UPPER_CASE");
8296

8397
let cfg = Config::builder()
84-
.add_source(File::new("tests/Settings", FileFormat::Ini))
98+
.add_source(File::from_str(
99+
r#"
100+
debug = true
101+
production = false
102+
FOO = FOO should be overridden
103+
bar = I am bar
104+
[place]
105+
name = Torre di Pisa
106+
longitude = 43.7224985
107+
latitude = 10.3970522
108+
favorite = false
109+
reviews = 3866
110+
rating = 4.5
111+
"#,
112+
FileFormat::Ini,
113+
))
85114
.add_source(config::Environment::with_prefix("APP").separator("_"))
86115
.build()
87116
.unwrap();
@@ -121,7 +150,22 @@ fn test_override_lowercase_value_for_struct() {
121150
std::env::set_var("config_foo", "I have been overridden_with_lower_case");
122151

123152
let cfg = Config::builder()
124-
.add_source(File::new("tests/Settings", FileFormat::Ini))
153+
.add_source(File::from_str(
154+
r#"
155+
debug = true
156+
production = false
157+
FOO = FOO should be overridden
158+
bar = I am bar
159+
[place]
160+
name = Torre di Pisa
161+
longitude = 43.7224985
162+
latitude = 10.3970522
163+
favorite = false
164+
reviews = 3866
165+
rating = 4.5
166+
"#,
167+
FileFormat::Ini,
168+
))
125169
.add_source(config::Environment::with_prefix("config").separator("_"))
126170
.build()
127171
.unwrap();
@@ -144,7 +188,12 @@ fn test_override_uppercase_value_for_enums() {
144188
std::env::set_var("APPS_BAR", "I HAVE BEEN OVERRIDDEN_WITH_UPPER_CASE");
145189

146190
let cfg = Config::builder()
147-
.add_source(File::new("tests/Settings-enum-test", FileFormat::Ini))
191+
.add_source(File::from_str(
192+
r#"
193+
bar = "bar is a lowercase param"
194+
"#,
195+
FileFormat::Ini,
196+
))
148197
.add_source(config::Environment::with_prefix("APPS").separator("_"))
149198
.build()
150199
.unwrap();
@@ -166,7 +215,12 @@ fn test_override_lowercase_value_for_enums() {
166215
std::env::set_var("test_bar", "I have been overridden_with_lower_case");
167216

168217
let cfg = Config::builder()
169-
.add_source(File::new("tests/Settings-enum-test", FileFormat::Ini))
218+
.add_source(File::from_str(
219+
r#"
220+
bar = "bar is a lowercase param"
221+
"#,
222+
FileFormat::Ini,
223+
))
170224
.add_source(config::Environment::with_prefix("test").separator("_"))
171225
.build()
172226
.unwrap();

0 commit comments

Comments
 (0)