Merge pull request #9784 from cli/andyfeller/testscripts-variable

Add acceptance tests for `variable` commands
This commit is contained in:
Andy Feller 2024-10-22 10:04:21 -04:00 committed by GitHub
commit 34f1b50acc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 89 additions and 0 deletions

View file

@ -99,6 +99,15 @@ func TestSecrets(t *testing.T) {
testscript.Run(t, testScriptParamsFor(tsEnv, "secret"))
}
func TestVariables(t *testing.T) {
var tsEnv testScriptEnv
if err := tsEnv.fromEnv(); err != nil {
t.Fatal(err)
}
testscript.Run(t, testScriptParamsFor(tsEnv, "variable"))
}
func testScriptParamsFor(tsEnv testScriptEnv, command string) testscript.Params {
var files []string
if tsEnv.script != "" {

View file

@ -0,0 +1,20 @@
# 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 list --org $ORG
! stdout $VAR_NAME
# Create an organization variable
exec gh variable set $VAR_NAME --org $ORG --body 'just an org variable'
# Defer organization variable cleanup
defer gh variable delete $VAR_NAME --org $ORG
# Verify new organization variable exists
exec gh variable list --org $ORG
stdout $VAR_NAME
# Verify organization variable can be retrieved
exec gh variable get $VAR_NAME --org $ORG
stdout 'just an org variable'

View file

@ -0,0 +1,32 @@
# 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
# 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/$ENV_NAME -X PUT --jq '.name'
# 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 $VAR_NAME --env $ENV_NAME --body 'just a repo env variable'
# Verify new repository environment variable exists
exec gh variable list --env $ENV_NAME
stdout $VAR_NAME
# Verify repository environment variable can be retrieved
exec gh variable get $VAR_NAME --env $ENV_NAME
stdout 'just a repo env variable'

View file

@ -0,0 +1,28 @@
# 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
# Defer repo cleanup
defer gh repo delete --yes $ORG/$REPO
# Clone the repo
exec gh repo clone $ORG/$REPO
cd $REPO
# Verify repository variable does not exist
exec gh variable list
! stdout $VAR_NAME
# Create a repository variable
exec gh variable set $VAR_NAME --body 'just a repo variable'
# Verify new repository variable exists
exec gh variable list
stdout $VAR_NAME
# Verify repository variable can be retrieved
exec gh variable get $VAR_NAME
stdout 'just a repo variable'