Skip to content

Commit 5ce1c93

Browse files
committed
test(ron): Reduce the scope of fixtures
1 parent 925da09 commit 5ce1c93

File tree

1 file changed

+108
-15
lines changed

1 file changed

+108
-15
lines changed

tests/testsuite/file_ron.rs

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

3-
use std::path::PathBuf;
4-
53
use chrono::{DateTime, TimeZone, Utc};
64
use float_cmp::ApproxEqUlps;
75
use serde_derive::Deserialize;
@@ -33,7 +31,33 @@ fn test_file() {
3331
}
3432

3533
let c = Config::builder()
36-
.add_source(File::new("tests/Settings", FileFormat::Ron))
34+
.add_source(File::from_str(
35+
r#"
36+
(
37+
debug: true,
38+
production: false,
39+
arr: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
40+
place: (
41+
initials: ('T', 'P'),
42+
name: "Torre di Pisa",
43+
longitude: 43.7224985,
44+
latitude: 10.3970522,
45+
favorite: false,
46+
reviews: 3866,
47+
rating: Some(4.5),
48+
telephone: None,
49+
creator: {
50+
"name": "John Smith",
51+
"username": "jsmith",
52+
"email": "jsmith@localhost"
53+
}
54+
),
55+
FOO: "FOO should be overridden",
56+
bar: "I am bar"
57+
)
58+
"#,
59+
FileFormat::Ron,
60+
))
3761
.build()
3862
.unwrap();
3963

@@ -75,16 +99,19 @@ fn test_file() {
7599
#[test]
76100
fn test_error_parse() {
77101
let res = Config::builder()
78-
.add_source(File::new("tests/Settings-invalid", FileFormat::Ron))
102+
.add_source(File::from_str(
103+
r#"
104+
(
105+
ok: true,
106+
error
107+
)
108+
"#,
109+
FileFormat::Ron,
110+
))
79111
.build();
80112

81-
let path_with_extension: PathBuf = ["tests", "Settings-invalid.ron"].iter().collect();
82-
83113
assert!(res.is_err());
84-
assert_eq!(
85-
res.unwrap_err().to_string(),
86-
format!("4:1: Expected colon in {}", path_with_extension.display())
87-
);
114+
assert_eq!(res.unwrap_err().to_string(), format!("5:1: Expected colon"));
88115
}
89116

90117
#[test]
@@ -104,7 +131,33 @@ fn test_override_uppercase_value_for_struct() {
104131
std::env::set_var("APP_FOO", "I HAVE BEEN OVERRIDDEN_WITH_UPPER_CASE");
105132

106133
let cfg = Config::builder()
107-
.add_source(File::new("tests/Settings", FileFormat::Ron))
134+
.add_source(File::from_str(
135+
r#"
136+
(
137+
debug: true,
138+
production: false,
139+
arr: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
140+
place: (
141+
initials: ('T', 'P'),
142+
name: "Torre di Pisa",
143+
longitude: 43.7224985,
144+
latitude: 10.3970522,
145+
favorite: false,
146+
reviews: 3866,
147+
rating: Some(4.5),
148+
telephone: None,
149+
creator: {
150+
"name": "John Smith",
151+
"username": "jsmith",
152+
"email": "jsmith@localhost"
153+
}
154+
),
155+
FOO: "FOO should be overridden",
156+
bar: "I am bar"
157+
)
158+
"#,
159+
FileFormat::Ron,
160+
))
108161
.add_source(config::Environment::with_prefix("APP").separator("_"))
109162
.build()
110163
.unwrap();
@@ -145,7 +198,33 @@ fn test_override_lowercase_value_for_struct() {
145198
std::env::set_var("config_foo", "I have been overridden_with_lower_case");
146199

147200
let cfg = Config::builder()
148-
.add_source(File::new("tests/Settings", FileFormat::Ron))
201+
.add_source(File::from_str(
202+
r#"
203+
(
204+
debug: true,
205+
production: false,
206+
arr: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
207+
place: (
208+
initials: ('T', 'P'),
209+
name: "Torre di Pisa",
210+
longitude: 43.7224985,
211+
latitude: 10.3970522,
212+
favorite: false,
213+
reviews: 3866,
214+
rating: Some(4.5),
215+
telephone: None,
216+
creator: {
217+
"name": "John Smith",
218+
"username": "jsmith",
219+
"email": "jsmith@localhost"
220+
}
221+
),
222+
FOO: "FOO should be overridden",
223+
bar: "I am bar"
224+
)
225+
"#,
226+
FileFormat::Ron,
227+
))
149228
.add_source(config::Environment::with_prefix("config").separator("_"))
150229
.build()
151230
.unwrap();
@@ -168,7 +247,14 @@ fn test_override_uppercase_value_for_enums() {
168247
std::env::set_var("APPS_BAR", "I HAVE BEEN OVERRIDDEN_WITH_UPPER_CASE");
169248

170249
let cfg = Config::builder()
171-
.add_source(File::new("tests/Settings-enum-test", FileFormat::Ron))
250+
.add_source(File::from_str(
251+
r#"
252+
(
253+
bar: "bar is a lowercase param"
254+
)
255+
"#,
256+
FileFormat::Ron,
257+
))
172258
.add_source(config::Environment::with_prefix("APPS").separator("_"))
173259
.build()
174260
.unwrap();
@@ -190,7 +276,14 @@ fn test_override_lowercase_value_for_enums() {
190276
std::env::set_var("test_bar", "I have been overridden_with_lower_case");
191277

192278
let cfg = Config::builder()
193-
.add_source(File::new("tests/Settings-enum-test", FileFormat::Ron))
279+
.add_source(File::from_str(
280+
r#"
281+
(
282+
bar: "bar is a lowercase param"
283+
)
284+
"#,
285+
FileFormat::Ron,
286+
))
194287
.add_source(config::Environment::with_prefix("test").separator("_"))
195288
.build()
196289
.unwrap();
@@ -211,7 +304,7 @@ fn ron() {
211304
(
212305
ron_datetime: "2021-04-19T11:33:02Z"
213306
)
214-
"#,
307+
"#,
215308
FileFormat::Ron,
216309
))
217310
.build()

0 commit comments

Comments
 (0)