From a009933a166b022613e1f98c8951bcd3e7ec96b4 Mon Sep 17 00:00:00 2001 From: bagtoad <47394200+BagToad@users.noreply.github.com> Date: Wed, 16 Oct 2024 11:03:50 -0600 Subject: [PATCH] Add acceptance tests for `release` commands --- acceptance/acceptance_test.go | 12 +++++++-- acceptance/testdata/release/create.txtar | 12 +++++++++ acceptance/testdata/release/list.txtar | 16 ++++++++++++ .../testdata/release/upload-download.txtar | 25 +++++++++++++++++++ acceptance/testdata/release/view.txtar | 16 ++++++++++++ 5 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 acceptance/testdata/release/create.txtar create mode 100644 acceptance/testdata/release/list.txtar create mode 100644 acceptance/testdata/release/upload-download.txtar create mode 100644 acceptance/testdata/release/view.txtar diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index 3040ce9b2..51e96778a 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -48,8 +48,7 @@ func TestIssues(t *testing.T) { func TestWorkflows(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, "workflow")) @@ -64,6 +63,15 @@ func TestAPI(t *testing.T) { testscript.Run(t, testScriptParamsFor(tsEnv, "api")) } +func TestReleases(t *testing.T) { + var tsEnv testScriptEnv + if err := tsEnv.fromEnv(); err != nil { + t.Fatal(err) + } + + testscript.Run(t, testScriptParamsFor(tsEnv, "release")) +} + func testScriptParamsFor(tsEnv testScriptEnv, command string) testscript.Params { var files []string if tsEnv.script != "" { diff --git a/acceptance/testdata/release/create.txtar b/acceptance/testdata/release/create.txtar new file mode 100644 index 000000000..3bdafe769 --- /dev/null +++ b/acceptance/testdata/release/create.txtar @@ -0,0 +1,12 @@ +# 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 a release in the repo +cd $SCRIPT_NAME-$RANDOM_STRING +exec gh release create v1.2.3 --notes 'awesome release' --latest diff --git a/acceptance/testdata/release/list.txtar b/acceptance/testdata/release/list.txtar new file mode 100644 index 000000000..844b25daa --- /dev/null +++ b/acceptance/testdata/release/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 a release in the repo +cd $SCRIPT_NAME-$RANDOM_STRING +exec gh release create v1.2.3 --notes 'awesome release' --latest + +# List the releases +exec gh release list +stdout 'v1.2.3' \ No newline at end of file diff --git a/acceptance/testdata/release/upload-download.txtar b/acceptance/testdata/release/upload-download.txtar new file mode 100644 index 000000000..92bfa4c71 --- /dev/null +++ b/acceptance/testdata/release/upload-download.txtar @@ -0,0 +1,25 @@ +# 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 a release in the repo +cd $SCRIPT_NAME-$RANDOM_STRING +exec gh release create v1.2.3 --notes 'awesome release' --latest + +# Upload an asset to the release +exec gh release upload v1.2.3 ../asset.txt +stdout '' + +# Download the asset from the release +exec gh release download v1.2.3 +exists asset.txt +exec gh release download v1.2.3 --archive=zip +exists $SCRIPT_NAME-$RANDOM_STRING-1.2.3.zip + +-- asset.txt -- +Hello, world! \ No newline at end of file diff --git a/acceptance/testdata/release/view.txtar b/acceptance/testdata/release/view.txtar new file mode 100644 index 000000000..a7138812a --- /dev/null +++ b/acceptance/testdata/release/view.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 a release in the repo +cd $SCRIPT_NAME-$RANDOM_STRING +exec gh release create v1.2.3 --notes 'awesome release' --latest + +# View the release +exec gh release view v1.2.3 +stdout 'v1.2.3' \ No newline at end of file