Skip to content

Commit 8a22dd4

Browse files
Clippy fixes in integration test.
1 parent 3a18df4 commit 8a22dd4

File tree

7 files changed

+86
-93
lines changed

7 files changed

+86
-93
lines changed
File renamed without changes.
Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
11
pub mod env;
22

3-
4-
use std::fs;
5-
use serde::{ Deserialize, Serialize };
3+
use serde::{Deserialize, Serialize};
64
use serde_json::{json, Value};
5+
use std::fs;
76

87
#[derive(Deserialize, Debug)]
9-
#[allow(dead_code)]
108
pub struct RustLanguage {
11-
pub name: String,
12-
pub version: String
9+
pub name: String,
10+
#[allow(dead_code)]
11+
pub version: String,
1312
}
1413

1514
#[derive(Deserialize, Debug)]
16-
#[allow(dead_code)]
1715
pub struct AntithesisSdk {
18-
pub language: RustLanguage,
16+
pub language: RustLanguage,
1917
pub protocol_version: String,
20-
pub sdk_version: String
18+
#[allow(dead_code)]
19+
pub sdk_version: String,
2120
}
2221

2322
#[derive(Deserialize, Debug)]
24-
#[allow(dead_code)]
2523
pub struct AntithesisSetup {
2624
pub status: String,
2725
pub details: Value,
2826
}
2927

3028
#[derive(Deserialize, Serialize, Debug)]
31-
#[allow(dead_code)]
3229
pub struct Location {
3330
begin_column: i32,
3431
begin_line: i32,
@@ -39,6 +36,7 @@ pub struct Location {
3936

4037
#[derive(Deserialize, Debug)]
4138
#[allow(dead_code)]
39+
// TODO: Setup integration test for assertions.
4240
pub struct AntithesisAssert {
4341
assert_type: AssertType,
4442
condition: bool,
@@ -55,11 +53,14 @@ pub struct AntithesisAssert {
5553
#[serde(rename_all = "snake_case")]
5654
pub enum SDKInput {
5755
AntithesisSdk(AntithesisSdk),
56+
#[allow(dead_code)]
57+
// TODO: Setup integration test for assertions.
5858
AntithesisAssert(AntithesisAssert),
5959
AntithesisSetup(AntithesisSetup),
60-
61-
#[allow(dead_code)]
62-
SendEvent{event_name: String, details: Value }
60+
SendEvent {
61+
event_name: String,
62+
details: Value,
63+
},
6364
}
6465

6566
#[derive(Deserialize, Debug)]
@@ -73,34 +74,44 @@ enum AssertType {
7374
fn parse_lines(lines: Vec<&str>) -> Result<Vec<SDKInput>, Box<dyn std::error::Error>> {
7475
let mut result = Vec::new();
7576

76-
let default_event = "abc".to_owned();
77+
let default_event = "abc".to_owned();
7778
for line in lines {
78-
if line.len() < 1 { continue; }
79+
if line.is_empty() {
80+
continue;
81+
}
7982
let parsed: SDKInput = match serde_json::from_str(line) {
8083
Ok(x) => x,
8184
Err(_e) => {
8285
// println!("{}", line);
8386
// println!("PARSING: {:?}", e);
84-
let temp: Value = serde_json::from_str(line)?;
87+
let temp: Value = serde_json::from_str(line)?;
8588
// should be Object(Map<String, Value>)
8689
// in this case the Map has just one entry (top-level name used by SendEvent())
8790
match temp {
8891
Value::Object(user_data) => {
89-
// let mut result = None;
90-
let mut res = Some(SDKInput::SendEvent{event_name: default_event.clone(), details: json!({})});
91-
for (event_name, details) in user_data {
92-
res = Some(SDKInput::SendEvent{
92+
// let mut result = None;
93+
let mut res = Some(SDKInput::SendEvent {
94+
event_name: default_event.clone(),
95+
details: json!({}),
96+
});
97+
if let Some((event_name, details)) = user_data.into_iter().next() {
98+
res = Some(SDKInput::SendEvent {
9399
event_name,
94100
details,
95101
});
96-
break;
97-
};
98-
match res {
99-
Some(x) => x,
100-
None => SDKInput::SendEvent{event_name: default_event.clone(), details: json!({})}
101-
}
102+
}
103+
match res {
104+
Some(x) => x,
105+
None => SDKInput::SendEvent {
106+
event_name: default_event.clone(),
107+
details: json!({}),
108+
},
109+
}
110+
}
111+
_ => SDKInput::SendEvent {
112+
event_name: default_event.clone(),
113+
details: json!({}),
102114
},
103-
_ => SDKInput::SendEvent{event_name: default_event.clone(), details: json!({})}
104115
}
105116
}
106117
};
@@ -111,9 +122,9 @@ fn parse_lines(lines: Vec<&str>) -> Result<Vec<SDKInput>, Box<dyn std::error::Er
111122

112123
pub fn read_jsonl_tags(jsonl_file: &str) -> Result<Vec<SDKInput>, Box<dyn std::error::Error>> {
113124
let contents = fs::read_to_string(jsonl_file)?;
114-
// .expect("Should have been able to read the file");
115-
116-
let lines = contents.split("\n");
125+
// .expect("Should have been able to read the file");
126+
127+
let lines = contents.split('\n');
117128
let parsed = parse_lines(lines.collect())?;
118-
Ok(parsed)
129+
Ok(parsed)
119130
}

lib/tests/integration/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
mod common;
2+
mod sdk_info;
3+
mod send_event;
4+
mod setup_complete_with_details;
5+
mod setup_complete_without_details;
Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
#[cfg(test)]
2-
use serde_json::{json};
3-
use antithesis_sdk_rust::{lifecycle};
4-
mod common;
1+
use antithesis_sdk_rust::lifecycle;
2+
use serde_json::json;
53

6-
use common::{AntithesisSdk, SDKInput};
4+
use crate::common::{self, SDKInput};
75

86
const LOCAL_OUTPUT: &str = "ANTITHESIS_SDK_LOCAL_OUTPUT";
97

@@ -15,7 +13,6 @@ const LOCAL_OUTPUT: &str = "ANTITHESIS_SDK_LOCAL_OUTPUT";
1513
// ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1614
#[test]
1715
fn sdk_info() {
18-
1916
let output_file = "/tmp/antithesis-sdk.json";
2017
let prev_v = common::env::set_var(LOCAL_OUTPUT, output_file);
2118
let no_details = json!({});
@@ -27,17 +24,13 @@ fn sdk_info() {
2724
match common::read_jsonl_tags(output_file) {
2825
Ok(x) => {
2926
for obj in x.iter() {
30-
match obj {
31-
SDKInput::AntithesisSdk(AntithesisSdk{language, protocol_version, sdk_version: _}) => {
32-
assert_eq!(protocol_version, "1.0.0");
33-
assert_eq!(language.name, "Rust")
34-
},
35-
_ => ()
27+
if let SDKInput::AntithesisSdk(sdk) = obj {
28+
assert_eq!(sdk.protocol_version, "1.0.0");
29+
assert_eq!(sdk.language.name, "Rust")
3630
}
3731
}
38-
},
39-
Err(e) => println!("{}", e)
32+
}
33+
Err(e) => println!("{}", e),
4034
}
4135
common::env::restore_var(LOCAL_OUTPUT, prev_v);
4236
}
43-
Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
#[cfg(test)]
2-
use serde_json::{json};
3-
use antithesis_sdk_rust::{lifecycle};
4-
mod common;
1+
use antithesis_sdk_rust::lifecycle;
2+
use serde_json::json;
53

6-
use common::{SDKInput};
4+
use crate::common::{self, SDKInput};
75

86
const LOCAL_OUTPUT: &str = "ANTITHESIS_SDK_LOCAL_OUTPUT";
97

@@ -15,7 +13,6 @@ const LOCAL_OUTPUT: &str = "ANTITHESIS_SDK_LOCAL_OUTPUT";
1513
// ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1614
#[test]
1715
fn send_event() {
18-
1916
let output_file = "/tmp/antithesis-send-event.json";
2017
let prev_v = common::env::set_var(LOCAL_OUTPUT, output_file);
2118
let details = json!({
@@ -30,19 +27,18 @@ fn send_event() {
3027
match common::read_jsonl_tags(output_file) {
3128
Ok(x) => {
3229
for obj in x.iter() {
33-
match obj {
34-
SDKInput::SendEvent{event_name, details} => {
35-
assert_eq!(event_name, "logging");
36-
assert_eq!(&details["x"], 100);
37-
assert_eq!(&details["tag"], "last value");
38-
},
39-
_ => ()
30+
if let SDKInput::SendEvent {
31+
event_name,
32+
details,
33+
} = obj
34+
{
35+
assert_eq!(event_name, "logging");
36+
assert_eq!(&details["x"], 100);
37+
assert_eq!(&details["tag"], "last value");
4038
}
4139
}
42-
},
43-
Err(e) => println!("{}", e)
40+
}
41+
Err(e) => println!("{}", e),
4442
}
4543
common::env::restore_var(LOCAL_OUTPUT, prev_v);
4644
}
47-
48-
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
#[cfg(test)]
1+
use antithesis_sdk_rust::lifecycle;
22
use serde_json::{json, Value};
3-
use antithesis_sdk_rust::{lifecycle};
4-
mod common;
53

6-
use common::{AntithesisSetup, SDKInput};
4+
use crate::common::{self, AntithesisSetup, SDKInput};
75

86
const LOCAL_OUTPUT: &str = "ANTITHESIS_SDK_LOCAL_OUTPUT";
97

@@ -15,8 +13,7 @@ const LOCAL_OUTPUT: &str = "ANTITHESIS_SDK_LOCAL_OUTPUT";
1513
// ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1614
#[test]
1715
fn setup_complete_with_details() {
18-
19-
let output_file = "/tmp/antithesis-lifecycle.json";
16+
let output_file = "/tmp/antithesis-lifecycle-with-details.json";
2017
let prev_v = common::env::set_var(LOCAL_OUTPUT, output_file);
2118
let bird_value: Value = json!({
2219
"name": "Tweety Bird",
@@ -31,17 +28,14 @@ fn setup_complete_with_details() {
3128
match common::read_jsonl_tags(output_file) {
3229
Ok(x) => {
3330
for obj in x.iter() {
34-
match obj {
35-
SDKInput::AntithesisSetup(AntithesisSetup{status, details}) => {
36-
assert_eq!(status, "complete");
37-
assert_eq!(details, &bird_value)
38-
},
39-
_ => ()
31+
if let SDKInput::AntithesisSetup(AntithesisSetup { status, details }) = obj {
32+
assert_eq!(status, "complete");
33+
assert_eq!(details, &bird_value)
4034
}
4135
println!("{:?}", obj)
4236
}
43-
},
44-
Err(e) => println!("{}", e)
37+
}
38+
Err(e) => println!("{}", e),
4539
}
4640
common::env::restore_var(LOCAL_OUTPUT, prev_v);
4741
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
#[cfg(test)]
2-
use serde_json::{json};
3-
use antithesis_sdk_rust::{lifecycle};
4-
mod common;
1+
use antithesis_sdk_rust::lifecycle;
2+
use serde_json::json;
53

6-
use common::{AntithesisSetup, SDKInput};
4+
use crate::common::{self, AntithesisSetup, SDKInput};
75

86
const LOCAL_OUTPUT: &str = "ANTITHESIS_SDK_LOCAL_OUTPUT";
97

@@ -15,8 +13,7 @@ const LOCAL_OUTPUT: &str = "ANTITHESIS_SDK_LOCAL_OUTPUT";
1513
// ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1614
#[test]
1715
fn setup_complete_without_details() {
18-
19-
let output_file = "/tmp/antithesis-lifecycle.json";
16+
let output_file = "/tmp/antithesis-lifecycle-withou-details.json";
2017
let prev_v = common::env::set_var(LOCAL_OUTPUT, output_file);
2118
let no_details = json!({});
2219

@@ -26,16 +23,13 @@ fn setup_complete_without_details() {
2623
match common::read_jsonl_tags(output_file) {
2724
Ok(x) => {
2825
for obj in x.iter() {
29-
match obj {
30-
SDKInput::AntithesisSetup(AntithesisSetup{status, details}) => {
31-
assert_eq!(status, "complete");
32-
assert_eq!(details, &no_details)
33-
},
34-
_ => ()
26+
if let SDKInput::AntithesisSetup(AntithesisSetup { status, details }) = obj {
27+
assert_eq!(status, "complete");
28+
assert_eq!(details, &no_details)
3529
}
3630
}
37-
},
38-
Err(e) => println!("{}", e)
31+
}
32+
Err(e) => println!("{}", e),
3933
}
4034
common::env::restore_var(LOCAL_OUTPUT, prev_v);
4135
}

0 commit comments

Comments
 (0)