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

Proposal for unit & integration testing #1

Merged
merged 24 commits into from
Oct 13, 2021
Merged

Proposal for unit & integration testing #1

merged 24 commits into from
Oct 13, 2021

Conversation

robertdfrench
Copy link
Owner

@robertdfrench robertdfrench commented Oct 10, 2021

There's a lot going on, and I haven't documented any of it. But the idea is to be able to do unit tests without relying on real git, since it could be slow, use the network, or impact local state.

So cargo test --lib will use mostly in-memory tests, reaching out to fake git binaries when necessary. The Integration tests (under the tests/ folder) will run against the real git binary, and may do things like authenticate to remote hosts or create / remove branches.

This is not really intended to be a PR, so much as a conversation starter around testing. I think we'll want to do some of this, but maybe not all of it.

There's a lot going on, and I haven't documented any of it. But the idea
is to be able to do unit tests without relying on real git, since it
could be slow, use the network, or impact local state.

So `cargo test --lib` will use mostly in-memory tests, reaching out to
fake git binaries when necessary. The Integration tests (under the
`tests/` folder) will run against the real git binary, and may do things
like authenticate to remote hosts or create / remove branches.
@robertdfrench robertdfrench marked this pull request as draft October 10, 2021 05:15
@robertdfrench robertdfrench marked this pull request as ready for review October 10, 2021 05:15
@robertdfrench robertdfrench changed the title Draft: proposal for unit & integration testing Proposal for unit & integration testing Oct 10, 2021
failing_git.sh Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@calebwherry calebwherry left a comment

Choose a reason for hiding this comment

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

Finished review.

J. Caleb Wherry and others added 2 commits October 10, 2021 12:59
* Rewrote fake_git sh scripts in Rust
* Moved all executables to src/bin & removed from TOML
* Updated tests to use new exes
I wasn't 100% sure this would work at first, but you can split an `impl`
block up over multiple sections. So since `with_path` doesn't need to be
defined for the `Git` struct in application code, I moved it into the
`test` module instead.

If you don't do something like this, then marking `with_path` as private
will generate a warning, since no other application code (even within
its own module) uses it.

Two alternative approaches:
* Leave `with_path` where it is, but mark it as `#[cfg(test)]`
* Change `new` to call `with_path`, so that `with_path` is used by something.
src/lib.rs Outdated Show resolved Hide resolved
robertdfrench and others added 4 commits October 10, 2021 18:56
Invoking git either raises an `io::Error` or returns a
`std::process::ExitStatus`, the `success()` method of which may return
`false`. The new type, `GitError`, is designed to encompass both of
these cases and should simplify error handling when interacting with git
subprocesses.
Commented Cargo.lock from gitignore so that we have a record
of why we did it. I think something like this is easy to forget
so leaving it along with the original comment makes sense.

Adding the version of Cargo.lock I get running on MacOs.
@calebwherry calebwherry added this to the Git PR v1.0.0 milestone Oct 11, 2021
Copy link
Collaborator

@calebwherry calebwherry left a comment

Choose a reason for hiding this comment

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

All latest changes and comments resolved. Need final pass on open items.

We can add build/release/platform info once we have CI set up (see #2).
@robertdfrench
Copy link
Owner Author

@calebwherry I like all your changes, I think I addressed the remaining concerns you had. Only thing left is figuring out what path to take with matching remotes other than "origin".

@robertdfrench
Copy link
Owner Author

Btw, here is the link to see what the updated README will look like: https://github.com/robertdfrench/git-pr/tree/pr-list/0

@calebwherry calebwherry added this to In progress in GitPr Kanban Oct 12, 2021
As @calebwherry said in the original issue:

> Using origin can cause issues with others not using that wordage.
> Replace with "not slash" match as it can be anything.

I tried to be clever and match hyphenated words, but then I tried to
look up the actual definition of a remote name, and there does not seem
to be one: https://stackoverflow.com/questions/41461152/which-characters-are-illegal-within-a-git-remote-name/41462742

So, it seems like the best thing to do is detect whatever isn't a slash,
because we know those *can't* be allowed, since they are allowed in
branch names (and therefore any ref with slashes in the remote or
branch would parse ambiguously). Whatever else git tells us is obviously
valid, since git is the authority here.
@calebwherry
Copy link
Collaborator

@robertdfrench Can you fix the merge conflicts? I assume just merge trunk is all that is needed? Once you do that, I'll merge this PR in!

@robertdfrench
Copy link
Owner Author

@calebwherry good catch, and luckily this gives us a chance to see whether our new CI pipeline passes!

robertdfrench and others added 8 commits October 12, 2021 21:44
GitHub checks out the repo in a detached head state. We use
a trick noted in the task to fix it.
GitHub checks out the repo in a detached head state. We use
a trick noted in the task to fix it.

Try 2...
GitHub checks out the repo in a detached head state. We use
a trick noted in the task to fix it.

Try 3...
@calebwherry calebwherry self-requested a review October 13, 2021 18:00
@robertdfrench robertdfrench merged commit 3aedbd6 into trunk Oct 13, 2021
GitPr Kanban automation moved this from In progress to Done Oct 13, 2021
@calebwherry calebwherry deleted the pr-list/0 branch October 15, 2021 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants