-
Notifications
You must be signed in to change notification settings - Fork 30
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 tembo cloud using minimal example #599
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
be346ed
adds test for tembo cloud using minimal example
shahadarsh 4c92914
cleanup
shahadarsh 7d72454
adds env vars from gh action secrets
shahadarsh e060819
replace the name to minimal after instance is deleted
shahadarsh 763a26c
replace the name to minimal after instance is deleted
shahadarsh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
use assert_cmd::Command; | ||
use random_string::generate; | ||
use std::env; | ||
use std::error::Error; | ||
use std::fs::File; | ||
use std::io::{Read, Write}; | ||
use std::path::PathBuf; | ||
use tembo::cli::context::{ | ||
get_current_context, tembo_context_file_path, tembo_credentials_file_path, Environment, | ||
}; | ||
use temboclient::apis::configuration::Configuration; | ||
use temboclient::apis::instance_api::get_all; | ||
use temboclient::models::{Instance, State}; | ||
|
||
const CARGO_BIN: &str = "tembo"; | ||
|
||
#[tokio::test] | ||
async fn minimal_cloud() -> 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)?; | ||
|
||
// tembo init | ||
let mut cmd = Command::cargo_bin(CARGO_BIN)?; | ||
cmd.arg("init"); | ||
cmd.assert().success(); | ||
|
||
let charset = "abcdefghijklmnopqrstuvwxyz"; | ||
let instance_name = generate(10, charset); | ||
|
||
setup_env(&instance_name)?; | ||
|
||
// tembo context set --name local | ||
let mut cmd = Command::cargo_bin(CARGO_BIN)?; | ||
cmd.arg("context"); | ||
cmd.arg("set"); | ||
cmd.arg("--name"); | ||
cmd.arg("prod"); | ||
cmd.assert().success(); | ||
|
||
// tembo apply | ||
let mut cmd = Command::cargo_bin(CARGO_BIN).unwrap(); | ||
cmd.arg("apply"); | ||
cmd.assert().success(); | ||
|
||
let env = get_current_context()?; | ||
let profile = env.clone().selected_profile.unwrap(); | ||
let config = Configuration { | ||
base_path: profile.tembo_host, | ||
bearer_access_token: Some(profile.tembo_access_token), | ||
..Default::default() | ||
}; | ||
|
||
let maybe_instance = get_instance(&instance_name, &config, &env).await?; | ||
if let Some(instance) = maybe_instance { | ||
assert_eq!(instance.state, State::Up, "Instance isn't Up") | ||
} else { | ||
assert!(false, "Instance isn't Up") | ||
} | ||
|
||
// tembo delete | ||
let mut cmd = Command::cargo_bin(CARGO_BIN)?; | ||
cmd.arg("delete"); | ||
let _ = cmd.ok(); | ||
|
||
let maybe_instance = get_instance(&instance_name, &config, &env).await?; | ||
if let Some(instance) = maybe_instance { | ||
assert_eq!(instance.state, State::Deleting, "Instance isn't Deleting") | ||
} else { | ||
assert!(true, "Instance isn't Deleting") | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
fn setup_env(instance_name: &String) -> Result<(), Box<dyn Error>> { | ||
replace_vars_in_file(tembo_context_file_path(), "ORG_ID", &env::var("ORG_ID")?)?; | ||
|
||
replace_vars_in_file( | ||
tembo_credentials_file_path(), | ||
"ACCESS_TOKEN", | ||
&env::var("ACCESS_TOKEN")?, | ||
)?; | ||
|
||
replace_vars_in_file( | ||
tembo_credentials_file_path(), | ||
"https://api.tembo.io", | ||
&env::var("TEMBO_HOST")?, | ||
)?; | ||
|
||
replace_vars_in_file( | ||
tembo_credentials_file_path(), | ||
"https://api.data-1.use1.tembo.io", | ||
&env::var("TEMBO_DATA_HOST")?, | ||
)?; | ||
|
||
replace_vars_in_file( | ||
"tembo.toml".to_string(), | ||
"instance_name = \"minimal\"", | ||
&format!("instance_name = \"{instance_name}\""), | ||
)?; | ||
|
||
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(()) | ||
} | ||
|
||
pub async fn get_instance( | ||
instance_name: &str, | ||
config: &Configuration, | ||
env: &Environment, | ||
) -> Result<Option<Instance>, anyhow::Error> { | ||
let v = get_all(config, env.org_id.clone().unwrap().as_str()).await; | ||
|
||
println!("OrgID: {}", env.org_id.clone().unwrap().as_str()); | ||
|
||
match v { | ||
Ok(result) => { | ||
let maybe_instance = result | ||
.iter() | ||
.find(|instance| instance.instance_name == instance_name); | ||
|
||
if let Some(instance) = maybe_instance { | ||
return Ok(Some(instance.clone())); | ||
} | ||
} | ||
Err(error) => eprintln!("Error getting instance: {}", error), | ||
}; | ||
Ok(None) | ||
} |
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added these secrets to gh action secrets but need to make sure they are added correctly and also need to use appropriate ORG_ID & TOKEN