torrust_tracker_deployer_lib/testing/fixtures.rs
1//! Test fixtures for persistence and serialization testing
2//!
3//! This module provides reusable test entities and builders for testing
4//! JSON serialization, deserialization, and file persistence operations.
5
6use serde::{Deserialize, Serialize};
7
8/// Test entity for JSON serialization tests
9///
10/// This is a simple entity used across multiple tests to verify
11/// serialization, deserialization, and persistence operations.
12///
13/// # Examples
14///
15/// ```rust
16/// use torrust_tracker_deployer_lib::testing::fixtures::TestEntity;
17///
18/// // Create with default values
19/// let entity = TestEntity::default();
20/// assert_eq!(entity.id, "test-id");
21/// assert_eq!(entity.value, 42);
22///
23/// // Create with custom values
24/// let entity = TestEntity::new("custom-id", 100);
25/// assert_eq!(entity.id, "custom-id");
26/// assert_eq!(entity.value, 100);
27/// ```
28#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
29pub struct TestEntity {
30 pub id: String,
31 pub value: i32,
32}
33
34impl Default for TestEntity {
35 /// Create a test entity with default values
36 ///
37 /// Default values:
38 /// - id: "test-id"
39 /// - value: 42
40 fn default() -> Self {
41 Self {
42 id: "test-id".to_string(),
43 value: 42,
44 }
45 }
46}
47
48impl TestEntity {
49 /// Create a test entity with custom values
50 ///
51 /// # Arguments
52 ///
53 /// * `id` - The entity ID (can be any type that converts to String)
54 /// * `value` - The entity value
55 ///
56 /// # Examples
57 ///
58 /// ```rust
59 /// use torrust_tracker_deployer_lib::testing::fixtures::TestEntity;
60 ///
61 /// let entity = TestEntity::new("my-id", 100);
62 /// assert_eq!(entity.id, "my-id");
63 /// assert_eq!(entity.value, 100);
64 /// ```
65 #[must_use]
66 pub fn new(id: impl Into<String>, value: i32) -> Self {
67 Self {
68 id: id.into(),
69 value,
70 }
71 }
72}