Skip to content

Commit

Permalink
Merge pull request #1040 from coreos/dependabot/cargo/mockito-1.0.1
Browse files Browse the repository at this point in the history
build(deps): bump mockito from 0.31.1 to 1.0.1
  • Loading branch information
cgwalters authored Aug 24, 2023
2 parents e984f9c + 7226b7a commit 77a0918
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 29 deletions.
20 changes: 17 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ keywords = ["cincinnati", "coreos", "fedora", "rpm-ostree"]
authors = ["Luca Bruno <[email protected]>"]
repository = "https://github.com/coreos/zincati"
edition = "2021"
rust-version = "1.64.0"
rust-version = "1.65.0"

[dependencies]
actix = "0.13"
Expand Down Expand Up @@ -51,7 +51,7 @@ zbus = "3"

[dev-dependencies]
http = "0.2"
mockito = "0.31"
mockito = "1.1"
proptest = "1.2"
tempfile = ">= 3.7, < 4.0"

Expand Down
10 changes: 6 additions & 4 deletions src/cincinnati/mock_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ use tokio::runtime as rt;

#[test]
fn test_empty_graph() {
let mut server = mockito::Server::new();
let empty_graph = r#"{ "nodes": [], "edges": [] }"#;
let m_graph = mockito::mock("GET", Matcher::Regex(r"^/v1/graph?.+$".to_string()))
.match_header("accept", Matcher::Regex("application/json".to_string()))
.with_body(empty_graph)
let m_graph = server
.mock("GET", Matcher::Regex(r"^/v1/graph?.+$".to_string()))
.with_status(200)
.with_header("accept", "application/json")
.with_body(empty_graph)
.create();

let runtime = rt::Runtime::new().unwrap();
let id = Identity::mock_default();
let client = Cincinnati {
base_url: mockito::server_url(),
base_url: server.url(),
};
let update = runtime.block_on(client.next_update(&id, BTreeSet::new(), false));
m_graph.assert();
Expand Down
33 changes: 17 additions & 16 deletions src/fleet_lock/mock_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use tokio::runtime as rt;

#[test]
fn test_pre_reboot_lock() {
let mut server = mockito::Server::new();
let body = r#"
{
"client_params": {
Expand All @@ -13,17 +14,17 @@ fn test_pre_reboot_lock() {
}
}
"#;
let m_pre_reboot = mockito::mock("POST", Matcher::Exact(format!("/{}", V1_PRE_REBOOT)))

let m_pre_reboot = server
.mock("POST", Matcher::Exact(format!("/{}", V1_PRE_REBOOT)))
.match_header("fleet-lock-protocol", "true")
.match_body(Matcher::PartialJsonString(body.to_string()))
.with_status(200)
.create();

let runtime = rt::Runtime::new().unwrap();
let id = Identity::mock_default();
let client = ClientBuilder::new(mockito::server_url(), &id)
.build()
.unwrap();
let client = ClientBuilder::new(server.url(), &id).build().unwrap();
let res = runtime.block_on(client.pre_reboot());
m_pre_reboot.assert();

Expand All @@ -33,23 +34,23 @@ fn test_pre_reboot_lock() {

#[test]
fn test_pre_reboot_error() {
let mut server = mockito::Server::new();
let body = r#"
{
"kind": "f1",
"value": "pre-reboot failure"
}
"#;
let m_pre_reboot = mockito::mock("POST", Matcher::Exact(format!("/{}", V1_PRE_REBOOT)))
let m_pre_reboot = server
.mock("POST", Matcher::Exact(format!("/{}", V1_PRE_REBOOT)))
.match_header("fleet-lock-protocol", "true")
.with_status(404)
.with_body(body)
.create();

let runtime = rt::Runtime::new().unwrap();
let id = Identity::mock_default();
let client = ClientBuilder::new(mockito::server_url(), &id)
.build()
.unwrap();
let client = ClientBuilder::new(server.url(), &id).build().unwrap();
let res = runtime.block_on(client.pre_reboot());
m_pre_reboot.assert();

Expand All @@ -58,6 +59,7 @@ fn test_pre_reboot_error() {

#[test]
fn test_steady_state_lock() {
let mut server = mockito::Server::new();
let body = r#"
{
"client_params": {
Expand All @@ -66,17 +68,16 @@ fn test_steady_state_lock() {
}
}
"#;
let m_steady_state = mockito::mock("POST", Matcher::Exact(format!("/{}", V1_STEADY_STATE)))
let m_steady_state = server
.mock("POST", Matcher::Exact(format!("/{}", V1_STEADY_STATE)))
.match_header("fleet-lock-protocol", "true")
.match_body(Matcher::PartialJsonString(body.to_string()))
.with_status(200)
.create();

let runtime = rt::Runtime::new().unwrap();
let id = Identity::mock_default();
let client = ClientBuilder::new(mockito::server_url(), &id)
.build()
.unwrap();
let client = ClientBuilder::new(server.url(), &id).build().unwrap();
let res = runtime.block_on(client.steady_state());
m_steady_state.assert();

Expand All @@ -86,23 +87,23 @@ fn test_steady_state_lock() {

#[test]
fn test_steady_state_error() {
let mut server = mockito::Server::new();
let body = r#"
{
"kind": "f1",
"value": "pre-reboot failure"
}
"#;
let m_steady_state = mockito::mock("POST", Matcher::Exact(format!("/{}", V1_STEADY_STATE)))
let m_steady_state = server
.mock("POST", Matcher::Exact(format!("/{}", V1_STEADY_STATE)))
.match_header("fleet-lock-protocol", "true")
.with_status(404)
.with_body(body)
.create();

let runtime = rt::Runtime::new().unwrap();
let id = Identity::mock_default();
let client = ClientBuilder::new(mockito::server_url(), &id)
.build()
.unwrap();
let client = ClientBuilder::new(server.url(), &id).build().unwrap();
let res = runtime.block_on(client.steady_state());
m_steady_state.assert();

Expand Down
12 changes: 8 additions & 4 deletions src/rpm_ostree/mock_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use tokio::runtime as rt;

#[test]
fn test_simple_graph() {
let mut server = mockito::Server::new();
let simple_graph = r#"
{
"nodes": [
Expand Down Expand Up @@ -35,7 +36,8 @@ fn test_simple_graph() {
}
"#;

let m_graph = mockito::mock("GET", Matcher::Regex(r"^/v1/graph?.+$".to_string()))
let m_graph = server
.mock("GET", Matcher::Regex(r"^/v1/graph?.+$".to_string()))
.match_header("accept", Matcher::Regex("application/json".to_string()))
.with_body(simple_graph)
.with_status(200)
Expand All @@ -44,7 +46,7 @@ fn test_simple_graph() {
let runtime = rt::Runtime::new().unwrap();
let id = Identity::mock_default();
let client = Cincinnati {
base_url: mockito::server_url(),
base_url: server.url(),
};
let update = runtime.block_on(client.fetch_update_hint(&id, BTreeSet::new(), false));
m_graph.assert();
Expand All @@ -55,6 +57,7 @@ fn test_simple_graph() {

#[test]
fn test_downgrade() {
let mut server = mockito::Server::new();
let simple_graph = r#"
{
"nodes": [
Expand Down Expand Up @@ -84,7 +87,8 @@ fn test_downgrade() {
}
"#;

let m_graph = mockito::mock("GET", Matcher::Regex(r"^/v1/graph?.+$".to_string()))
let m_graph = server
.mock("GET", Matcher::Regex(r"^/v1/graph?.+$".to_string()))
.match_header("accept", Matcher::Regex("application/json".to_string()))
.with_body(simple_graph)
.with_status(200)
Expand All @@ -94,7 +98,7 @@ fn test_downgrade() {
let runtime = rt::Runtime::new().unwrap();
let id = Identity::mock_default();
let client = Cincinnati {
base_url: mockito::server_url(),
base_url: server.url(),
};

// Downgrades denied.
Expand Down

0 comments on commit 77a0918

Please sign in to comment.