Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds test for local using minimal example with Standard stack against pg_versions(14, 15 & 16) #630

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tembo-cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tembo-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ k8s-openapi = { version = "0.18.0", features = ["v1_25", "schemars"], default-fe
tembo-stacks = "0.3.9"
itertools = "0.12.1"
random-string = "1.1.0"
test-case = "=2.0.0-rc2"

[target.aarch64-unknown-linux-musl.dependencies]
openssl = { version = "0.10", features = ["vendored"] }
Expand Down
1 change: 1 addition & 0 deletions tembo-cli/examples/minimal/tembo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[minimal]
environment = "prod"
instance_name = "minimal"
pg_version = 14
29 changes: 28 additions & 1 deletion tembo-cli/tests/integration_tests_docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ use predicates::prelude::*;
use sqlx::postgres::PgConnectOptions;
use std::env;
use std::error::Error;
use std::fs::File;
use std::io::{Read, Write};
use std::path::PathBuf;
use std::process::Command;
use std::thread::sleep;
use std::time::Duration;
use tembo::cli::sqlx_utils::SqlxUtils;
use test_case::test_case;

const CARGO_BIN: &str = "tembo";

Expand All @@ -24,13 +27,22 @@ fn help() -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}

#[test_case(14)]
#[test_case(15)]
#[test_case(16)]
#[tokio::test]
async fn minimal() -> Result<(), Box<dyn Error>> {
async fn minimal(version: i32) -> Result<(), Box<dyn Error>> {
let root_dir = env!("CARGO_MANIFEST_DIR");
let test_dir = PathBuf::from(root_dir).join("examples").join("minimal");

env::set_current_dir(&test_dir)?;

replace_vars_in_file(
"tembo.toml".to_string(),
"pg_version = 15",
&format!("pg_version = {version}"),
)?;

// tembo init
let mut cmd = Command::cargo_bin(CARGO_BIN)?;
cmd.arg("init");
Expand Down Expand Up @@ -220,3 +232,18 @@ async fn assert_can_connect(instance_name: String) -> Result<(), Box<dyn Error>>
assert!(result.contains('1'), "Query did not return 1");
Ok(())
}

fn replace_vars_in_file(
file_path: String,
word_from: &str,
word_to: &str,
) -> Result<(), Box<dyn Error>> {
let mut src = File::open(&file_path)?;
let mut data = String::new();
src.read_to_string(&mut data)?;
drop(src);
let new_data = data.replace(&*word_from, &*word_to);
let mut dst = File::create(&file_path)?;
dst.write(new_data.as_bytes())?;
Ok(())
}