From b4be8cbf9dfeed652f96f0ba95317742f637d72b Mon Sep 17 00:00:00 2001 From: Andy Feller Date: Thu, 17 Oct 2024 16:01:48 -0400 Subject: [PATCH] Add acceptance tests for `gh variable` --- .../testdata/variable/variable-org.txtar | 20 +++++++++++ .../testdata/variable/variable-repo-env.txtar | 33 +++++++++++++++++++ .../testdata/variable/variable-repo.txtar | 29 ++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 acceptance/testdata/variable/variable-org.txtar create mode 100644 acceptance/testdata/variable/variable-repo-env.txtar create mode 100644 acceptance/testdata/variable/variable-repo.txtar diff --git a/acceptance/testdata/variable/variable-org.txtar b/acceptance/testdata/variable/variable-org.txtar new file mode 100644 index 000000000..370e63b0d --- /dev/null +++ b/acceptance/testdata/variable/variable-org.txtar @@ -0,0 +1,20 @@ +# Prepare organization variable, GitHub Actions uppercases names +env2upper ORG_VARIABLE_NAME=$RANDOM_STRING + +# Confirm organization variable does not exist, will fail admin:org scope missing +! exec gh variable get $ORG_VARIABLE_NAME --org $ORG +stderr 'variable .+ was not found' + +# Create an organization variable +exec gh variable set $ORG_VARIABLE_NAME --org $ORG --body 'just an org variable' + +# Defer organization variable cleanup +defer gh variable delete $ORG_VARIABLE_NAME --org $ORG + +# Confirm organization variable exists +exec gh variable list --org $ORG +stdout $ORG_VARIABLE_NAME + +# Verify repository environment variable can be retrieved +exec gh variable get $ORG_VARIABLE_NAME --org $ORG +stdout 'just an org variable' diff --git a/acceptance/testdata/variable/variable-repo-env.txtar b/acceptance/testdata/variable/variable-repo-env.txtar new file mode 100644 index 000000000..f4b11c3dd --- /dev/null +++ b/acceptance/testdata/variable/variable-repo-env.txtar @@ -0,0 +1,33 @@ +# Force GitHub CLI to treat testscript as TTY +env GH_FORCE_TTY=80 +env REPO=$SCRIPT_NAME-$RANDOM_STRING + +# Create a repository where the variable will be registered +exec gh repo create $ORG/$REPO --add-readme --private + +# Defer repo cleanup +defer gh repo delete --yes $ORG/$REPO + +# Clone the repo +exec gh repo clone $ORG/$REPO +cd $REPO + +# Create a repository environment, will fail if organization does not have environment support +exec gh api /repos/$ORG/$REPO/environments/testscripts -X PUT --jq '.name' +stdout 'testscripts' + +# Verify no repository environment variables exist +exec gh variable list --env testscripts +stderr 'no variables found' + +# Create a repository environment variable +exec gh variable set TESTSCRIPTS_ENV --env testscripts --body 'just a repo env variable' +stdout 'Created variable TESTSCRIPTS_ENV for' + +# Verify new repository environment variable exists +exec gh variable list --env testscripts +stdout 'TESTSCRIPTS_ENV\s+just a repo env variable\s+less than a minute ago' + +# Verify repository environment variable can be retrieved +exec gh variable get TESTSCRIPTS_ENV --env testscripts +stdout 'just a repo env variable' diff --git a/acceptance/testdata/variable/variable-repo.txtar b/acceptance/testdata/variable/variable-repo.txtar new file mode 100644 index 000000000..f6295b566 --- /dev/null +++ b/acceptance/testdata/variable/variable-repo.txtar @@ -0,0 +1,29 @@ +# Setup environment variables to force TTY +env GH_FORCE_TTY=80 +env REPO=$SCRIPT_NAME-$RANDOM_STRING + +# Create a repository where the variable will be registered +exec gh repo create $ORG/$REPO --add-readme --private + +# Defer repo cleanup +defer gh repo delete --yes $ORG/$REPO + +# Clone the repo +exec gh repo clone $ORG/$REPO +cd $REPO + +# Verify no repository variables exist +exec gh variable list +stderr 'no variables found' + +# Create a repository variable +exec gh variable set TESTSCRIPTS --body 'just a repo variable' +stdout 'Created variable TESTSCRIPTS for' + +# Verify new repository variable exists +exec gh variable list +stdout 'TESTSCRIPTS\s+just a repo variable\s+less than a minute ago' + +# Verify repository variable can be retrieved +exec gh variable get TESTSCRIPTS +stdout 'just a repo variable'