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