Skip to content

Commit c74c36c

Browse files
committed
Update tests
1 parent 48bd6a3 commit c74c36c

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

src/interpreters/Http_original.rs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ impl Interpreter for Http_original {
158158
#[cfg(test)]
159159
mod test_http_original {
160160
use super::*;
161-
use neovim_lib::Value;
162161
use serial_test::serial;
163162
use ureq::serde_json;
164163

@@ -173,21 +172,21 @@ mod test_http_original {
173172
let res = interpreter.run();
174173

175174
assert!(res.is_ok(), "Could not run http interpreter");
176-
assert_eq!(res.ok().unwrap(), "200".to_owned());
175+
let data = res.ok().unwrap();
176+
let (body, status) = data.split_once("---").unwrap();
177+
178+
let v: serde_json::Value = serde_json::from_str(&body).unwrap();
179+
println!("{}", serde_json::to_string_pretty(&v).unwrap());
180+
assert_eq!(v["url"], "https://httpbin.org/get".to_owned());
181+
182+
assert!(status.contains("200"));
177183
}
178184

179185
#[test]
180186
#[serial]
181187
fn simple_http_get_long() {
182188
let data = DataHolder {
183189
current_bloc: String::from("GET https://httpbin.org/get"),
184-
interpreter_options: Some(Value::Map(vec![(
185-
"interpreter_options".into(),
186-
Value::Map(vec![(
187-
"Http_original".into(),
188-
Value::Map(vec![("error_truncate".into(), "long".into())]),
189-
)]),
190-
)])),
191190
..Default::default()
192191
};
193192

@@ -199,10 +198,13 @@ mod test_http_original {
199198

200199
assert!(res.is_ok(), "Could not run http interpreter");
201200
let data = res.ok().unwrap();
201+
let (body, status) = data.split_once("---").unwrap();
202202

203-
let v: serde_json::Value = serde_json::from_str(&data).unwrap();
203+
let v: serde_json::Value = serde_json::from_str(&body).unwrap();
204204
println!("{}", serde_json::to_string_pretty(&v).unwrap());
205205
assert_eq!(v["url"], "https://httpbin.org/get".to_owned());
206+
207+
assert!(status.contains("200"));
206208
}
207209

208210
#[test]
@@ -216,21 +218,22 @@ GET https://httpbin.org/get
216218
GET https://httpbin.org/anything
217219
"####,
218220
),
219-
interpreter_options: Some(Value::Map(vec![(
220-
"interpreter_options".into(),
221-
Value::Map(vec![(
222-
"Http_original".into(),
223-
Value::Map(vec![("error_truncate".into(), "short".into())]),
224-
)]),
225-
)])),
226221
..Default::default()
227222
};
228223

229224
let mut interpreter = Http_original::new(data);
230225
let res = interpreter.run();
231226

232227
assert!(res.is_ok(), "Could not run http interpreter");
233-
assert_eq!(res.ok().unwrap(), "200\n---\n200".to_owned());
228+
229+
let data = res.ok().unwrap();
230+
231+
let v: Vec<&str> = data.split("---").collect();
232+
233+
println!("{v:?}");
234+
235+
// Body + Status + newline per request
236+
assert_eq!(v.len(), 6);
234237
}
235238

236239
#[test]
@@ -252,14 +255,17 @@ POST https://httpbin.org/post
252255

253256
assert!(res.is_ok(), "Could not run http interpreter");
254257
let data = res.ok().unwrap();
258+
let (body, status) = data.split_once("---").unwrap();
255259

256-
let v: serde_json::Value = serde_json::from_str(&data).unwrap();
260+
let v: serde_json::Value = serde_json::from_str(&body).unwrap();
257261
// println!("{}", serde_json::to_string_pretty(&v).unwrap());
258262

259263
let j: serde_json::Value = serde_json::from_str(&v["json"].to_string()).unwrap();
260264
// println!("{}", serde_json::to_string_pretty(&foo).unwrap());
261265

262266
assert_eq!(v["url"], "https://httpbin.org/post".to_owned());
263267
assert_eq!(j["foo"], "bar".to_owned());
268+
269+
assert!(status.contains("200"));
264270
}
265271
}

0 commit comments

Comments
 (0)