nightlight: trim test-only helpers

This commit is contained in:
centra 2026-03-31 22:00:56 +09:00
parent bd09761def
commit ec55fdea05
Signed by: centra
GPG key ID: 0C09689D20B25ACA
4 changed files with 13 additions and 2 deletions

View file

@ -130,6 +130,7 @@ impl Config {
} }
/// Save configuration to a YAML file /// Save configuration to a YAML file
#[cfg(test)]
pub fn save(&self, path: &str) -> Result<()> { pub fn save(&self, path: &str) -> Result<()> {
let content = serde_yaml::to_string(self)?; let content = serde_yaml::to_string(self)?;
fs::write(path, content)?; fs::write(path, content)?;

View file

@ -138,6 +138,7 @@ impl IngestionService {
} }
/// Get current storage statistics /// Get current storage statistics
#[cfg(test)]
pub async fn storage_stats(&self) -> Result<(usize, usize), Error> { pub async fn storage_stats(&self) -> Result<(usize, usize), Error> {
let stats = self let stats = self
.storage .storage

View file

@ -24,7 +24,9 @@ use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::Arc; use std::sync::Arc;
use std::time::Instant; use std::time::Instant;
use tokio::sync::RwLock; use tokio::sync::RwLock;
use tracing::{debug, error, info}; use tracing::{debug, error};
#[cfg(test)]
use tracing::info;
const QUERY_DURATION_HISTORY_LIMIT: usize = 512; const QUERY_DURATION_HISTORY_LIMIT: usize = 512;
@ -83,6 +85,7 @@ impl QueryService {
} }
/// Create QueryService and load persistent state from disk if it exists /// Create QueryService and load persistent state from disk if it exists
#[cfg(test)]
pub fn new_with_persistence(data_path: &std::path::Path) -> Result<Self> { pub fn new_with_persistence(data_path: &std::path::Path) -> Result<Self> {
let storage = QueryableStorage::load_from_file(data_path)?; let storage = QueryableStorage::load_from_file(data_path)?;
info!("Loaded {} series from persistent storage", storage.series.len()); info!("Loaded {} series from persistent storage", storage.series.len());
@ -94,6 +97,7 @@ impl QueryService {
} }
/// Save current storage state to disk /// Save current storage state to disk
#[cfg(test)]
pub async fn save_to_disk(&self, data_path: &std::path::Path) -> Result<()> { pub async fn save_to_disk(&self, data_path: &std::path::Path) -> Result<()> {
let storage = self.storage.read().await; let storage = self.storage.read().await;
storage.save_to_file(data_path)?; storage.save_to_file(data_path)?;
@ -799,6 +803,7 @@ impl QueryableStorage {
} }
/// Get label values for a specific label name /// Get label values for a specific label name
#[cfg(test)]
pub fn label_values(&self, label_name: &str) -> Vec<String> { pub fn label_values(&self, label_name: &str) -> Vec<String> {
let mut values: Vec<String> = self let mut values: Vec<String> = self
.label_index .label_index

View file

@ -3,7 +3,9 @@
use anyhow::Result; use anyhow::Result;
use chrono::Utc; use chrono::Utc;
use nightlight_types::{SeriesId, TimeSeries}; #[cfg(test)]
use nightlight_types::SeriesId;
use nightlight_types::TimeSeries;
use std::{ use std::{
fs::{File, OpenOptions}, fs::{File, OpenOptions},
io::{Read, Write}, io::{Read, Write},
@ -79,6 +81,7 @@ impl Storage {
Ok(()) Ok(())
} }
#[cfg(test)]
pub async fn query_series( pub async fn query_series(
&self, &self,
series_id: SeriesId, series_id: SeriesId,
@ -92,6 +95,7 @@ impl Storage {
.map(|series| series.filter_by_time(start, end))) .map(|series| series.filter_by_time(start, end)))
} }
#[cfg(test)]
pub async fn find_series(&self, matchers: Vec<String>) -> Result<Vec<SeriesId>> { pub async fn find_series(&self, matchers: Vec<String>) -> Result<Vec<SeriesId>> {
let parsed: Vec<(String, String)> = matchers let parsed: Vec<(String, String)> = matchers
.iter() .iter()