Skip to content

Commit

Permalink
ci: remove github services for devcontainers
Browse files Browse the repository at this point in the history
  • Loading branch information
bbortt committed Jul 9, 2024
1 parent c4792f4 commit 31de284
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 16 deletions.
16 changes: 0 additions & 16 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,6 @@ jobs:
build:
name: 'Rust Build'
runs-on: ubuntu-latest
services:
postgres:
image: postgres:12.19-alpine3.20
ports:
- 5432:5432
env:
POSTGRES_DB: demo
POSTGRES_USER: demo
POSTGRES_PASSWORD: demo_password
vault:
image: hashicorp/vault:1.17.1
ports:
- 8200:8200
options: --cap-add=IPC_LOCK
env:
VAULT_DEV_ROOT_TOKEN_ID: 'root-token'
steps:
- name: Check out code
uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ assert_cmd = "2.0.14"
predicates = "3.1.0"
reqwest = { version = "0.12.5", features = ["json"] }
serde_json = "1.0.120"
testcontainers = { version = "0.20.0", features = ["blocking"] }
Empty file modified dev/podman.sh
100755 → 100644
Empty file.
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub(crate) fn read_config(config_path: PathBuf) -> Config {
serde_yaml::from_str(&config_data).expect("Failed to parse configuration")
}

#[cfg(test)]
mod tests {
use super::*;

Expand Down
1 change: 1 addition & 0 deletions src/vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ fn get_vault_client(config: &Config) -> VaultClient {
vault_client
}

#[cfg(test)]
mod tests {
use super::*;
use crate::config::PostgresConfig;
Expand Down
1 change: 1 addition & 0 deletions src/workflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ fn update_passive_user_postgres_password(
debug!("Successfully rotated PostgreSQL password of passive user");
}

#[cfg(test)]
mod tests {
use super::*;
use postgres::Client;
Expand Down
21 changes: 21 additions & 0 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use testcontainers::{Container, core::{IntoContainerPort, WaitFor}, GenericImage, ImageExt, runners::SyncRunner};

pub fn postgres_container() -> Container<GenericImage> {
GenericImage::new("postgres", "12.19-alpine3.20")
.with_exposed_port(5432.tcp())
.with_wait_for(WaitFor::message_on_stdout("database system is ready to accept connections"))
.with_env_var("POSTGRES_DB", "demo")
.with_env_var("POSTGRES_USER", "demo")
.with_env_var("POSTGRES_PASSWORD", "demo_password")
.start()
.expect("PostgreSQL database started")
}

pub fn vault_container() -> Container<GenericImage> {
GenericImage::new("hashicorp/vault", "1.17.1")
.with_exposed_port(8200.tcp())
.with_wait_for(WaitFor::message_on_stdout("==> Vault server started! Log data will stream in below"))
.with_env_var("VAULT_DEV_ROOT_TOKEN_ID", "root-token")
.start()
.expect("Vault started")
}
6 changes: 6 additions & 0 deletions tests/init_vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ use reqwest::{Client, Response};
use serde_json::Value;
use tokio::runtime::{Builder, Runtime};

mod common;

lazy_static! {
static ref BIN_PATH: PathBuf = cargo_bin(env!("CARGO_PKG_NAME"));
}

#[test]
fn init_vault_new_path() {
common::vault_container();

Command::new(&*BIN_PATH)
.arg("init-vault")
.arg("-c")
Expand Down Expand Up @@ -42,6 +46,8 @@ fn init_vault_new_path() {

#[test]
fn init_vault_invalid_url() {
common::vault_container();

Command::new(&*BIN_PATH)
.arg("init-vault")
.arg("-c")
Expand Down
11 changes: 11 additions & 0 deletions tests/rotate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use serde::{Deserialize, Serialize};
use serde_json::Value;
use tokio::runtime::{Builder, Runtime};

mod common;

lazy_static! {
static ref BIN_PATH: PathBuf = cargo_bin(env!("CARGO_PKG_NAME"));
}
Expand All @@ -32,6 +34,9 @@ struct VaultSecretDTO {

#[test]
fn rotate_secrets() {
common::vault_container();
common::postgres_container();

let http_client = Client::new();
let url = "http://localhost:8200/v1/secret/data/rotate/secrets";

Expand Down Expand Up @@ -103,6 +108,9 @@ fn rotate_secrets() {

#[test]
fn rotate_invalid_initialized_secret() {
common::vault_container();
common::postgres_container();

let http_client = Client::new();
let url = "http://localhost:8200/v1/secret/data/rotate/invalid/initialized/secret";

Expand All @@ -123,6 +131,9 @@ fn rotate_invalid_initialized_secret() {

#[test]
fn rotate_non_existing_secret() {
common::vault_container();
common::postgres_container();

Command::new(&*BIN_PATH)
.arg("rotate")
.arg("-c")
Expand Down

0 comments on commit 31de284

Please sign in to comment.