1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//! Test utilities for AGPM
//!
//! This module provides utilities for writing tests, including helpers for
//! managing test environments, temporary directories, and test isolation.
//!
//! # Test Isolation
//!
//! The utilities in this module help ensure tests don't interfere with each other:
//! - Temporary directory management
//! - Environment variable isolation
//! - Test fixtures for manifests, lockfiles, and markdown files
//! - Complete test environments with mock git repositories
//!
//! # Example
//!
//! ```rust,no_run
//! #[cfg(test)]
//! mod tests {
//!
//! #[test]
//! fn test_with_environment() {
//! let env = TestEnvironment::with_basic_manifest().unwrap();
//!
//! // Use the test environment
//! assert!(env.file_exists("agpm.toml"));
//! }
//! }
//! ```
pub use ;
pub use TestEnvironment;
pub use ;
pub use TestGit;
use Once;
use Level;
use EnvFilter;
/// Global flag to ensure logging is only initialized once in tests
static INIT_LOGGING: Once = new;
/// Initialize logging for tests.
///
/// This function initializes the tracing subscriber for tests, but only once
/// regardless of how many times it's called. It respects the `RUST_LOG` environment
/// variable if set, or uses the provided log level.
///
/// # Arguments
///
/// * `level` - Optional log level to use. If None, uses `RUST_LOG` environment variable
///
/// # Example
///
/// ```rust,no_run
/// use tracing::Level;
///
/// fn my_test() {
/// // Use environment variable
/// agpm_cli::test_utils::init_test_logging(None);
///
/// // Or set level programmatically
/// agpm_cli::test_utils::init_test_logging(Some(Level::DEBUG));
///
/// // Your test code here - logging will work
/// }
/// ```
///
/// To enable logging in tests via environment variable:
/// ```bash
/// RUST_LOG=debug cargo test
/// ```
/// Compute the SHA-256 hash of variant_inputs JSON value for tests.
///
/// This helper function computes the correct `variant_inputs_hash` value
/// that should be used when creating `LockedResource` instances in tests.
/// It delegates to the centralized hash computation function.
///
/// # Arguments
///
/// * `variant_inputs` - The variant_inputs JSON value (typically empty object for tests)
///
/// # Returns
///
/// A string in the format "sha256:hexdigest"
///
/// # Example
///
/// ```rust,no_run
/// use agpm_cli::test_utils::compute_variant_inputs_hash;
/// use serde_json::json;
///
/// let hash = compute_variant_inputs_hash(&json!({}));
/// assert_eq!(hash, "sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a");
/// ```