|
10 | 10 | /// test guards in `common/mod.rs`. |
11 | 11 | /// |
12 | 12 | /// Fixture categories: |
13 | | -/// - `stellarnode_*` — `StellarNodeSpec` and related CRD types |
14 | 13 | /// - `backup_*` — `BackupVerificationConfig` and `BackupSource` |
15 | 14 | /// - `rotation_*` — `SecretRotationConfig` |
16 | | -/// - `manifest_*` — raw YAML strings for `kubectl apply` tests |
17 | 15 | /// - `k8s_*` — Kubernetes API objects (Pods, Containers, VolumeMounts) |
18 | | -/// - `deterministic` — SeededRng, fixed timestamps, deterministic name helpers |
19 | | -use k8s_openapi::api::core::v1::{Container, VolumeMount}; |
20 | | -use rand::SeedableRng; |
21 | | - |
22 | | -// --------------------------------------------------------------------------- |
23 | | -// Deterministic test utilities (consolidated from tests/fixtures/mod.rs) |
24 | | -// --------------------------------------------------------------------------- |
25 | | - |
26 | | -/// Deterministic RNG for tests. Use `SeededRng::seeded(seed)` for reproducible |
27 | | -/// results. |
28 | | -pub struct SeededRng(rand::rngs::SmallRng); |
29 | | - |
30 | | -impl SeededRng { |
31 | | - pub fn seeded(seed: u64) -> Self { |
32 | | - Self(rand::rngs::SmallRng::seed_from_u64(seed)) |
33 | | - } |
34 | | - |
35 | | - pub fn inner(&mut self) -> &mut rand::rngs::SmallRng { |
36 | | - &mut self.0 |
37 | | - } |
38 | | -} |
39 | | - |
40 | | -/// Fixed "now" timestamp for deterministic time-sensitive tests. |
41 | | -/// |
42 | | -/// Returns 2026-01-15T12:00:00Z. Use this instead of `Utc::now()` in tests |
43 | | -/// to avoid flaky time-dependent assertions. |
44 | | -pub fn fixed_now() -> chrono::DateTime<chrono::Utc> { |
45 | | - chrono::DateTime::parse_from_rfc3339("2026-01-15T12:00:00Z") |
46 | | - .unwrap() |
47 | | - .with_timezone(&chrono::Utc) |
48 | | -} |
49 | | - |
50 | | -/// Generate a deterministic test namespace name from a seed. |
51 | | -pub fn test_namespace(seed: &str) -> String { |
52 | | - format!("test-{}", seed) |
53 | | -} |
54 | | - |
55 | | -/// Generate a deterministic test StellarNode name from a seed. |
56 | | -pub fn test_node_name(seed: &str) -> String { |
57 | | - format!("node-{}", seed) |
58 | | -} |
59 | | - |
60 | | -// --------------------------------------------------------------------------- |
61 | | -// StellarNode fixtures |
62 | | -// --------------------------------------------------------------------------- |
63 | | - |
64 | | -/// Unique namespace name for an integration test. |
65 | | -/// |
66 | | -/// Includes a short random suffix so parallel tests do not collide even when |
67 | | -/// the same test binary runs more than once against the same cluster. |
68 | 16 | /// |
69 | | -/// # Example |
70 | | -/// ``` |
71 | | -/// use tests::common::fixtures::unique_namespace; |
72 | | -/// let ns = unique_namespace("backup-test"); |
73 | | -/// // "stellar-it-backup-test-a1b2c3d4" |
74 | | -/// ``` |
75 | | -pub fn unique_namespace(label: &str) -> String { |
76 | | - // Use thread ID + timestamp for a lightweight unique suffix that works |
77 | | - // without pulling in uuid or rand at the test level. |
78 | | - let ts = std::time::SystemTime::now() |
79 | | - .duration_since(std::time::UNIX_EPOCH) |
80 | | - .map(|d| d.subsec_nanos()) |
81 | | - .unwrap_or(0); |
82 | | - format!("stellar-it-{label}-{ts:08x}") |
83 | | -} |
84 | | - |
85 | | -/// Minimal valid `StellarNode` YAML for a Testnet Validator. |
86 | | -/// |
87 | | -/// Uses `retentionPolicy: Delete` so PVCs are cleaned up automatically and |
88 | | -/// tests do not leave orphaned storage in the cluster. |
89 | | -pub fn testnet_validator_manifest(name: &str, namespace: &str) -> String { |
90 | | - format!( |
91 | | - r#"apiVersion: stellar.org/v1alpha1 |
92 | | -kind: StellarNode |
93 | | -metadata: |
94 | | - name: {name} |
95 | | - namespace: {namespace} |
96 | | - labels: |
97 | | - app.kubernetes.io/managed-by: stellar-k8s-integration-test |
98 | | -spec: |
99 | | - nodeType: Validator |
100 | | - network: Testnet |
101 | | - version: "v21.0.0" |
102 | | - storage: |
103 | | - storageClass: standard |
104 | | - size: 10Gi |
105 | | - retentionPolicy: Delete |
106 | | -"# |
107 | | - ) |
108 | | -} |
109 | | - |
110 | | -/// Minimal valid `StellarNode` YAML for a Testnet Horizon node. |
111 | | -pub fn testnet_horizon_manifest(name: &str, namespace: &str) -> String { |
112 | | - format!( |
113 | | - r#"apiVersion: stellar.org/v1alpha1 |
114 | | -kind: StellarNode |
115 | | -metadata: |
116 | | - name: {name} |
117 | | - namespace: {namespace} |
118 | | - labels: |
119 | | - app.kubernetes.io/managed-by: stellar-k8s-integration-test |
120 | | -spec: |
121 | | - nodeType: Horizon |
122 | | - network: Testnet |
123 | | - version: "v2.28.0" |
124 | | - storage: |
125 | | - storageClass: standard |
126 | | - size: 50Gi |
127 | | - retentionPolicy: Delete |
128 | | -"# |
129 | | - ) |
130 | | -} |
131 | | - |
132 | | -/// Minimal valid `StellarNode` YAML for a Testnet Soroban RPC node. |
133 | | -pub fn testnet_soroban_manifest(name: &str, namespace: &str) -> String { |
134 | | - format!( |
135 | | - r#"apiVersion: stellar.org/v1alpha1 |
136 | | -kind: StellarNode |
137 | | -metadata: |
138 | | - name: {name} |
139 | | - namespace: {namespace} |
140 | | - labels: |
141 | | - app.kubernetes.io/managed-by: stellar-k8s-integration-test |
142 | | -spec: |
143 | | - nodeType: SorobanRpc |
144 | | - network: Testnet |
145 | | - version: "v0.0.5" |
146 | | - storage: |
147 | | - storageClass: standard |
148 | | - size: 20Gi |
149 | | - retentionPolicy: Delete |
150 | | -"# |
151 | | - ) |
152 | | -} |
| 17 | +/// Obsolete StellarNode YAML / deterministic helpers for deprecated |
| 18 | +/// reconciliation integration paths were removed in issue #1218 (unused after |
| 19 | +/// reconciler tests moved to typed `create_test_*` constructors). |
| 20 | +use k8s_openapi::api::core::v1::{Container, VolumeMount}; |
153 | 21 |
|
154 | 22 | // --------------------------------------------------------------------------- |
155 | 23 | // Kubernetes API object fixtures |
@@ -270,44 +138,3 @@ pub fn secret_rotation_full() -> stellar_k8s::backup::SecretRotationConfig { |
270 | 138 | notification_webhook: Some("https://webhook.example.com".to_string()), |
271 | 139 | } |
272 | 140 | } |
273 | | - |
274 | | -#[cfg(test)] |
275 | | -mod tests { |
276 | | - use super::*; |
277 | | - |
278 | | - #[test] |
279 | | - fn seeded_rng_deterministic() { |
280 | | - let mut a = SeededRng::seeded(42); |
281 | | - let mut b = SeededRng::seeded(42); |
282 | | - let va: u64 = rand::Rng::gen(a.inner()); |
283 | | - let vb: u64 = rand::Rng::gen(b.inner()); |
284 | | - assert_eq!(va, vb); |
285 | | - } |
286 | | - |
287 | | - #[test] |
288 | | - fn seeded_rng_different_seeds() { |
289 | | - let mut a = SeededRng::seeded(1); |
290 | | - let mut b = SeededRng::seeded(2); |
291 | | - let va: u64 = rand::Rng::gen(a.inner()); |
292 | | - let vb: u64 = rand::Rng::gen(b.inner()); |
293 | | - assert_ne!(va, vb); |
294 | | - } |
295 | | - |
296 | | - #[test] |
297 | | - fn fixed_now_is_deterministic() { |
298 | | - let t1 = fixed_now(); |
299 | | - let t2 = fixed_now(); |
300 | | - assert_eq!(t1, t2); |
301 | | - assert_eq!(t1.to_rfc3339(), "2026-01-15T12:00:00+00:00"); |
302 | | - } |
303 | | - |
304 | | - #[test] |
305 | | - fn test_namespace_format() { |
306 | | - assert_eq!(test_namespace("mytest"), "test-mytest"); |
307 | | - } |
308 | | - |
309 | | - #[test] |
310 | | - fn test_node_name_format() { |
311 | | - assert_eq!(test_node_name("alpha"), "node-alpha"); |
312 | | - } |
313 | | -} |
0 commit comments