|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +/// Add an additional module here for convenience to scope this to only |
| 19 | +/// when the feature integration-tests is built |
| 20 | +#[cfg(feature = "integration-tests")] |
| 21 | +mod tests { |
| 22 | + use datafusion::error::{DataFusionError, Result}; |
| 23 | + use datafusion_common::config::{ConfigExtension, ConfigOptions}; |
| 24 | + use datafusion_ffi::config::extension_options::FFI_ExtensionOptions; |
| 25 | + use datafusion_ffi::tests::config::ExternalConfig; |
| 26 | + use datafusion_ffi::tests::utils::get_module; |
| 27 | + |
| 28 | + #[test] |
| 29 | + fn test_ffi_extension_options() -> Result<()> { |
| 30 | + let module = get_module()?; |
| 31 | + |
| 32 | + let extension_options = |
| 33 | + module |
| 34 | + .create_extension_options() |
| 35 | + .ok_or(DataFusionError::NotImplemented( |
| 36 | + "External test library failed to implement create_extension_options" |
| 37 | + .to_string(), |
| 38 | + ))?(); |
| 39 | + |
| 40 | + println!("{:?} {}", extension_options, FFI_ExtensionOptions::PREFIX); |
| 41 | + |
| 42 | + let mut config = ConfigOptions::new(); |
| 43 | + config.extensions.insert(extension_options); |
| 44 | + |
| 45 | + fn extract_config(config: &ConfigOptions) -> ExternalConfig { |
| 46 | + // For our use case of this test, we do not need to check |
| 47 | + // using .get::<ExternalConfig>() but it is left here as an |
| 48 | + // example to users of this crate. |
| 49 | + config |
| 50 | + .extensions |
| 51 | + .get::<ExternalConfig>() |
| 52 | + .map(|v| v.to_owned()) |
| 53 | + .or_else(|| { |
| 54 | + config |
| 55 | + .extensions |
| 56 | + .get::<FFI_ExtensionOptions>() |
| 57 | + .and_then(|ext| ext.to_extension().ok()) |
| 58 | + }) |
| 59 | + .expect("Should be able to get ExternalConfig") |
| 60 | + } |
| 61 | + |
| 62 | + // Verify default values are as expected |
| 63 | + let returned_config = extract_config(&config); |
| 64 | + |
| 65 | + assert_eq!(returned_config, ExternalConfig::default()); |
| 66 | + |
| 67 | + config.set("external_config.is_enabled", "false")?; |
| 68 | + let returned_config = extract_config(&config); |
| 69 | + assert!(!returned_config.is_enabled); |
| 70 | + |
| 71 | + Ok(()) |
| 72 | + } |
| 73 | +} |
0 commit comments