Skip to content

Commit a58a9cf

Browse files
committed
Fix pre-commit hooks
Signed-off-by: Javier G. Sogo <[email protected]>
1 parent 0e23faa commit a58a9cf

5 files changed

+34
-45
lines changed

.github/dependabot.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ updates:
44
directory: "/"
55
# Check for updates every Monday
66
schedule:
7-
interval: "weekly"
7+
interval: "weekly"

src/client/app_configuration_http.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use crate::client::feature_snapshot::FeatureSnapshot;
1818
pub use crate::client::property_proxy::PropertyProxy;
1919
use crate::client::property_snapshot::PropertySnapshot;
2020
use crate::errors::{ConfigurationAccessError, Error, Result};
21-
use crate::TokenProvider;
22-
use crate::{ServerClientImpl, ServiceAddress};
21+
use crate::network::{ServiceAddress, TokenProvider};
22+
use crate::ServerClientImpl;
2323
use std::net::TcpStream;
2424
use std::sync::{Arc, Mutex};
2525
use std::thread;

src/client/app_configuration_ibm_cloud.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use crate::client::feature_snapshot::FeatureSnapshot;
1717
pub use crate::client::property_proxy::PropertyProxy;
1818
use crate::client::property_snapshot::PropertySnapshot;
1919
use crate::errors::Result;
20+
use crate::network::ServiceAddress;
2021
use crate::IBMCloudTokenProvider;
21-
use crate::ServiceAddress;
2222

2323
use super::AppConfigurationClientHttp;
2424
use super::{AppConfigurationClient, ConfigurationId};

src/network/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ mod http_client;
1616
mod token_provider;
1717

1818
pub(crate) use http_client::ServerClientImpl;
19-
pub use http_client::{ServiceAddress, ServiceAddressProtocol};
19+
pub use http_client::ServiceAddress;
2020
pub(crate) use token_provider::IBMCloudTokenProvider;
2121
pub use token_provider::TokenProvider;

tests/test_initial_configuration_from_server.rs

+29-40
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ use std::{
44
thread::{sleep, spawn},
55
time::Duration,
66
};
7-
use tungstenite::{
8-
accept_hdr, connect,
9-
handshake::server::{Request, Response},
10-
};
117

128
use appconfiguration::{
139
AppConfigurationClient, AppConfigurationClientHttp, ConfigurationId, ServiceAddress,
@@ -20,23 +16,18 @@ use std::{fs, path::PathBuf};
2016
use tungstenite::WebSocket;
2117

2218
fn handle_config_request_trivial_config(server: &TcpListener) {
23-
let json_payload = r#"
24-
{
25-
"environments":
26-
[
27-
{
28-
"name": "Dev",
29-
"environment_id": "dev",
30-
"features": [],
31-
"properties": []
32-
}
19+
let json_payload = serde_json::json!({
20+
"environments": [
21+
{
22+
"name": "Dev",
23+
"environment_id": "dev",
24+
"features": [],
25+
"properties": []
26+
}
3327
],
34-
"segments": []
35-
}
36-
"#
37-
.to_string();
38-
39-
handle_config_request(server, json_payload);
28+
"segments": []
29+
});
30+
handle_config_request(server, json_payload.to_string());
4031
}
4132

4233
fn handle_config_request_enterprise_example(server: &TcpListener) {
@@ -67,34 +58,35 @@ fn handle_config_request(server: &TcpListener, json_payload: String) {
6758
}
6859

6960
fn handle_websocket(server: &TcpListener) -> WebSocket<TcpStream> {
70-
let (mut stream, _) = server.accept().unwrap();
61+
let (stream, _) = server.accept().unwrap();
7162
let mut websocket = tungstenite::accept(stream).unwrap();
72-
websocket.send(tungstenite::Message::text("test message".to_string())).unwrap();
73-
websocket.send(tungstenite::Message::text("test messag".to_string())).unwrap();
63+
websocket
64+
.send(tungstenite::Message::text("test message".to_string()))
65+
.unwrap();
66+
websocket
67+
.send(tungstenite::Message::text("test messag".to_string()))
68+
.unwrap();
7469
websocket
7570
}
7671

7772
struct ServerHandle {
78-
terminator: std::sync::mpsc::Sender<()>,
73+
_terminator: std::sync::mpsc::Sender<()>,
7974
config_updated: std::sync::mpsc::Receiver<()>,
80-
port: u16
75+
port: u16,
8176
}
8277
fn server_thread() -> ServerHandle {
8378
let (terminator, receiver) = channel();
8479
let (config_updated_tx, config_updated_rx) = channel();
8580

86-
let server = TcpListener::bind(("127.0.0.1", 0))
87-
.expect("Failed to bind");
81+
let server = TcpListener::bind(("127.0.0.1", 0)).expect("Failed to bind");
8882
let port = server.local_addr().unwrap().port();
8983
spawn(move || {
90-
9184
handle_config_request_enterprise_example(&server);
9285

9386
// notify client that config changed
9487
let _websocket = handle_websocket(&server);
9588

96-
// client will request changed config
97-
// asynchronously
89+
// client will request changed config asynchronously
9890
handle_config_request_trivial_config(&server);
9991

10092
// we now allow the test to continue
@@ -103,9 +95,9 @@ fn server_thread() -> ServerHandle {
10395
let _ = receiver.recv();
10496
});
10597
ServerHandle {
106-
terminator,
98+
_terminator: terminator,
10799
config_updated: config_updated_rx,
108-
port
100+
port,
109101
}
110102
}
111103

@@ -141,22 +133,19 @@ fn main() {
141133
features.sort();
142134
assert_eq!(features, vec!["f1", "f2", "f3", "f4", "f5", "f6"]);
143135

136+
// TODO: Once we can subscribe to config updates via client APIs, we don't need to wait for signal, neither the loop below
144137
server.config_updated.recv().unwrap();
145138

146139
let start = std::time::Instant::now();
147-
148-
loop{
140+
loop {
149141
// We need the loop for now to wait until client updates the config.
150-
// TODO: Once we can subscribe to config updates via client APIs, we do not need to loop here anymore.
151142
let features = client.get_feature_ids().unwrap();
152-
if features.is_empty()
153-
{
143+
if features.is_empty() {
154144
// This is what we expect after the config update :)
155145
break;
156146
}
157-
if start.elapsed().as_millis() > 1000
158-
{
159-
assert!(false, "Did not receive updated configuration in time")
147+
if start.elapsed().as_millis() > 1000 {
148+
panic!("Did not receive updated configuration in time")
160149
}
161150
sleep(Duration::from_millis(10));
162151
}

0 commit comments

Comments
 (0)