Skip to content

Commit 9aa6273

Browse files
ekumpyannham
authored andcommitted
add response and fips tests
1 parent a4563d5 commit 9aa6273

3 files changed

Lines changed: 66 additions & 1 deletion

File tree

libdd-http-client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fastrand = "2"
2626
tokio = { version = "1.23", features = ["rt", "time"] }
2727
reqwest = { version = "0.13", default-features = false, optional = true }
2828
rustls = { version = "0.23", default-features = false, optional = true }
29-
libdd-common = { version = "1.1.0", path = "../libdd-common", default-features = false, optional = true }
29+
libdd-common = { version = "2.0.0", path = "../libdd-common", default-features = false, optional = true }
3030
hyper = { workspace = true, optional = true }
3131
hyper-util = { workspace = true, optional = true }
3232
http-body-util = { version = "0.1", optional = true }

libdd-http-client/src/response.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,44 @@ pub struct HttpResponse {
1515
/// Response body bytes.
1616
pub body: bytes::Bytes,
1717
}
18+
19+
#[cfg(test)]
20+
mod tests {
21+
use super::*;
22+
23+
#[test]
24+
fn fields_accessible() {
25+
let resp = HttpResponse {
26+
status_code: 200,
27+
headers: vec![("content-type".to_owned(), "application/json".to_owned())],
28+
body: bytes::Bytes::from_static(b"{\"ok\":true}"),
29+
};
30+
assert_eq!(resp.status_code, 200);
31+
assert_eq!(resp.headers.len(), 1);
32+
assert_eq!(resp.headers[0].0, "content-type");
33+
assert_eq!(resp.headers[0].1, "application/json");
34+
assert_eq!(resp.body.as_ref(), b"{\"ok\":true}");
35+
}
36+
37+
#[test]
38+
fn empty_response() {
39+
let resp = HttpResponse {
40+
status_code: 204,
41+
headers: vec![],
42+
body: bytes::Bytes::new(),
43+
};
44+
assert_eq!(resp.status_code, 204);
45+
assert!(resp.headers.is_empty());
46+
assert!(resp.body.is_empty());
47+
}
48+
49+
#[test]
50+
fn debug_includes_status() {
51+
let resp = HttpResponse {
52+
status_code: 404,
53+
headers: vec![],
54+
body: bytes::Bytes::new(),
55+
};
56+
assert!(format!("{resp:?}").contains("404"));
57+
}
58+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2026-Present Datadog, Inc. https://www.datadoghq.com/
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
#![cfg(feature = "fips")]
5+
6+
use libdd_http_client::init_fips_crypto;
7+
8+
/// Verifies that init_fips_crypto() installs the aws-lc-rs provider and that a
9+
/// second call returns an error. This confirms the `fips` feature wires up
10+
/// aws-lc-rs rather than ring.
11+
#[test]
12+
fn fips_crypto_provider() {
13+
let first = init_fips_crypto();
14+
let second = init_fips_crypto();
15+
16+
assert!(first.is_ok(), "init_fips_crypto() failed: {first:?}");
17+
assert!(second.is_err(), "expected Err on second call, got Ok");
18+
19+
let err_msg = second.unwrap_err().to_string();
20+
assert!(
21+
err_msg.contains("already installed"),
22+
"unexpected error message: {err_msg}"
23+
);
24+
}

0 commit comments

Comments
 (0)