Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
20 changes: 20 additions & 0 deletions acceptance/testdata/variable/variable-org.txtar
Original file line number Diff line number Diff line change
@@ -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'
32 changes: 32 additions & 0 deletions acceptance/testdata/variable/variable-repo-env.txtar
Original file line number Diff line number Diff line change
@@ -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'
28 changes: 28 additions & 0 deletions acceptance/testdata/variable/variable-repo.txtar
Original file line number Diff line number Diff line change
@@ -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'