feat: add self replacer integration tests#2401
Conversation
59c162c to
5a86f7b
Compare
DavSanchez
left a comment
There was a problem hiding this comment.
Great! Some comments.
b15ed85 to
fa91684
Compare
DavSanchez
left a comment
There was a problem hiding this comment.
Looking great to start driving this functionality. Thanks!
|
|
||
| // Set specific permissions on v1 | ||
| let mut perms = fs::metadata(&binary_v1).unwrap().permissions(); | ||
| perms.set_mode(0o754); |
There was a problem hiding this comment.
Would be nice to have a constant or let binding for this one so it's easier to use down in the code, compare it and document what permission it is.
There was a problem hiding this comment.
Done in last commit.
e2ae2a0 to
51e0d3a
Compare
sigilioso
left a comment
There was a problem hiding this comment.
Looks good! Find some additional questions below
| [[example]] | ||
| name = "self_replacing_binary" | ||
| test = false |
There was a problem hiding this comment.
Nice! Could we add a comment explaining why test = false is needed?
Maybe some comments regarding the purpose of the example (either here or in the example's rust file) would be useful as well.
There was a problem hiding this comment.
Done in last commit.
| backup_path | ||
| ); | ||
|
|
||
| // Verify backup has the original hash |
There was a problem hiding this comment.
Nit:
| // Verify backup has the original hash | |
| // Verify that the binary in the backup is the original |
There was a problem hiding this comment.
Done in last commit
self-replacer/tests/test_helpers.rs
Outdated
| /// This ensures tests work both locally and in CI without requiring a separate build step. | ||
| pub fn get_example_binary() -> PathBuf { |
There was a problem hiding this comment.
Doesn't assert_cmd already take care of binaries in the examples path?
// assert_cmd looks in target/debug/examples/ automatically
Command::cargo_bin("self_replacing_binary")
.expect("Example binary 'self_replacing_binary' should exist");I think that assert_cmd already calls cargo under the hood. Maybe we don't need this helper.
There was a problem hiding this comment.
assert_cmd doesn't work with examples and would need to have this binary in the [[bin]] that is not optimal
| Command::new(&binary_path) | ||
| .assert() | ||
| .success() | ||
| .stdout(predicate::str::starts_with("HASH:")); | ||
|
|
||
| let output2 = Command::new(&binary_path) | ||
| .output() | ||
| .expect("Failed to get new hash"); |
There was a problem hiding this comment.
This test runs the command two times each. Can't we retrieve the hash and assert on the assert_cmd::Command in the same run? I see there's get_output() that we can call on the Asserts that get generated on calls to assert().
There was a problem hiding this comment.
Done in last commit
Summary
Adds comprehensive integration tests for the self-replacer crate that compile and run real binaries to verify self-replacement behavior works correctly on both Unix and Windows platforms.
Test Coverage:
Common tests (Unix + Windows):
Unix-specific tests:
Uses Cargo's
examples/directory to provide a pre-built test binary that:--replaceflagStructure
self-replacer/
├── examples/
│ └── self_replacing_binary.rs # Pre-built example binary
└── tests/
├── integration_tests.rs # All integration tests
└── test_helpers.rs # Helper functions (copy/modify binary)