Skip to content

Commit 81ee8de

Browse files
committed
test(toml): Reduce the scope of fixtures
1 parent 5ce1c93 commit 81ee8de

File tree

1 file changed

+213
-8
lines changed

1 file changed

+213
-8
lines changed

tests/testsuite/file_toml.rs

Lines changed: 213 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,70 @@ fn test_file() {
3838
struct AsciiCode(i8);
3939

4040
let c = Config::builder()
41-
.add_source(File::new("tests/Settings", FileFormat::Toml))
41+
.add_source(File::from_str(
42+
r#"
43+
debug = true
44+
debug_s = "true"
45+
production = false
46+
production_s = "false"
47+
48+
code = 53
49+
50+
# errors
51+
boolean_s_parse = "fals"
52+
53+
# For override tests
54+
FOO="FOO should be overridden"
55+
bar="I am bar"
56+
57+
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
58+
quarks = ["up", "down", "strange", "charm", "bottom", "top"]
59+
60+
[diodes]
61+
green = "off"
62+
63+
[diodes.red]
64+
brightness = 100
65+
66+
[diodes.blue]
67+
blinking = [300, 700]
68+
69+
[diodes.white.pattern]
70+
name = "christmas"
71+
inifinite = true
72+
73+
[[items]]
74+
name = "1"
75+
76+
[[items]]
77+
name = "2"
78+
79+
[place]
80+
number = 1
81+
name = "Torre di Pisa"
82+
longitude = 43.7224985
83+
latitude = 10.3970522
84+
favorite = false
85+
reviews = 3866
86+
rating = 4.5
87+
88+
[place.creator]
89+
name = "John Smith"
90+
username = "jsmith"
91+
email = "jsmith@localhost"
92+
93+
[proton]
94+
up = 2
95+
down = 1
96+
97+
[divisors]
98+
1 = 1
99+
2 = 2
100+
4 = 3
101+
5 = 2
102+
"#,
103+
FileFormat::Toml,
104+
))
42105
.build()
43106
.unwrap();
44107

@@ -81,14 +144,20 @@ fn test_file() {
81144
#[test]
82145
fn test_error_parse() {
83146
let res = Config::builder()
84-
.add_source(File::new("tests/Settings-invalid", FileFormat::Toml))
147+
.add_source(File::from_str(
148+
r#"
149+
ok = true
150+
error = tru
151+
"#,
152+
FileFormat::Toml,
153+
))
85154
.build();
86155

87156
assert!(res.is_err());
88157
assert!(res
89158
.unwrap_err()
90159
.to_string()
91-
.contains("TOML parse error at line 2, column 9"));
160+
.contains("TOML parse error at line 3, column 9"));
92161
}
93162

94163
#[test]
@@ -108,7 +177,70 @@ fn test_override_uppercase_value_for_struct() {
108177
std::env::set_var("APP_FOO", "I HAVE BEEN OVERRIDDEN_WITH_UPPER_CASE");
109178

110179
let cfg = Config::builder()
111-
.add_source(File::new("tests/Settings.toml", FileFormat::Toml))
180+
.add_source(File::from_str(
181+
r#"
182+
debug = true
183+
debug_s = "true"
184+
production = false
185+
production_s = "false"
186+
187+
code = 53
188+
189+
# errors
190+
boolean_s_parse = "fals"
191+
192+
# For override tests
193+
FOO="FOO should be overridden"
194+
bar="I am bar"
195+
196+
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
197+
quarks = ["up", "down", "strange", "charm", "bottom", "top"]
198+
199+
[diodes]
200+
green = "off"
201+
202+
[diodes.red]
203+
brightness = 100
204+
205+
[diodes.blue]
206+
blinking = [300, 700]
207+
208+
[diodes.white.pattern]
209+
name = "christmas"
210+
inifinite = true
211+
212+
[[items]]
213+
name = "1"
214+
215+
[[items]]
216+
name = "2"
217+
218+
[place]
219+
number = 1
220+
name = "Torre di Pisa"
221+
longitude = 43.7224985
222+
latitude = 10.3970522
223+
favorite = false
224+
reviews = 3866
225+
rating = 4.5
226+
227+
[place.creator]
228+
name = "John Smith"
229+
username = "jsmith"
230+
email = "jsmith@localhost"
231+
232+
[proton]
233+
up = 2
234+
down = 1
235+
236+
[divisors]
237+
1 = 1
238+
2 = 2
239+
4 = 3
240+
5 = 2
241+
"#,
242+
FileFormat::Toml,
243+
))
112244
.add_source(config::Environment::with_prefix("APP").separator("_"))
113245
.build()
114246
.unwrap();
@@ -149,7 +281,70 @@ fn test_override_lowercase_value_for_struct() {
149281
std::env::set_var("config_bar", "I have been overridden_with_lower_case");
150282

151283
let cfg = Config::builder()
152-
.add_source(File::new("tests/Settings.toml", FileFormat::Toml))
284+
.add_source(File::from_str(
285+
r#"
286+
debug = true
287+
debug_s = "true"
288+
production = false
289+
production_s = "false"
290+
291+
code = 53
292+
293+
# errors
294+
boolean_s_parse = "fals"
295+
296+
# For override tests
297+
FOO="FOO should be overridden"
298+
bar="I am bar"
299+
300+
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
301+
quarks = ["up", "down", "strange", "charm", "bottom", "top"]
302+
303+
[diodes]
304+
green = "off"
305+
306+
[diodes.red]
307+
brightness = 100
308+
309+
[diodes.blue]
310+
blinking = [300, 700]
311+
312+
[diodes.white.pattern]
313+
name = "christmas"
314+
inifinite = true
315+
316+
[[items]]
317+
name = "1"
318+
319+
[[items]]
320+
name = "2"
321+
322+
[place]
323+
number = 1
324+
name = "Torre di Pisa"
325+
longitude = 43.7224985
326+
latitude = 10.3970522
327+
favorite = false
328+
reviews = 3866
329+
rating = 4.5
330+
331+
[place.creator]
332+
name = "John Smith"
333+
username = "jsmith"
334+
email = "jsmith@localhost"
335+
336+
[proton]
337+
up = 2
338+
down = 1
339+
340+
[divisors]
341+
1 = 1
342+
2 = 2
343+
4 = 3
344+
5 = 2
345+
"#,
346+
FileFormat::Toml,
347+
))
153348
.add_source(config::Environment::with_prefix("config").separator("_"))
154349
.build()
155350
.unwrap();
@@ -172,7 +367,12 @@ fn test_override_uppercase_value_for_enums() {
172367
std::env::set_var("APPS_BAR", "I HAVE BEEN OVERRIDDEN_WITH_UPPER_CASE");
173368

174369
let cfg = Config::builder()
175-
.add_source(File::new("tests/Settings-enum-test.toml", FileFormat::Toml))
370+
.add_source(File::from_str(
371+
r#"
372+
bar = "bar is a lowercase param"
373+
"#,
374+
FileFormat::Toml,
375+
))
176376
.add_source(config::Environment::with_prefix("APPS").separator("_"))
177377
.build()
178378
.unwrap();
@@ -195,7 +395,12 @@ fn test_override_lowercase_value_for_enums() {
195395
std::env::set_var("test_bar", "I have been overridden_with_lower_case");
196396

197397
let cfg = Config::builder()
198-
.add_source(File::new("tests/Settings-enum-test.toml", FileFormat::Toml))
398+
.add_source(File::from_str(
399+
r#"
400+
bar = "bar is a lowercase param"
401+
"#,
402+
FileFormat::Toml,
403+
))
199404
.add_source(config::Environment::with_prefix("test").separator("_"))
200405
.build()
201406
.unwrap();
@@ -214,7 +419,7 @@ fn toml() {
214419
.add_source(File::from_str(
215420
r#"
216421
toml_datetime = 2017-05-11T14:55:15Z
217-
"#,
422+
"#,
218423
FileFormat::Toml,
219424
))
220425
.build()

0 commit comments

Comments
 (0)