Skip to content

Commit 4fde828

Browse files
committed
Add failing IPC test
This commit adds a test for a failing IPC. Signed-off-by: Ionut Mihalcea <[email protected]>
1 parent 017da40 commit 4fde828

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/core/testing/core_tests.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Copyright 2020 Contributors to the Parsec project.
22
// SPDX-License-Identifier: Apache-2.0
3-
use super::{TestCoreClient, DEFAULT_APP_NAME};
3+
use super::{FailingMockIpc, TestCoreClient, DEFAULT_APP_NAME};
44
use crate::error::{ClientErrorKind, Error};
5-
use mockstream::MockStream;
5+
use mockstream::{FailingMockStream, MockStream};
66
use parsec_interface::operations;
77
use parsec_interface::operations::list_providers::ProviderInfo;
88
use parsec_interface::operations::psa_algorithm::*;
@@ -15,6 +15,7 @@ use parsec_interface::requests::ResponseStatus;
1515
use parsec_interface::requests::{request::RequestHeader, Request};
1616
use parsec_interface::requests::{AuthType, BodyType, Opcode, ProviderID};
1717
use std::collections::HashSet;
18+
use std::io::ErrorKind;
1819

1920
const PROTOBUF_CONVERTER: ProtobufConverter = ProtobufConverter {};
2021
const REQ_HEADER: RequestHeader = RequestHeader {
@@ -411,3 +412,19 @@ fn auth_value_test() {
411412
String::from(DEFAULT_APP_NAME)
412413
);
413414
}
415+
416+
#[test]
417+
fn failing_ipc_test() {
418+
let mut client: TestCoreClient = Default::default();
419+
client.set_ipc_client(Box::from(FailingMockIpc(FailingMockStream::new(
420+
ErrorKind::ConnectionRefused,
421+
"connection was refused, so rude",
422+
1,
423+
))));
424+
425+
let err = client.ping().expect_err("Expected to fail");
426+
assert_eq!(
427+
err,
428+
Error::Client(ClientErrorKind::Interface(ResponseStatus::ConnectionError))
429+
);
430+
}

src/core/testing/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use super::ipc_client::{Connect, ReadWrite};
55
use super::CoreClient;
66
use crate::auth::AuthenticationData;
77
use crate::error::Result;
8-
use mockstream::SyncMockStream;
8+
use mockstream::{FailingMockStream, SyncMockStream};
99
use std::ops::{Deref, DerefMut};
1010

1111
mod core_tests;
@@ -20,6 +20,14 @@ impl Connect for MockIpc {
2020
}
2121
}
2222

23+
struct FailingMockIpc(FailingMockStream);
24+
25+
impl Connect for FailingMockIpc {
26+
fn connect(&self) -> Result<Box<dyn ReadWrite>> {
27+
Ok(Box::from(self.0.clone()))
28+
}
29+
}
30+
2331
struct TestCoreClient {
2432
core_client: CoreClient,
2533
mock_stream: SyncMockStream,

0 commit comments

Comments
 (0)