Skip to content

Commit 6d4fe85

Browse files
pfmooneyPatrick Mooney
authored andcommitted
Standardize on mod test
Keep a consistent style of `mod test`, rather than a mix of that and `mod tests`. Enforce this new rule with a rudimentary check, added as `xtask style`.
1 parent 0d8efa1 commit 6d4fe85

File tree

21 files changed

+168
-70
lines changed

21 files changed

+168
-70
lines changed

.github/workflows/rust.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ jobs:
2121
run: cargo fmt -- --version
2222
- name: Check style
2323
run: cargo fmt -- --check
24+
- name: Check misc. style
25+
run: cargo xtask style
2426
check-clippy:
2527
runs-on: ubuntu-latest
2628
steps:

bin/propolis-cli/src/main.rs

Lines changed: 67 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -360,57 +360,6 @@ async fn stdin_to_websockets_task(
360360
}
361361
}
362362

363-
#[tokio::test]
364-
async fn test_stdin_to_websockets_task() {
365-
use tokio::sync::mpsc::error::TryRecvError;
366-
367-
let (stdintx, stdinrx) = tokio::sync::mpsc::channel(16);
368-
let (wstx, mut wsrx) = tokio::sync::mpsc::channel(16);
369-
370-
tokio::spawn(async move { stdin_to_websockets_task(stdinrx, wstx).await });
371-
372-
// send characters, receive characters
373-
stdintx
374-
.send("test post please ignore".chars().map(|c| c as u8).collect())
375-
.await
376-
.unwrap();
377-
let actual = wsrx.recv().await.unwrap();
378-
assert_eq!(String::from_utf8(actual).unwrap(), "test post please ignore");
379-
380-
// don't send ctrl-a
381-
stdintx.send("\x01".chars().map(|c| c as u8).collect()).await.unwrap();
382-
assert_eq!(wsrx.try_recv(), Err(TryRecvError::Empty));
383-
384-
// the "t" here is sent "raw" because of last ctrl-a but that doesn't change anything
385-
stdintx.send("test".chars().map(|c| c as u8).collect()).await.unwrap();
386-
let actual = wsrx.recv().await.unwrap();
387-
assert_eq!(String::from_utf8(actual).unwrap(), "test");
388-
389-
// ctrl-a ctrl-c = only ctrl-c sent
390-
stdintx.send("\x01\x03".chars().map(|c| c as u8).collect()).await.unwrap();
391-
let actual = wsrx.recv().await.unwrap();
392-
assert_eq!(String::from_utf8(actual).unwrap(), "\x03");
393-
394-
// same as above, across two messages
395-
stdintx.send("\x01".chars().map(|c| c as u8).collect()).await.unwrap();
396-
stdintx.send("\x03".chars().map(|c| c as u8).collect()).await.unwrap();
397-
assert_eq!(wsrx.try_recv(), Err(TryRecvError::Empty));
398-
let actual = wsrx.recv().await.unwrap();
399-
assert_eq!(String::from_utf8(actual).unwrap(), "\x03");
400-
401-
// ctrl-a ctrl-a = only ctrl-a sent
402-
stdintx.send("\x01\x01".chars().map(|c| c as u8).collect()).await.unwrap();
403-
let actual = wsrx.recv().await.unwrap();
404-
assert_eq!(String::from_utf8(actual).unwrap(), "\x01");
405-
406-
// ctrl-c on its own means exit
407-
stdintx.send("\x03".chars().map(|c| c as u8).collect()).await.unwrap();
408-
assert_eq!(wsrx.try_recv(), Err(TryRecvError::Empty));
409-
410-
// channel is closed
411-
assert!(wsrx.recv().await.is_none());
412-
}
413-
414363
async fn serial(
415364
addr: SocketAddr,
416365
byte_offset: Option<i64>,
@@ -747,3 +696,70 @@ impl Drop for RawTermiosGuard {
747696
}
748697
}
749698
}
699+
700+
#[cfg(test)]
701+
mod test {
702+
use super::stdin_to_websockets_task;
703+
704+
#[tokio::test]
705+
async fn test_stdin_to_websockets_task() {
706+
use tokio::sync::mpsc::error::TryRecvError;
707+
708+
let (stdintx, stdinrx) = tokio::sync::mpsc::channel(16);
709+
let (wstx, mut wsrx) = tokio::sync::mpsc::channel(16);
710+
711+
tokio::spawn(
712+
async move { stdin_to_websockets_task(stdinrx, wstx).await },
713+
);
714+
715+
// send characters, receive characters
716+
stdintx
717+
.send("test post please ignore".chars().map(|c| c as u8).collect())
718+
.await
719+
.unwrap();
720+
let actual = wsrx.recv().await.unwrap();
721+
assert_eq!(
722+
String::from_utf8(actual).unwrap(),
723+
"test post please ignore"
724+
);
725+
726+
// don't send ctrl-a
727+
stdintx.send("\x01".chars().map(|c| c as u8).collect()).await.unwrap();
728+
assert_eq!(wsrx.try_recv(), Err(TryRecvError::Empty));
729+
730+
// the "t" here is sent "raw" because of last ctrl-a but that doesn't change anything
731+
stdintx.send("test".chars().map(|c| c as u8).collect()).await.unwrap();
732+
let actual = wsrx.recv().await.unwrap();
733+
assert_eq!(String::from_utf8(actual).unwrap(), "test");
734+
735+
// ctrl-a ctrl-c = only ctrl-c sent
736+
stdintx
737+
.send("\x01\x03".chars().map(|c| c as u8).collect())
738+
.await
739+
.unwrap();
740+
let actual = wsrx.recv().await.unwrap();
741+
assert_eq!(String::from_utf8(actual).unwrap(), "\x03");
742+
743+
// same as above, across two messages
744+
stdintx.send("\x01".chars().map(|c| c as u8).collect()).await.unwrap();
745+
stdintx.send("\x03".chars().map(|c| c as u8).collect()).await.unwrap();
746+
assert_eq!(wsrx.try_recv(), Err(TryRecvError::Empty));
747+
let actual = wsrx.recv().await.unwrap();
748+
assert_eq!(String::from_utf8(actual).unwrap(), "\x03");
749+
750+
// ctrl-a ctrl-a = only ctrl-a sent
751+
stdintx
752+
.send("\x01\x01".chars().map(|c| c as u8).collect())
753+
.await
754+
.unwrap();
755+
let actual = wsrx.recv().await.unwrap();
756+
assert_eq!(String::from_utf8(actual).unwrap(), "\x01");
757+
758+
// ctrl-c on its own means exit
759+
stdintx.send("\x03".chars().map(|c| c as u8).collect()).await.unwrap();
760+
assert_eq!(wsrx.try_recv(), Err(TryRecvError::Empty));
761+
762+
// channel is closed
763+
assert!(wsrx.recv().await.is_none());
764+
}
765+
}

bin/propolis-server/src/lib/migrate/protocol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ pub(super) fn select_protocol_from_offer(
256256
}
257257

258258
#[cfg(test)]
259-
mod tests {
259+
mod test {
260260
use super::*;
261261

262262
// N.B. The test protocol lists are sorted by version to meet the

bin/propolis-server/src/lib/serial/history_buffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ impl HistoryBuffer {
218218
}
219219

220220
#[cfg(test)]
221-
mod tests {
221+
mod test {
222222
use super::*;
223223
use SerialHistoryOffset::*;
224224

bin/propolis-server/src/lib/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ fn not_created_error() -> HttpError {
11471147
}
11481148

11491149
#[cfg(test)]
1150-
mod tests {
1150+
mod test {
11511151
#[test]
11521152
fn test_propolis_server_openapi() {
11531153
let mut buf: Vec<u8> = vec![];

bin/propolis-server/src/lib/stats/virtual_machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ fn produce_vcpu_usage<'a>(
395395
}
396396

397397
#[cfg(test)]
398-
mod tests {
398+
mod test {
399399
use super::kstat_instance_from_instance_id;
400400
use super::kstat_microstate_to_state_name;
401401
use super::produce_vcpu_usage;

bin/propolis-server/src/lib/vm/request_queue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ impl ExternalRequestQueue {
444444
}
445445

446446
#[cfg(test)]
447-
mod tests {
447+
mod test {
448448
use super::*;
449449

450450
use uuid::Uuid;

bin/propolis-server/src/lib/vm/state_driver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ where
567567
}
568568

569569
#[cfg(test)]
570-
mod tests {
570+
mod test {
571571
use anyhow::bail;
572572
use mockall::Sequence;
573573

crates/propolis-server-config/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ pub fn parse<P: AsRef<Path>>(path: P) -> Result<Config, ParseError> {
143143
}
144144

145145
#[cfg(test)]
146-
mod tests {
146+
mod test {
147147
use super::*;
148148

149149
#[test]

lib/propolis-client/src/support.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ fn _assert_impls() {
449449
}
450450

451451
#[cfg(test)]
452-
mod tests {
452+
mod test {
453453
use super::InstanceSerialConsoleControlMessage;
454454
use super::InstanceSerialConsoleHelper;
455455
use super::Role;

0 commit comments

Comments
 (0)