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.
This commit is contained in:
Andy Feller 2024-10-21 16:02:26 -04:00
parent fa03013a23
commit 6192ac74df
3 changed files with 30 additions and 32 deletions

View file

@ -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'

View file

@ -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'

View file

@ -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'