Add tests for using the pr Finder outside of repo
This includes an acceptance test for `gh pr view` and a unit test on `TestFind`
This commit is contained in:
parent
de9971d718
commit
29e57ee8e7
2 changed files with 60 additions and 0 deletions
28
acceptance/testdata/pr/pr-view-outside-repo.txtar
vendored
Normal file
28
acceptance/testdata/pr/pr-view-outside-repo.txtar
vendored
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
# Use gh as a credential helper
|
||||
exec gh auth setup-git
|
||||
|
||||
# Create a repository with a file so it has a default branch
|
||||
exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --add-readme --private
|
||||
|
||||
# Defer repo cleanup
|
||||
defer gh repo delete --yes $ORG/$SCRIPT_NAME-$RANDOM_STRING
|
||||
|
||||
# Clone the repo
|
||||
exec gh repo clone $ORG/$SCRIPT_NAME-$RANDOM_STRING
|
||||
|
||||
# Prepare a branch to PR
|
||||
cd $SCRIPT_NAME-$RANDOM_STRING
|
||||
exec git checkout -b feature-branch
|
||||
exec git commit --allow-empty -m 'Empty Commit'
|
||||
exec git push -u origin feature-branch
|
||||
|
||||
# Create the PR
|
||||
exec gh pr create --title 'Feature Title' --body 'Feature Body'
|
||||
stdout2env PR_URL
|
||||
|
||||
# Change directories
|
||||
cd ..
|
||||
|
||||
# View the PR
|
||||
exec gh pr view $PR_URL
|
||||
stdout 'Feature Title'
|
||||
|
|
@ -211,6 +211,38 @@ func TestFind(t *testing.T) {
|
|||
wantPR: 13,
|
||||
wantRepo: "https://example.org/OWNER/REPO",
|
||||
},
|
||||
{
|
||||
name: "PR URL argument and not in a local git repo",
|
||||
args: args{
|
||||
selector: "https://example.org/OWNER/REPO/pull/13/files",
|
||||
fields: []string{"id", "number"},
|
||||
baseRepoFn: nil,
|
||||
branchFn: func() (string, error) {
|
||||
return "", &git.GitError{
|
||||
Stderr: "fatal: not a git repository (or any of the parent directories): .git",
|
||||
ExitCode: 128,
|
||||
}
|
||||
},
|
||||
branchConfig: stubBranchConfig(git.BranchConfig{}, &git.GitError{
|
||||
Stderr: "fatal: not a git repository (or any of the parent directories): .git",
|
||||
ExitCode: 128,
|
||||
}),
|
||||
pushDefault: stubPushDefault("simple", nil),
|
||||
remotePushDefault: stubRemotePushDefault("", &git.GitError{
|
||||
Stderr: "fatal: not a git repository (or any of the parent directories): .git",
|
||||
ExitCode: 128,
|
||||
}),
|
||||
},
|
||||
httpStub: func(r *httpmock.Registry) {
|
||||
r.Register(
|
||||
httpmock.GraphQL(`query PullRequestByNumber\b`),
|
||||
httpmock.StringResponse(`{"data":{"repository":{
|
||||
"pullRequest":{"number":13}
|
||||
}}}`))
|
||||
},
|
||||
wantPR: 13,
|
||||
wantRepo: "https://example.org/OWNER/REPO",
|
||||
},
|
||||
{
|
||||
name: "when provided branch argument with an open and closed PR for that branch name, it returns the open PR",
|
||||
args: args{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue