registry_testkit/config.rs
1//! Configuration types for the registry server.
2
3use std::path::PathBuf;
4
5/// Storage backend for registry data.
6#[derive(Debug, Clone)]
7pub enum StorageBackend {
8 /// In-memory storage (data lost when server stops).
9 Memory,
10 /// Temporary directory storage (cleaned up automatically).
11 TempDir,
12 /// Persistent directory storage at a specific path.
13 Directory(PathBuf),
14}
15
16/// Configuration for the registry server.
17#[derive(Debug, Clone)]
18pub struct RegistryConfig {
19 /// Storage backend to use.
20 pub storage: StorageBackend,
21 /// Port to bind to (None for random port).
22 pub port: Option<u16>,
23 /// Host address to bind to.
24 pub host: String,
25}
26
27impl RegistryConfig {
28 /// Creates a new configuration with the specified storage backend.
29 pub fn new(storage: StorageBackend) -> Self {
30 Self {
31 storage,
32 port: None,
33 host: "127.0.0.1".to_string(),
34 }
35 }
36
37 /// Creates a configuration with in-memory storage.
38 pub fn memory() -> Self {
39 Self::new(StorageBackend::Memory)
40 }
41
42 /// Creates a configuration with temporary directory storage.
43 pub fn temp_dir() -> Self {
44 Self::new(StorageBackend::TempDir)
45 }
46
47 /// Creates a configuration with directory storage at the specified path.
48 pub fn directory(path: PathBuf) -> Self {
49 Self::new(StorageBackend::Directory(path))
50 }
51
52 /// Sets a specific port for the server to bind to.
53 pub fn with_port(mut self, port: u16) -> Self {
54 self.port = Some(port);
55 self
56 }
57
58 /// Sets the host address for the server to bind to.
59 pub fn with_host(mut self, host: impl Into<String>) -> Self {
60 self.host = host.into();
61 self
62 }
63}
64
65impl Default for RegistryConfig {
66 fn default() -> Self {
67 Self::memory()
68 }
69}