From 6970eb36f134beb88fc0170675b5ff5984005a8e Mon Sep 17 00:00:00 2001 From: William Martin Date: Mon, 14 Oct 2024 20:48:38 +0200 Subject: [PATCH] Acceptance test issue command --- acceptance/acceptance_test.go | 14 ++++++++++--- acceptance/testdata/issue/issue-comment.txtar | 20 +++++++++++++++++++ .../testdata/issue/issue-create-basic.txtar | 17 ++++++++++++++++ .../issue/issue-create-with-metadata.txtar | 19 ++++++++++++++++++ acceptance/testdata/issue/issue-list.txtar | 16 +++++++++++++++ acceptance/testdata/issue/issue-view.txtar | 17 ++++++++++++++++ 6 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 acceptance/testdata/issue/issue-comment.txtar create mode 100644 acceptance/testdata/issue/issue-create-basic.txtar create mode 100644 acceptance/testdata/issue/issue-create-with-metadata.txtar create mode 100644 acceptance/testdata/issue/issue-list.txtar create mode 100644 acceptance/testdata/issue/issue-view.txtar diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index bcc27faca..429e0850c 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -28,8 +28,16 @@ func TestMain(m *testing.M) { func TestPullRequests(t *testing.T) { var tsEnv testScriptEnv if err := tsEnv.fromEnv(); err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) + t.Fatal(err) + } + + testscript.Run(t, testScriptParamsFor(tsEnv, "pr")) +} + +func TestIssues(t *testing.T) { + var tsEnv testScriptEnv + if err := tsEnv.fromEnv(); err != nil { + t.Fatal(err) } testscript.Run(t, testScriptParamsFor(tsEnv, "pr")) @@ -120,7 +128,7 @@ type missingEnvError struct { } func (e missingEnvError) Error() string { - return fmt.Sprintf("environment variables %s must be set and non-empty", strings.Join(e.missingEnvs, ", ")) + return fmt.Sprintf("environment variable(s) %s must be set and non-empty", strings.Join(e.missingEnvs, ", ")) } type testScriptEnv struct { diff --git a/acceptance/testdata/issue/issue-comment.txtar b/acceptance/testdata/issue/issue-comment.txtar new file mode 100644 index 000000000..f47bf619c --- /dev/null +++ b/acceptance/testdata/issue/issue-comment.txtar @@ -0,0 +1,20 @@ +# 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 + +# Create an issue in the repo +cd $SCRIPT_NAME-$RANDOM_STRING +exec gh issue create --title 'Feature Request' --body 'Feature Body' +stdout2env ISSUE_URL + +# Comment on the issue +exec gh issue comment $ISSUE_URL --body 'Looks like a great feature!' + +# View the issue +exec gh issue view $ISSUE_URL --comments +stdout 'Looks like a great feature!' diff --git a/acceptance/testdata/issue/issue-create-basic.txtar b/acceptance/testdata/issue/issue-create-basic.txtar new file mode 100644 index 000000000..ddba28eec --- /dev/null +++ b/acceptance/testdata/issue/issue-create-basic.txtar @@ -0,0 +1,17 @@ +# 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 + +# Create an issue in the repo +cd $SCRIPT_NAME-$RANDOM_STRING +exec gh issue create --title 'Feature Request' --body 'Feature Body' +stdout2env ISSUE_URL + +# Check the issue was created +exec gh issue view $ISSUE_URL +stdout 'title:\tFeature Request$' diff --git a/acceptance/testdata/issue/issue-create-with-metadata.txtar b/acceptance/testdata/issue/issue-create-with-metadata.txtar new file mode 100644 index 000000000..e1ce5a0da --- /dev/null +++ b/acceptance/testdata/issue/issue-create-with-metadata.txtar @@ -0,0 +1,19 @@ +# 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 + +# Create an issue in the repo +cd $SCRIPT_NAME-$RANDOM_STRING +exec gh issue create --title 'Feature Request' --body 'Feature Body' --assignee '@me' --label 'bug' +stdout2env ISSUE_URL + +# Check the issue was create +exec gh issue view $ISSUE_URL +stdout 'title:\tFeature Request$' +stdout 'assignees:\t.*$' +stdout 'labels:\tbug$' diff --git a/acceptance/testdata/issue/issue-list.txtar b/acceptance/testdata/issue/issue-list.txtar new file mode 100644 index 000000000..5a810f5e1 --- /dev/null +++ b/acceptance/testdata/issue/issue-list.txtar @@ -0,0 +1,16 @@ +# 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 + +# Create an issue in the repo +cd $SCRIPT_NAME-$RANDOM_STRING +exec gh issue create --title 'Feature Request' --body 'Feature Body' + +# Check the issue is included in the list output +exec gh issue list +stdout 'OPEN\tFeature Request' diff --git a/acceptance/testdata/issue/issue-view.txtar b/acceptance/testdata/issue/issue-view.txtar new file mode 100644 index 000000000..ddba28eec --- /dev/null +++ b/acceptance/testdata/issue/issue-view.txtar @@ -0,0 +1,17 @@ +# 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 + +# Create an issue in the repo +cd $SCRIPT_NAME-$RANDOM_STRING +exec gh issue create --title 'Feature Request' --body 'Feature Body' +stdout2env ISSUE_URL + +# Check the issue was created +exec gh issue view $ISSUE_URL +stdout 'title:\tFeature Request$'