Skip to content

Commit 8da6dde

Browse files
authored
Merge pull request #95 from hug-dev/use-parsec-mock
Use Parsec Mock for testing
2 parents 4579ec1 + cfc13ca commit 8da6dde

File tree

5 files changed

+56
-29
lines changed

5 files changed

+56
-29
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ jobs:
77
name: Build and check formatting
88
runs-on: ubuntu-latest
99
steps:
10-
- uses: actions/checkout@v1
11-
- name: Execute all tests
12-
run: ./tests/ci.sh
10+
- uses: actions/checkout@v2
11+
- name: Set up Python 3.7
12+
uses: actions/setup-python@v1
13+
with:
14+
python-version: 3.7
15+
- name: Download Parsec Mock, install dependencies and execute all tests
16+
run: |
17+
curl -s -N -L https://github.com/parallaxsecond/parsec-mock/archive/refs/tags/0.1.1.tar.gz | tar xz
18+
cd parsec-mock-0.1.1/
19+
python -m pip install --upgrade pip
20+
pip install -r requirements.txt
21+
cd ..
22+
./tests/ci.sh

src/core/basic_client.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,16 @@ impl BasicClient {
116116
///#
117117
///# fn main() -> Result<(), Box<dyn Error>> {
118118
///use parsec_client::BasicClient;
119-
///let client = BasicClient::new_naked();
119+
///let client = BasicClient::new_naked()?;
120120
///let (major, minor) = client.ping()?;
121121
///# Ok(())}
122122
/// ```
123-
pub fn new_naked() -> Self {
124-
BasicClient {
125-
op_client: Default::default(),
123+
pub fn new_naked() -> Result<Self> {
124+
Ok(BasicClient {
125+
op_client: OperationClient::new()?,
126126
auth_data: Authentication::None,
127127
implicit_provider: ProviderId::Core,
128-
}
128+
})
129129
}
130130

131131
/// Query the service for the list of authenticators provided and use the first one as default
@@ -150,7 +150,7 @@ impl BasicClient {
150150
///# fn main() -> Result<(), Box<dyn Error>> {
151151
///use parsec_client::BasicClient;
152152
///use parsec_client::core::interface::requests::ProviderId;
153-
///let mut client = BasicClient::new_naked();
153+
///let mut client = BasicClient::new_naked()?;
154154
///// Set the default authenticator but choose a specific provider.
155155
///client.set_implicit_provider(ProviderId::Pkcs11);
156156
///client.set_default_auth(Some("main_client".to_string()))?;
@@ -209,7 +209,7 @@ impl BasicClient {
209209
///# fn main() -> Result<(), Box<dyn Error>> {
210210
///use parsec_client::BasicClient;
211211
///use parsec_client::auth::Authentication;
212-
///let mut client = BasicClient::new_naked();
212+
///let mut client = BasicClient::new_naked()?;
213213
///client.set_auth_data(Authentication::UnixPeerCredentials);
214214
///assert_eq!(Authentication::UnixPeerCredentials, client.auth_data());
215215
///# Ok(())}
@@ -233,7 +233,7 @@ impl BasicClient {
233233
///# fn main() -> Result<(), Box<dyn Error>> {
234234
///use parsec_client::BasicClient;
235235
///use parsec_client::auth::Authentication;
236-
///let mut client = BasicClient::new_naked();
236+
///let mut client = BasicClient::new_naked()?;
237237
///// Use the default provider but use a specific authentication.
238238
///client.set_default_provider()?;
239239
///client.set_auth_data(Authentication::UnixPeerCredentials);
@@ -268,7 +268,7 @@ impl BasicClient {
268268
///# fn main() -> Result<(), Box<dyn Error>> {
269269
///use parsec_client::BasicClient;
270270
///use parsec_client::core::interface::requests::ProviderId;
271-
///let mut client = BasicClient::new_naked();
271+
///let mut client = BasicClient::new_naked()?;
272272
///client.set_implicit_provider(ProviderId::Pkcs11);
273273
///assert_eq!(ProviderId::Pkcs11, client.implicit_provider());
274274
///# Ok(())}
@@ -327,7 +327,7 @@ impl BasicClient {
327327
///# fn main() -> Result<(), Box<dyn Error>> {
328328
///use parsec_client::BasicClient;
329329
///
330-
///let mut client: BasicClient = BasicClient::new_naked();
330+
///let mut client: BasicClient = BasicClient::new_naked()?;
331331
///let providers = client.list_providers()?;
332332
///// Set the second most prioritary provider
333333
///client.set_implicit_provider(providers[1].id);
@@ -1291,3 +1291,13 @@ impl BasicClient {
12911291
}
12921292
}
12931293
}
1294+
1295+
impl Default for BasicClient {
1296+
fn default() -> Self {
1297+
BasicClient {
1298+
op_client: Default::default(),
1299+
auth_data: Authentication::None,
1300+
implicit_provider: ProviderId::Core,
1301+
}
1302+
}
1303+
}

src/core/testing/core_tests.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,6 @@ fn get_operation_from_req_bytes(bytes: Vec<u8>) -> NativeOperation {
5656
.unwrap()
5757
}
5858

59-
#[test]
60-
fn ping_test() {
61-
let mut client: TestBasicClient = Default::default();
62-
client.set_mock_read(&get_response_bytes_from_result(NativeResult::Ping(
63-
operations::ping::Result {
64-
wire_protocol_version_maj: 1,
65-
wire_protocol_version_min: 0,
66-
},
67-
)));
68-
// Check request:
69-
// Ping request is empty so no checking to be done
70-
71-
// Check response:
72-
assert_eq!(client.ping().expect("Ping failed"), (1, 0));
73-
}
74-
7559
#[test]
7660
fn list_provider_test() {
7761
let mut client: TestBasicClient = Default::default();

tests/ci.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ if cargo clippy -h; then
2727
cargo clippy --all-targets -- -D clippy::all -D clippy::cargo
2828
fi
2929

30+
######################
31+
# Start Mock Service #
32+
######################
33+
CURRENT_PATH=$(pwd)
34+
cd parsec-mock-0.1.1
35+
python parsec_mock/parsec_mock.py --parsec-socket $CURRENT_PATH/parsec_mock.sock &
36+
while [[ ! -S $CURRENT_PATH/parsec_mock.sock ]]; do
37+
sleep 5
38+
done
39+
cd ..
40+
export PARSEC_SERVICE_ENDPOINT="unix://$CURRENT_PATH/parsec_mock.sock"
41+
3042
#############
3143
# Run tests #
3244
#############

tests/mock_service.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2021 Contributors to the Parsec project.
2+
// SPDX-License-Identifier: Apache-2.0
3+
use parsec_client::BasicClient;
4+
5+
#[test]
6+
fn ping_noauth() {
7+
let client = BasicClient::new_naked().unwrap();
8+
9+
// ping_noauth request
10+
assert_eq!(client.ping().expect("Ping failed"), (1, 0));
11+
}

0 commit comments

Comments
 (0)