Compare commits
No commits in common. "1920e8ae7997deae949f9e068e687314b4459ebb" and "b2896b206c321344fc53c36a4cdac84e87ddc20e" have entirely different histories.
1920e8ae79
...
b2896b206c
@ -2,10 +2,10 @@
|
||||
name = "sal"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
authors = ["PlanetFirst <info@incubaid.com>"]
|
||||
authors = ["Your Name <your.email@example.com>"]
|
||||
description = "System Abstraction Layer - A library for easy interaction with operating system features"
|
||||
repository = "https://git.ourworld.tf/herocode/sal"
|
||||
license = "Apache-2.0"
|
||||
repository = "https://github.com/yourusername/sal"
|
||||
license = "MIT OR Apache-2.0"
|
||||
keywords = ["system", "os", "abstraction", "platform", "filesystem"]
|
||||
categories = ["os", "filesystem", "api-bindings"]
|
||||
readme = "README.md"
|
||||
|
7
src/env/mod.rs
vendored
7
src/env/mod.rs
vendored
@ -1,6 +1 @@
|
||||
mod redisclient;
|
||||
|
||||
pub use redisclient::*;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
pub mod redisclient;
|
126
src/env/tests.rs
vendored
126
src/env/tests.rs
vendored
@ -1,126 +0,0 @@
|
||||
use super::*;
|
||||
use std::env;
|
||||
use redis::RedisResult;
|
||||
|
||||
#[cfg(test)]
|
||||
mod redis_client_tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_env_vars() {
|
||||
// Save original REDISDB value to restore later
|
||||
let original_redisdb = env::var("REDISDB").ok();
|
||||
|
||||
// Set test environment variables
|
||||
env::set_var("REDISDB", "5");
|
||||
|
||||
// Test with invalid value
|
||||
env::set_var("REDISDB", "invalid");
|
||||
|
||||
// Test with unset value
|
||||
env::remove_var("REDISDB");
|
||||
|
||||
// Restore original REDISDB value
|
||||
if let Some(redisdb) = original_redisdb {
|
||||
env::set_var("REDISDB", redisdb);
|
||||
} else {
|
||||
env::remove_var("REDISDB");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_redis_client_creation_mock() {
|
||||
// This is a simplified test that doesn't require an actual Redis server
|
||||
// It just verifies that the function handles environment variables correctly
|
||||
|
||||
// Save original HOME value to restore later
|
||||
let original_home = env::var("HOME").ok();
|
||||
|
||||
// Set HOME to a test value
|
||||
env::set_var("HOME", "/tmp");
|
||||
|
||||
// The actual client creation would be tested in integration tests
|
||||
// with a real Redis server or a mock
|
||||
|
||||
// Restore original HOME value
|
||||
if let Some(home) = original_home {
|
||||
env::set_var("HOME", home);
|
||||
} else {
|
||||
env::remove_var("HOME");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_reset_mock() {
|
||||
// This is a simplified test that doesn't require an actual Redis server
|
||||
// In a real test, we would need to mock the Redis client
|
||||
|
||||
// Just verify that the reset function doesn't panic
|
||||
// This is a minimal test - in a real scenario, we would use mocking
|
||||
// to verify that the client is properly reset
|
||||
if let Err(_) = reset() {
|
||||
// If Redis is not available, this is expected to fail
|
||||
// So we don't assert anything here
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Integration tests that require a real Redis server
|
||||
// These tests will be skipped if Redis is not available
|
||||
#[cfg(test)]
|
||||
mod redis_integration_tests {
|
||||
use super::*;
|
||||
|
||||
// Helper function to check if Redis is available
|
||||
fn is_redis_available() -> bool {
|
||||
match get_redis_client() {
|
||||
Ok(_) => true,
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_redis_client_integration() {
|
||||
if !is_redis_available() {
|
||||
println!("Skipping Redis integration tests - Redis server not available");
|
||||
return;
|
||||
}
|
||||
|
||||
println!("Running Redis integration tests...");
|
||||
|
||||
// Test basic operations
|
||||
test_basic_redis_operations();
|
||||
}
|
||||
|
||||
fn test_basic_redis_operations() {
|
||||
if !is_redis_available() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Test setting and getting values
|
||||
let client_result = get_redis_client();
|
||||
|
||||
if client_result.is_err() {
|
||||
// Skip the test if we can't connect to Redis
|
||||
return;
|
||||
}
|
||||
|
||||
// Create SET command
|
||||
let mut set_cmd = redis::cmd("SET");
|
||||
set_cmd.arg("test_key").arg("test_value");
|
||||
|
||||
// Execute SET command
|
||||
let set_result: RedisResult<()> = execute(&mut set_cmd);
|
||||
assert!(set_result.is_ok());
|
||||
|
||||
// Create GET command
|
||||
let mut get_cmd = redis::cmd("GET");
|
||||
get_cmd.arg("test_key");
|
||||
|
||||
// Execute GET command and check the result
|
||||
if let Ok(value) = execute::<String>(&mut get_cmd) {
|
||||
assert_eq!(value, "test_value");
|
||||
}
|
||||
let _: RedisResult<()> = execute(&mut redis::cmd("DEL").arg("test_key"));
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ use std::collections::HashMap;
|
||||
use redis::Cmd;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::env;
|
||||
use crate::env::redisclient;
|
||||
use crate::git::git::parse_git_url;
|
||||
|
||||
// Define a custom error type for GitExecutor operations
|
||||
@ -127,7 +127,7 @@ impl GitExecutor {
|
||||
cmd.arg("GET").arg("herocontext:git");
|
||||
|
||||
// Execute the command
|
||||
let result: redis::RedisResult<String> = env::execute(&mut cmd);
|
||||
let result: redis::RedisResult<String> = redisclient::execute(&mut cmd);
|
||||
|
||||
match result {
|
||||
Ok(json_str) => {
|
||||
|
@ -1,4 +1,5 @@
|
||||
use std::process::Command;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
use std::error::Error;
|
||||
use std::io;
|
||||
|
@ -2,6 +2,7 @@ use std::io::{BufRead, BufReader, Write};
|
||||
use std::fs::{self, File};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Child, Command, Output, Stdio};
|
||||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
use std::error::Error;
|
||||
use std::io;
|
||||
|
Loading…
Reference in New Issue
Block a user