From 6192ac74df5a583fb487f3f248064738e9fa9b32 Mon Sep 17 00:00:00 2001 From: Andy Feller Date: Mon, 21 Oct 2024 16:02:26 -0400 Subject: [PATCH] Update variable testscripts based on secret This commit refactors a bit of the variable testscripts given the changes in the secret testscripts efforts, removing potentially unnecessary assertions and making these look more similar to other testscripts. --- .../testdata/variable/variable-org.txtar | 20 +++++++-------- .../testdata/variable/variable-repo-env.txtar | 25 +++++++++---------- .../testdata/variable/variable-repo.txtar | 17 ++++++------- 3 files changed, 30 insertions(+), 32 deletions(-) diff --git a/acceptance/testdata/variable/variable-org.txtar b/acceptance/testdata/variable/variable-org.txtar index 370e63b0d..c09381b29 100644 --- a/acceptance/testdata/variable/variable-org.txtar +++ b/acceptance/testdata/variable/variable-org.txtar @@ -1,20 +1,20 @@ -# Prepare organization variable, GitHub Actions uppercases names -env2upper ORG_VARIABLE_NAME=$RANDOM_STRING +# Setup environment variables used for testscript +env2upper VAR_NAME=${SCRIPT_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' +exec gh variable list --org $ORG +! stdout $VAR_NAME # Create an organization variable -exec gh variable set $ORG_VARIABLE_NAME --org $ORG --body 'just an org variable' +exec gh variable set $VAR_NAME --org $ORG --body 'just an org variable' # Defer organization variable cleanup -defer gh variable delete $ORG_VARIABLE_NAME --org $ORG +defer gh variable delete $VAR_NAME --org $ORG -# Confirm organization variable exists +# Verify new organization variable exists exec gh variable list --org $ORG -stdout $ORG_VARIABLE_NAME +stdout $VAR_NAME -# Verify repository environment variable can be retrieved -exec gh variable get $ORG_VARIABLE_NAME --org $ORG +# Verify organization variable can be retrieved +exec gh variable get $VAR_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 index f4b11c3dd..99dbb6b9f 100644 --- a/acceptance/testdata/variable/variable-repo-env.txtar +++ b/acceptance/testdata/variable/variable-repo-env.txtar @@ -1,6 +1,7 @@ -# Force GitHub CLI to treat testscript as TTY -env GH_FORCE_TTY=80 -env REPO=$SCRIPT_NAME-$RANDOM_STRING +# Setup environment variables used for testscript +env REPO=${SCRIPT_NAME}-${RANDOM_STRING} +env ENV_NAME=testscripts +env VAR_NAME=TESTSCRIPTS_ENV # Create a repository where the variable will be registered exec gh repo create $ORG/$REPO --add-readme --private @@ -13,21 +14,19 @@ 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' +exec gh api /repos/$ORG/$REPO/environments/$ENV_NAME -X PUT --jq '.name' -# Verify no repository environment variables exist -exec gh variable list --env testscripts -stderr 'no variables found' +# Verify repository environment variable does not exist +exec gh variable list --env $ENV_NAME +! stdout $VAR_NAME # 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' +exec gh variable set $VAR_NAME --env $ENV_NAME --body 'just a repo env variable' # 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' +exec gh variable list --env $ENV_NAME +stdout $VAR_NAME # Verify repository environment variable can be retrieved -exec gh variable get TESTSCRIPTS_ENV --env testscripts +exec gh variable get $VAR_NAME --env $ENV_NAME stdout 'just a repo env variable' diff --git a/acceptance/testdata/variable/variable-repo.txtar b/acceptance/testdata/variable/variable-repo.txtar index f6295b566..9ff64db0f 100644 --- a/acceptance/testdata/variable/variable-repo.txtar +++ b/acceptance/testdata/variable/variable-repo.txtar @@ -1,6 +1,6 @@ -# Setup environment variables to force TTY -env GH_FORCE_TTY=80 -env REPO=$SCRIPT_NAME-$RANDOM_STRING +# Setup environment variables used for testscript +env REPO=${SCRIPT_NAME}-${RANDOM_STRING} +env VAR_NAME=TESTSCRIPTS # Create a repository where the variable will be registered exec gh repo create $ORG/$REPO --add-readme --private @@ -12,18 +12,17 @@ defer gh repo delete --yes $ORG/$REPO exec gh repo clone $ORG/$REPO cd $REPO -# Verify no repository variables exist +# Verify repository variable does not exist exec gh variable list -stderr 'no variables found' +! stdout $VAR_NAME # Create a repository variable -exec gh variable set TESTSCRIPTS --body 'just a repo variable' -stdout 'Created variable TESTSCRIPTS for' +exec gh variable set $VAR_NAME --body 'just a repo variable' # Verify new repository variable exists exec gh variable list -stdout 'TESTSCRIPTS\s+just a repo variable\s+less than a minute ago' +stdout $VAR_NAME # Verify repository variable can be retrieved -exec gh variable get TESTSCRIPTS +exec gh variable get $VAR_NAME stdout 'just a repo variable'