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

Fixed the test file in dotenv.rs #1651

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
29 changes: 29 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions cmd/crates/soroban-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ soroban-sdk = { workspace = true }
sep5 = { workspace = true }
soroban-cli = { workspace = true }
soroban-rpc = { workspace = true }
rand = "0.8"
wasm-encoder = "0.24"
wasmparser = "0.102"
tempfile = "3.2"
KoxyG marked this conversation as resolved.
Show resolved Hide resolved

thiserror = "1.0.31"
sha2 = "0.10.6"
Expand Down
38 changes: 11 additions & 27 deletions cmd/crates/soroban-test/tests/it/integration/dotenv.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,17 @@
use soroban_test::TestEnv;

use super::util::deploy_hello;
use soroban_test::TestEnv;

fn write_env_file(e: &TestEnv, contents: &str) {
let env_file = e.dir().join(".env");
let contents = format!("SOROBAN_CONTRACT_ID={contents}");
std::fs::write(&env_file, &contents).unwrap();
assert_eq!(contents, std::fs::read_to_string(env_file).unwrap());
}

#[tokio::test]
async fn can_read_file() {
let e = &TestEnv::new();
std::thread::sleep(core::time::Duration::from_millis(1000));
let id = deploy_hello(e).await;
println!("{id}");
write_env_file(e, &id);
e.new_assert_cmd("contract")
.arg("invoke")
.arg("--")
.arg("hello")
.arg("--world=world")
.assert()
.stdout("[\"Hello\",\"world\"]\n")
.success();
KoxyG marked this conversation as resolved.
Show resolved Hide resolved
std::fs::write(&env_file, &contents).expect("Failed to write to .env file");
let read_contents = std::fs::read_to_string(&env_file).expect("Failed to read .env file");
assert_eq!(contents, read_contents, "Contents of .env do not match");
}

#[tokio::test]
async fn current_env_not_overwritten() {
let e = TestEnv::new();
std::thread::sleep(core::time::Duration::from_millis(3000));
write_env_file(&e, &deploy_hello(&e).await);
e.new_assert_cmd("contract")
.env(
Expand All @@ -49,20 +31,22 @@ async fn current_env_not_overwritten() {
#[tokio::test]
async fn cli_args_have_priority() {
let e = &TestEnv::new();
std::thread::sleep(core::time::Duration::from_millis(6000));
let id = deploy_hello(e).await;
write_env_file(e, &id);
e.new_assert_cmd("contract")

let result = e
.new_assert_cmd("contract")
.env(
"SOROBAN_CONTRACT_ID",
"CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4",
"CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4",
KoxyG marked this conversation as resolved.
Show resolved Hide resolved
)
.arg("invoke")
.arg("--id")
.arg(id)
.arg("--")
.arg("hello")
.arg("--world=world")
.assert()
.stdout("[\"Hello\",\"world\"]\n");
.assert();

result.stdout("[\"Hello\",\"world\"]\n").success();
Comment on lines +53 to +67
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do these lines need to change? I see that a .success() has been added, and the stdout has been moved to after the .assert(). What's the significance of those changes?

}