drasi_bootstrap_platform/lib.rs
1// Copyright 2025 The Drasi Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Platform bootstrap plugin for Drasi
16//!
17//! This plugin provides the Platform bootstrap provider implementation for fetching
18//! initial data from a remote Drasi Query API service.
19//!
20//! # Example
21//!
22//! ```no_run
23//! use drasi_bootstrap_platform::PlatformBootstrapProvider;
24//!
25//! // Using the builder
26//! let provider = PlatformBootstrapProvider::builder()
27//! .with_query_api_url("http://remote-drasi:8080")
28//! .with_timeout_seconds(600)
29//! .build()
30//! .expect("Failed to create provider");
31//!
32//! // Or using configuration
33//! use drasi_lib::bootstrap::PlatformBootstrapConfig;
34//!
35//! let config = PlatformBootstrapConfig {
36//! query_api_url: Some("http://remote-drasi:8080".to_string()),
37//! timeout_seconds: 600,
38//! };
39//! let provider = PlatformBootstrapProvider::new(config)
40//! .expect("Failed to create provider");
41//! ```
42
43pub mod platform;
44
45pub use drasi_lib::bootstrap::PlatformBootstrapConfig;
46pub use platform::{PlatformBootstrapProvider, PlatformBootstrapProviderBuilder};
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn test_platform_bootstrap_builder_requires_url() {
54 // Builder without URL should fail to build
55 let result = PlatformBootstrapProviderBuilder::new().build();
56 assert!(result.is_err());
57 }
58
59 #[test]
60 fn test_platform_bootstrap_builder_with_valid_url() {
61 // Builder with valid URL should succeed
62 let result = PlatformBootstrapProviderBuilder::new()
63 .with_query_api_url("http://remote-drasi:8080") // DevSkim: ignore DS137138
64 .with_timeout_seconds(600)
65 .build();
66 assert!(result.is_ok());
67 }
68
69 #[test]
70 fn test_platform_bootstrap_builder_invalid_url() {
71 // Builder with invalid URL should fail
72 let result = PlatformBootstrapProviderBuilder::new()
73 .with_query_api_url("not-a-valid-url")
74 .build();
75 assert!(result.is_err());
76 }
77
78 #[test]
79 fn test_platform_bootstrap_builder_default() {
80 // Default builder should have no URL set
81 let builder = PlatformBootstrapProviderBuilder::default();
82 // Without URL, build should fail
83 let result = builder.build();
84 assert!(result.is_err());
85 }
86
87 #[test]
88 fn test_platform_bootstrap_from_provider_method() {
89 // Test using PlatformBootstrapProvider::builder()
90 let result = PlatformBootstrapProvider::builder()
91 .with_query_api_url("http://source-api:9000") // DevSkim: ignore DS137138
92 .with_timeout_seconds(900)
93 .build();
94 assert!(result.is_ok());
95 }
96
97 #[test]
98 fn test_platform_bootstrap_new_with_config() {
99 // Test using PlatformBootstrapProvider::new(config)
100 let config = PlatformBootstrapConfig {
101 query_api_url: Some("http://localhost:8080".to_string()), // DevSkim: ignore DS137138
102 timeout_seconds: 300,
103 };
104 let result = PlatformBootstrapProvider::new(config);
105 assert!(result.is_ok());
106 }
107
108 #[test]
109 fn test_platform_bootstrap_new_without_url() {
110 // Config without URL should fail
111 let config = PlatformBootstrapConfig {
112 query_api_url: None,
113 timeout_seconds: 300,
114 };
115 let result = PlatformBootstrapProvider::new(config);
116 assert!(result.is_err());
117 }
118
119 #[test]
120 fn test_platform_bootstrap_with_url() {
121 // Test using PlatformBootstrapProvider::with_url()
122 let result = PlatformBootstrapProvider::with_url("http://example.com:8080", 600); // DevSkim: ignore DS137138
123 assert!(result.is_ok());
124 }
125}