testkit_macros/
lib.rs

1#![deny(warnings)]
2#![warn(unused_extern_crates)]
3#![deny(clippy::todo)]
4#![deny(clippy::unimplemented)]
5#![deny(clippy::unwrap_used)]
6#![deny(clippy::expect_used)]
7#![deny(clippy::panic)]
8#![deny(clippy::unreachable)]
9#![deny(clippy::await_holding_lock)]
10#![deny(clippy::needless_pass_by_value)]
11#![deny(clippy::trivially_copy_pass_by_ref)]
12
13mod entry;
14
15#[allow(unused_extern_crates)]
16extern crate proc_macro;
17
18use proc_macro::TokenStream;
19use quote::quote;
20
21#[proc_macro_attribute]
22pub fn test(args: TokenStream, item: TokenStream) -> TokenStream {
23    entry::test(args, item)
24}
25
26#[proc_macro]
27/// used in testkit to build and run the kanidm binary with the correct environment variables
28pub fn cli_kanidm(_input: TokenStream) -> TokenStream {
29    let code = quote! {
30        {
31        // get the manifest path for the kanidm binary
32        let cli_manifest_file_path =
33            format!("{}/../../tools/cli/Cargo.toml", env!("CARGO_MANIFEST_DIR"));
34        let cli_manifest_file = std::path::Path::new(&cli_manifest_file_path)
35            .canonicalize()
36            .unwrap();
37
38        // make sure we're building/running the current version
39        let mut kanidm = escargot::CargoBuild::new()
40            .bin("kanidm")
41            .current_release()
42            .current_target()
43            .manifest_path(&cli_manifest_file)
44            .run()
45            .unwrap();
46        let mut kanidm = kanidm.command();
47        kanidm.env("KANIDM_URL", rsclient.get_url().to_string());
48        kanidm.env("KANIDM_TOKEN_CACHE_PATH", &token_cache_path);
49        kanidm
50        }
51    };
52
53    code.into()
54}