100-exercises-to-learn-rust/exercises/07_threads/11_locks/tests/check.rs

32 lines
925 B
Rust
Raw Permalink Normal View History

2024-05-13 04:21:03 +08:00
use locks::data::{Status, TicketDraft};
use locks::launch;
use ticket_fields::test_helpers::{ticket_description, ticket_title};
#[test]
fn works() {
let client = launch(5);
let draft = TicketDraft {
title: ticket_title(),
description: ticket_description(),
};
let ticket_id = client.insert(draft.clone()).unwrap();
let ticket = client.get(ticket_id).unwrap().unwrap();
{
2024-05-14 03:00:43 +08:00
let mut ticket = ticket.lock().unwrap();
2024-05-13 04:21:03 +08:00
assert_eq!(ticket_id, ticket.id);
assert_eq!(ticket.status, Status::ToDo);
assert_eq!(ticket.title, draft.title);
assert_eq!(ticket.description, draft.description);
2024-05-14 03:00:43 +08:00
ticket.status = Status::InProgress;
2024-05-13 04:21:03 +08:00
}
let ticket = client.get(ticket_id).unwrap().unwrap();
{
let ticket = ticket.lock().unwrap();
assert_eq!(ticket_id, ticket.id);
assert_eq!(ticket.status, Status::InProgress);
}
}