vaultrs_test/
lib.rs

1//! # vaultrs-test
2//!
3//! <p align="center">
4//!     <a href="https://crates.io/crates/vaultrs-test">
5//!         <img src="https://img.shields.io/crates/v/vaultrs-test">
6//!     </a>
7//!     <a href="https://docs.rs/vaultrs-test">
8//!         <img src="https://img.shields.io/docsrs/vaultrs-test" />
9//!     </a>
10//!     <a href="https://www.vaultproject.io/">
11//!         <img src="https://img.shields.io/badge/Vault-1.8.2-green" />
12//!     </a>
13//!     <a href="https://github.com/jmgilman/vaultrs-test/actions/workflows/ci.yml">
14//!         <img src="https://github.com/jmgilman/vaultrs-test/actions/workflows/ci.yml/badge.svg"/>
15//!     </a>
16//! </p>
17//!
18//! > A test suite for testing against [Hashicorp Vault][1] servers.
19//!
20//! ## Installation
21//!
22//! Add `vaultrs-test` as a developemnt depdendency to your cargo.toml:
23//! ```ignore
24//! [dev-dependencies]
25//! vaultrs-test = "0.2.0"
26//! ```
27//!
28//! ## Usage
29//!
30//! ```rust
31//! use vaultrs_test::docker::{Server, ServerConfig};
32//! use vaultrs_test::{VaultServer, VaultServerConfig};
33//!
34//! // Configures a container to run Vault server v1.8.2
35//! let config = VaultServerConfig::default(Some("1.8.2"));
36//!
37//! // Creates a test instance to run the container in
38//! let instance = config.to_instance();
39//!
40//! // Runs the test instance, passing in details about the container environment
41//! instance.run(|ops| async move {
42//!     // The code below only runs after the container is verified running
43//!
44//!     // Creates an abstraction for interacting with the Vault container
45//!     let server = VaultServer::new(&ops, &config);
46//!
47//!     // Run test code against container
48//! })
49//!
50//! // Container is cleaned up at this point
51//! ```
52//!
53//! ## Testing
54//!
55//! Run tests with cargo:
56//!
57//! ```ignore
58//! cargo test
59//! ```
60//!
61//! [1]: https://www.vaultproject.io/
62
63pub mod docker;
64pub mod oidc;
65pub mod vault;
66
67pub use docker::TestInstance;
68pub use vault::VaultServer;
69pub use vault::VaultServerConfig;
70
71#[cfg(test)]
72mod tests {
73    use crate::{
74        docker::{Server, ServerConfig},
75        oidc::{OIDCServer, OIDCServerConfig},
76        vault::{VaultServer, VaultServerConfig},
77        TestInstance,
78    };
79
80    #[test]
81    fn test() {
82        let oidc_config = OIDCServerConfig::default(Some("0.3.4"));
83        let vault_config = VaultServerConfig::default(Some("1.8.2"));
84        let instance = TestInstance::new(vec![oidc_config.to_comp(), vault_config.to_comp()]);
85
86        instance.run(|ops| async move {
87            let oidc_server = OIDCServer::new(&ops, &oidc_config);
88            let res = reqwest::get(oidc_server.address).await;
89            assert!(res.is_ok());
90
91            let vault_server = VaultServer::new(&ops, &vault_config);
92            let res = reqwest::get(vault_server.address).await;
93            assert!(res.is_ok());
94        })
95    }
96}