Skip to content

Commit 85b5abb

Browse files
committed
test: add elixir tests
1 parent cb01acf commit 85b5abb

44 files changed

Lines changed: 5281 additions & 119 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.PHONY: help install dev build clean demo test lint check-versions \
22
core control web mcp \
3-
docker-build docker-test docker-test-quick docker-clean \
3+
docker-build docker-test docker-test-quick docker-clean docker-purge \
44
docker-core docker-web docker-query docker-mcp docker-control \
55
quality-gates quality-rust quality-go quality-elixir
66

@@ -206,14 +206,25 @@ docker-build:
206206
./scripts/container-test.sh --build-only
207207

208208
docker-clean:
209-
@echo "🧹 Cleaning test containers..."
209+
@echo "🧹 Cleaning test containers and images..."
210+
-docker rm -f query-service-test-db 2>/dev/null
210211
-docker rmi chronos-core:test 2>/dev/null
211212
-docker rmi chronos-web:test 2>/dev/null
212213
-docker rmi chronos-query-service:test 2>/dev/null
213214
-docker rmi chronos-mcp-server:test 2>/dev/null
214215
-docker rmi chronos-control-plane:test 2>/dev/null
215216
@echo "✅ Test images cleaned"
216217

218+
docker-purge:
219+
@echo "🧹 Purging ALL docker resources (containers, images, volumes, networks)..."
220+
-docker stop $$(docker ps -aq) 2>/dev/null
221+
-docker rm $$(docker ps -aq) 2>/dev/null
222+
-docker rmi $$(docker images -q) 2>/dev/null
223+
-docker volume prune -f 2>/dev/null
224+
-docker network prune -f 2>/dev/null
225+
-docker system prune -af 2>/dev/null
226+
@echo "✅ All docker resources purged"
227+
217228
# Individual container builds
218229
docker-core:
219230
@echo "🐳 Building core container..."

apps/core/src/application/services/audit_logger.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl AuditLogBuilder {
167167
/// - Error handling (audit failures are logged but don't break requests)
168168
///
169169
/// # Example
170-
/// ```rust
170+
/// ```ignore
171171
/// let audit_logger = AuditLogger::new(audit_repo);
172172
///
173173
/// audit_logger.log(

apps/core/src/error.rs

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,136 @@ impl IntoResponse for AllSourceError {
117117
(status, axum::Json(body)).into_response()
118118
}
119119
}
120+
121+
#[cfg(test)]
122+
mod tests {
123+
use super::*;
124+
125+
#[test]
126+
fn test_error_display() {
127+
let err = AllSourceError::EventNotFound("event-123".to_string());
128+
assert_eq!(err.to_string(), "Event not found: event-123");
129+
130+
let err = AllSourceError::EntityNotFound("entity-456".to_string());
131+
assert_eq!(err.to_string(), "Entity not found: entity-456");
132+
133+
let err = AllSourceError::TenantAlreadyExists("tenant-1".to_string());
134+
assert_eq!(err.to_string(), "Tenant already exists: tenant-1");
135+
136+
let err = AllSourceError::TenantNotFound("tenant-2".to_string());
137+
assert_eq!(err.to_string(), "Tenant not found: tenant-2");
138+
}
139+
140+
#[test]
141+
fn test_error_variants() {
142+
let errors: Vec<AllSourceError> = vec![
143+
AllSourceError::InvalidEvent("bad event".to_string()),
144+
AllSourceError::InvalidQuery("bad query".to_string()),
145+
AllSourceError::InvalidInput("bad input".to_string()),
146+
AllSourceError::StorageError("storage failed".to_string()),
147+
AllSourceError::ArrowError("arrow failed".to_string()),
148+
AllSourceError::IndexError("index failed".to_string()),
149+
AllSourceError::ValidationError("validation failed".to_string()),
150+
AllSourceError::ConcurrencyError("conflict".to_string()),
151+
AllSourceError::QueueFull("queue full".to_string()),
152+
AllSourceError::InternalError("internal error".to_string()),
153+
];
154+
155+
for err in errors {
156+
let msg = err.to_string();
157+
assert!(!msg.is_empty());
158+
}
159+
}
160+
161+
#[test]
162+
fn test_into_response_not_found() {
163+
let err = AllSourceError::EventNotFound("event-123".to_string());
164+
let response = err.into_response();
165+
assert_eq!(response.status(), StatusCode::NOT_FOUND);
166+
167+
let err = AllSourceError::EntityNotFound("entity-456".to_string());
168+
let response = err.into_response();
169+
assert_eq!(response.status(), StatusCode::NOT_FOUND);
170+
171+
let err = AllSourceError::TenantNotFound("tenant-1".to_string());
172+
let response = err.into_response();
173+
assert_eq!(response.status(), StatusCode::NOT_FOUND);
174+
}
175+
176+
#[test]
177+
fn test_into_response_bad_request() {
178+
let err = AllSourceError::InvalidEvent("bad event".to_string());
179+
let response = err.into_response();
180+
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
181+
182+
let err = AllSourceError::InvalidQuery("bad query".to_string());
183+
let response = err.into_response();
184+
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
185+
186+
let err = AllSourceError::InvalidInput("bad input".to_string());
187+
let response = err.into_response();
188+
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
189+
190+
let err = AllSourceError::ValidationError("validation failed".to_string());
191+
let response = err.into_response();
192+
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
193+
}
194+
195+
#[test]
196+
fn test_into_response_conflict() {
197+
let err = AllSourceError::TenantAlreadyExists("tenant-1".to_string());
198+
let response = err.into_response();
199+
assert_eq!(response.status(), StatusCode::CONFLICT);
200+
201+
let err = AllSourceError::ConcurrencyError("conflict".to_string());
202+
let response = err.into_response();
203+
assert_eq!(response.status(), StatusCode::CONFLICT);
204+
}
205+
206+
#[test]
207+
fn test_into_response_service_unavailable() {
208+
let err = AllSourceError::QueueFull("queue is full".to_string());
209+
let response = err.into_response();
210+
assert_eq!(response.status(), StatusCode::SERVICE_UNAVAILABLE);
211+
}
212+
213+
#[test]
214+
fn test_into_response_internal_error() {
215+
let err = AllSourceError::StorageError("storage error".to_string());
216+
let response = err.into_response();
217+
assert_eq!(response.status(), StatusCode::INTERNAL_SERVER_ERROR);
218+
219+
let err = AllSourceError::ArrowError("arrow error".to_string());
220+
let response = err.into_response();
221+
assert_eq!(response.status(), StatusCode::INTERNAL_SERVER_ERROR);
222+
223+
let err = AllSourceError::IndexError("index error".to_string());
224+
let response = err.into_response();
225+
assert_eq!(response.status(), StatusCode::INTERNAL_SERVER_ERROR);
226+
227+
let err = AllSourceError::InternalError("internal error".to_string());
228+
let response = err.into_response();
229+
assert_eq!(response.status(), StatusCode::INTERNAL_SERVER_ERROR);
230+
}
231+
232+
#[test]
233+
fn test_from_arrow_error() {
234+
let arrow_err = arrow::error::ArrowError::InvalidArgumentError("test".to_string());
235+
let err: AllSourceError = arrow_err.into();
236+
assert!(matches!(err, AllSourceError::ArrowError(_)));
237+
}
238+
239+
#[test]
240+
fn test_from_parquet_error() {
241+
let parquet_err = parquet::errors::ParquetError::General("test".to_string());
242+
let err: AllSourceError = parquet_err.into();
243+
assert!(matches!(err, AllSourceError::StorageError(_)));
244+
}
245+
246+
#[test]
247+
fn test_error_debug() {
248+
let err = AllSourceError::EventNotFound("test".to_string());
249+
let debug_str = format!("{:?}", err);
250+
assert!(debug_str.contains("EventNotFound"));
251+
}
252+
}

0 commit comments

Comments
 (0)