Skip to content

Commit 0f92881

Browse files
committed
factor out env logger init for tests
Signed-off-by: clux <[email protected]>
1 parent a7a010b commit 0f92881

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/analyzer.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,20 @@ mod test {
434434
use crate::analyze;
435435
use k8s_openapi::apiextensions_apiserver::pkg::apis::apiextensions::v1::JSONSchemaProps;
436436
use serde_yaml;
437+
use std::sync::Once;
438+
439+
static START: Once = Once::new();
440+
fn init() {
441+
START.call_once(|| {
442+
env_logger::init();
443+
});
444+
}
445+
// To debug individual tests:
446+
// RUST_LOG=debug cargo test --lib -- --nocapture testname
437447

438448
#[test]
439449
fn map_of_struct() {
450+
init();
440451
// validationsInfo from agent test
441452
let schema_str = r#"
442453
description: AgentStatus defines the observed state of Agent
@@ -464,7 +475,6 @@ mod test {
464475
type: object
465476
"#;
466477
let schema: JSONSchemaProps = serde_yaml::from_str(schema_str).unwrap();
467-
//env_logger::init();
468478
//println!("schema: {}", serde_json::to_string_pretty(&schema).unwrap());
469479

470480
let mut structs = vec![];
@@ -491,6 +501,7 @@ mod test {
491501

492502
#[test]
493503
fn empty_preserve_unknown_fields() {
504+
init();
494505
let schema_str = r#"
495506
description: |-
496507
Identifies servers in the same namespace for which this authorization applies.
@@ -531,6 +542,7 @@ type: object
531542

532543
#[test]
533544
fn int_or_string() {
545+
init();
534546
let schema_str = r#"
535547
properties:
536548
port:
@@ -556,6 +568,7 @@ type: object
556568

557569
#[test]
558570
fn enum_string() {
571+
init();
559572
let schema_str = r#"
560573
properties:
561574
operator:
@@ -571,7 +584,6 @@ type: object
571584
"#;
572585

573586
let schema: JSONSchemaProps = serde_yaml::from_str(schema_str).unwrap();
574-
//env_logger::init();
575587
let mut structs = vec![];
576588
analyze(schema, "", "MatchExpressions", 0, &mut structs).unwrap();
577589
println!("got {:?}", structs);
@@ -599,6 +611,7 @@ type: object
599611

600612
#[test]
601613
fn enum_string_within_container() {
614+
init();
602615
let schema_str = r#"
603616
description: Endpoint
604617
properties:
@@ -607,8 +620,6 @@ type: object
607620
properties:
608621
action:
609622
default: replace
610-
description: Action to perform based on regex matching.
611-
Default is 'replace'
612623
enum:
613624
- replace
614625
- keep
@@ -627,7 +638,6 @@ type: object
627638
"#;
628639

629640
let schema: JSONSchemaProps = serde_yaml::from_str(schema_str).unwrap();
630-
//env_logger::init();
631641
let mut structs = vec![];
632642
analyze(schema, "", "Endpoint", 0, &mut structs).unwrap();
633643
println!("got {:?}", structs);
@@ -664,6 +674,7 @@ type: object
664674
#[test]
665675
#[ignore] // oneof support not done
666676
fn enum_oneof() {
677+
init();
667678
let schema_str = r#"
668679
description: "Auto-generated derived type for ServerSpec via `CustomResource`"
669680
properties:
@@ -712,7 +723,6 @@ type: object
712723
type: object"#;
713724

714725
let schema: JSONSchemaProps = serde_yaml::from_str(schema_str).unwrap();
715-
//env_logger::init();
716726
let mut structs = vec![];
717727
analyze(schema, "", "ServerSpec", 0, &mut structs).unwrap();
718728
println!("got {:?}", structs);
@@ -764,6 +774,7 @@ type: object
764774

765775
#[test]
766776
fn service_monitor_params() {
777+
init();
767778
let schema_str = r#"
768779
properties:
769780
endpoints:
@@ -785,7 +796,6 @@ type: object
785796
type: object
786797
"#;
787798
let schema: JSONSchemaProps = serde_yaml::from_str(schema_str).unwrap();
788-
//env_logger::init();
789799
let mut structs = vec![];
790800
analyze(schema, "Endpoints", "ServiceMonitor", 0, &mut structs).unwrap();
791801
println!("got {:?}", structs);
@@ -811,6 +821,7 @@ type: object
811821

812822
#[test]
813823
fn integer_handling_in_maps() {
824+
init();
814825
// via https://istio.io/latest/docs/reference/config/networking/destination-rule/
815826
// distribute:
816827
// - from: us-west/zone1/*

0 commit comments

Comments
 (0)