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#![allow(unexpected_cfgs)]
16
17//! Platform bootstrap plugin for Drasi
18//!
19//! This plugin provides the Platform bootstrap provider implementation for fetching
20//! initial data from a remote Drasi Query API service.
21//!
22//! # Example
23//!
24//! ```no_run
25//! use drasi_bootstrap_platform::PlatformBootstrapProvider;
26//!
27//! // Using the builder
28//! let provider = PlatformBootstrapProvider::builder()
29//! .with_query_api_url("http://remote-drasi:8080")
30//! .with_timeout_seconds(600)
31//! .build()
32//! .expect("Failed to create provider");
33//!
34//! // Or using configuration
35//! use drasi_lib::bootstrap::PlatformBootstrapConfig;
36//!
37//! let config = PlatformBootstrapConfig {
38//! query_api_url: Some("http://remote-drasi:8080".to_string()),
39//! timeout_seconds: 600,
40//! };
41//! let provider = PlatformBootstrapProvider::new(config)
42//! .expect("Failed to create provider");
43//! ```
44
45pub mod descriptor;
46pub mod platform;
47
48pub use drasi_lib::bootstrap::PlatformBootstrapConfig;
49pub use platform::{PlatformBootstrapProvider, PlatformBootstrapProviderBuilder};
50
51/// Dynamic plugin entry point.
52///
53/// Dynamic plugin entry point.
54#[cfg(feature = "dynamic-plugin")]
55drasi_plugin_sdk::export_plugin!(
56 plugin_id = "platform-bootstrap",
57 core_version = env!("CARGO_PKG_VERSION"),
58 lib_version = env!("CARGO_PKG_VERSION"),
59 plugin_version = env!("CARGO_PKG_VERSION"),
60 source_descriptors = [],
61 reaction_descriptors = [],
62 bootstrap_descriptors = [descriptor::PlatformBootstrapDescriptor],
63);
64
65#[cfg(test)]
66mod tests {
67 use super::*;
68
69 #[test]
70 fn test_platform_bootstrap_builder_requires_url() {
71 // Builder without URL should fail to build
72 let result = PlatformBootstrapProviderBuilder::new().build();
73 assert!(result.is_err());
74 }
75
76 #[test]
77 fn test_platform_bootstrap_builder_with_valid_url() {
78 // Builder with valid URL should succeed
79 let result = PlatformBootstrapProviderBuilder::new()
80 .with_query_api_url("http://remote-drasi:8080") // DevSkim: ignore DS137138
81 .with_timeout_seconds(600)
82 .build();
83 assert!(result.is_ok());
84 }
85
86 #[test]
87 fn test_platform_bootstrap_builder_invalid_url() {
88 // Builder with invalid URL should fail
89 let result = PlatformBootstrapProviderBuilder::new()
90 .with_query_api_url("not-a-valid-url")
91 .build();
92 assert!(result.is_err());
93 }
94
95 #[test]
96 fn test_platform_bootstrap_builder_default() {
97 // Default builder should have no URL set
98 let builder = PlatformBootstrapProviderBuilder::default();
99 // Without URL, build should fail
100 let result = builder.build();
101 assert!(result.is_err());
102 }
103
104 #[test]
105 fn test_platform_bootstrap_from_provider_method() {
106 // Test using PlatformBootstrapProvider::builder()
107 let result = PlatformBootstrapProvider::builder()
108 .with_query_api_url("http://source-api:9000") // DevSkim: ignore DS137138
109 .with_timeout_seconds(900)
110 .build();
111 assert!(result.is_ok());
112 }
113
114 #[test]
115 fn test_platform_bootstrap_new_with_config() {
116 // Test using PlatformBootstrapProvider::new(config)
117 let config = PlatformBootstrapConfig {
118 query_api_url: Some("http://localhost:8080".to_string()), // DevSkim: ignore DS137138
119 timeout_seconds: 300,
120 };
121 let result = PlatformBootstrapProvider::new(config);
122 assert!(result.is_ok());
123 }
124
125 #[test]
126 fn test_platform_bootstrap_new_without_url() {
127 // Config without URL should fail
128 let config = PlatformBootstrapConfig {
129 query_api_url: None,
130 timeout_seconds: 300,
131 };
132 let result = PlatformBootstrapProvider::new(config);
133 assert!(result.is_err());
134 }
135
136 #[test]
137 fn test_platform_bootstrap_with_url() {
138 // Test using PlatformBootstrapProvider::with_url()
139 let result = PlatformBootstrapProvider::with_url("http://example.com:8080", 600); // DevSkim: ignore DS137138
140 assert!(result.is_ok());
141 }
142}