Merge pull request #9783 from cli/jtmcg/testscripts-repo
Add acceptance tests for `repo` commands
This commit is contained in:
commit
92ff87c6b7
10 changed files with 186 additions and 0 deletions
|
|
@ -72,6 +72,14 @@ func TestReleases(t *testing.T) {
|
|||
testscript.Run(t, testScriptParamsFor(tsEnv, "release"))
|
||||
}
|
||||
|
||||
func TestRepo(t *testing.T) {
|
||||
var tsEnv testScriptEnv
|
||||
if err := tsEnv.fromEnv(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
testscript.Run(t, testScriptParamsFor(tsEnv, "repo"))
|
||||
}
|
||||
|
||||
func testScriptParamsFor(tsEnv testScriptEnv, command string) testscript.Params {
|
||||
var files []string
|
||||
if tsEnv.script != "" {
|
||||
|
|
|
|||
23
acceptance/testdata/repo/repo-archive-unarchive.txtar
vendored
Normal file
23
acceptance/testdata/repo/repo-archive-unarchive.txtar
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# Create a repository with a file so it has a default branch
|
||||
exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --add-readme --private
|
||||
|
||||
# Defer repo cleanup
|
||||
defer gh repo delete --yes $ORG/$SCRIPT_NAME-$RANDOM_STRING
|
||||
|
||||
# Check that the repo exists and isn't archived
|
||||
exec gh repo view $ORG/$SCRIPT_NAME-$RANDOM_STRING --json=isArchived --jq='.isArchived'
|
||||
stdout 'false'
|
||||
|
||||
# Archive the repo
|
||||
exec gh repo archive $ORG/$SCRIPT_NAME-$RANDOM_STRING --yes
|
||||
|
||||
# Check that the repo is archived
|
||||
exec gh repo view $ORG/$SCRIPT_NAME-$RANDOM_STRING --json=isArchived --jq='.isArchived'
|
||||
stdout 'true'
|
||||
|
||||
# Unarchive the repo
|
||||
exec gh repo unarchive $ORG/$SCRIPT_NAME-$RANDOM_STRING --yes
|
||||
|
||||
# Check that the repo is unarchived
|
||||
exec gh repo view $ORG/$SCRIPT_NAME-$RANDOM_STRING --json=isArchived --jq='.isArchived'
|
||||
stdout 'false'
|
||||
11
acceptance/testdata/repo/repo-clone.txtar
vendored
Normal file
11
acceptance/testdata/repo/repo-clone.txtar
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# Create a repository with a file so it has a default branch
|
||||
exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --add-readme --private
|
||||
|
||||
# Defer repo cleanup
|
||||
defer gh repo delete --yes $ORG/$SCRIPT_NAME-$RANDOM_STRING
|
||||
|
||||
# Clone the repo
|
||||
exec gh repo clone $ORG/$SCRIPT_NAME-$RANDOM_STRING
|
||||
|
||||
# Ensure the repo was cloned
|
||||
exists $SCRIPT_NAME-$RANDOM_STRING/README.md
|
||||
9
acceptance/testdata/repo/repo-create-view.txtar
vendored
Normal file
9
acceptance/testdata/repo/repo-create-view.txtar
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# Create a repository with a file so it has a default branch
|
||||
exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --add-readme --private
|
||||
|
||||
# Defer repo cleanup
|
||||
defer gh repo delete --yes $ORG/$SCRIPT_NAME-$RANDOM_STRING
|
||||
|
||||
# Check that the repo exists
|
||||
exec gh repo view $ORG/$SCRIPT_NAME-$RANDOM_STRING --json=name --jq='.name'
|
||||
stdout $SCRIPT_NAME-$RANDOM_STRING
|
||||
13
acceptance/testdata/repo/repo-delete.txtar
vendored
Normal file
13
acceptance/testdata/repo/repo-delete.txtar
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# Create a repository with a file so it has a default branch
|
||||
exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --add-readme --private
|
||||
|
||||
# Check that the repo exists
|
||||
exec gh repo view $ORG/$SCRIPT_NAME-$RANDOM_STRING --json name --jq '.name'
|
||||
stdout $SCRIPT_NAME-$RANDOM_STRING
|
||||
|
||||
# Delete the repo
|
||||
exec gh repo delete --yes $ORG/$SCRIPT_NAME-$RANDOM_STRING
|
||||
|
||||
# Ensure that the repo was deleted
|
||||
! exec gh repo view $ORG/$SCRIPT_NAME-$RANDOM_STRING
|
||||
stderr 'Could not resolve to a Repository with the name'
|
||||
31
acceptance/testdata/repo/repo-deploy-key.txtar
vendored
Normal file
31
acceptance/testdata/repo/repo-deploy-key.txtar
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# Create and clone a repository with a file so it has a default branch
|
||||
exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --add-readme --private --clone
|
||||
|
||||
# Defer repo cleanup
|
||||
defer gh repo delete --yes $ORG/$SCRIPT_NAME-$RANDOM_STRING
|
||||
|
||||
# cd to the repo and list the deploy keys. There should be no keys
|
||||
cd $SCRIPT_NAME-$RANDOM_STRING
|
||||
exec gh repo deploy-key list --json=title
|
||||
! stdout title
|
||||
|
||||
# Add a deploy key
|
||||
exec gh repo deploy-key add ../deployKey.pub
|
||||
|
||||
# Ensure the deploy key was added
|
||||
exec gh repo deploy-key list --json=title --jq='.[].title'
|
||||
stdout myTitle
|
||||
|
||||
# Get the deploy key id
|
||||
exec gh repo deploy-key list --json=title,id --jq='.[].title="myTitle" | .[].id'
|
||||
stdout2env DEPLOY_KEY_ID
|
||||
|
||||
# Delete the deploy key
|
||||
exec gh repo deploy-key delete $DEPLOY_KEY_ID
|
||||
|
||||
# Ensure the deploy key was deleted
|
||||
exec gh repo deploy-key list --json=id --jq='.[].id'
|
||||
! stdout $DEPLOY_KEY_ID
|
||||
|
||||
-- deployKey.pub --
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAZmdeRNskfpvYL5YHB/YJaW8hTEXpnvPMkx5Ri+YwUr myTitle
|
||||
16
acceptance/testdata/repo/repo-edit.txtar
vendored
Normal file
16
acceptance/testdata/repo/repo-edit.txtar
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# Create a repository with a file so it has a default branch
|
||||
exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --add-readme --private
|
||||
|
||||
# Defer repo cleanup
|
||||
defer gh repo delete --yes $ORG/$SCRIPT_NAME-$RANDOM_STRING
|
||||
|
||||
# Check that the repo description is empty
|
||||
exec gh repo view $ORG/$SCRIPT_NAME-$RANDOM_STRING --json description --jq '.description'
|
||||
! stdout '.'
|
||||
|
||||
# Edit the repo description
|
||||
exec gh repo edit $ORG/$SCRIPT_NAME-$RANDOM_STRING --description 'newDescription'
|
||||
|
||||
# Check that the repo description is updated
|
||||
exec gh repo view $ORG/$SCRIPT_NAME-$RANDOM_STRING --json description --jq '.description'
|
||||
stdout 'newDescription'
|
||||
42
acceptance/testdata/repo/repo-fork-sync.txtar
vendored
Normal file
42
acceptance/testdata/repo/repo-fork-sync.txtar
vendored
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
# Use gh as a credential helper
|
||||
exec gh auth setup-git
|
||||
|
||||
# Create and clone a repository with a file so it has a default branch
|
||||
exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --add-readme --private --clone
|
||||
|
||||
# Defer repo cleanup
|
||||
defer gh repo delete --yes $ORG/$SCRIPT_NAME-$RANDOM_STRING
|
||||
|
||||
# Fork and clone the repo
|
||||
exec gh repo fork $ORG/$SCRIPT_NAME-$RANDOM_STRING --org $ORG --fork-name $SCRIPT_NAME-$RANDOM_STRING-fork --clone
|
||||
|
||||
# Defer fork cleanup
|
||||
defer gh repo delete $ORG/$SCRIPT_NAME-$RANDOM_STRING-fork --yes
|
||||
|
||||
# Sleep so that the BE has time to sync
|
||||
sleep 5
|
||||
|
||||
# Check that the repo was forked
|
||||
exec gh repo view $ORG/$SCRIPT_NAME-$RANDOM_STRING-fork --json='isFork' --jq='.isFork'
|
||||
stdout 'true'
|
||||
|
||||
# Modify original repo
|
||||
cd $SCRIPT_NAME-$RANDOM_STRING
|
||||
mv ../asset.txt asset.txt
|
||||
exec git add .
|
||||
exec git commit -m 'Add asset.txt'
|
||||
exec git push
|
||||
|
||||
# Checkout the forked repo and ensure asset.txt is not present
|
||||
cd ../$SCRIPT_NAME-$RANDOM_STRING-fork
|
||||
exec git checkout main
|
||||
! exists asset.txt
|
||||
|
||||
# Sync the forked repo with the original repo
|
||||
exec gh repo sync
|
||||
|
||||
# Check that asset.txt now exists in the fork
|
||||
exists asset.txt
|
||||
|
||||
-- asset.txt --
|
||||
Hello, world!
|
||||
16
acceptance/testdata/repo/repo-list-rename.txtar
vendored
Normal file
16
acceptance/testdata/repo/repo-list-rename.txtar
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# Create a repository with a file so it has a default branch
|
||||
exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --add-readme --private
|
||||
|
||||
# List the repos and check for the new repo
|
||||
exec gh repo list $ORG --json=name --jq='.[].name'
|
||||
stdout $SCRIPT_NAME-$RANDOM_STRING
|
||||
|
||||
# Rename the repo
|
||||
exec gh repo rename $SCRIPT_NAME-$RANDOM_STRING-renamed --repo=$ORG/$SCRIPT_NAME-$RANDOM_STRING --yes
|
||||
|
||||
# Defer repo deletion
|
||||
defer gh repo delete $ORG/$SCRIPT_NAME-$RANDOM_STRING-renamed --yes
|
||||
|
||||
# List the repos and check for the renamed repo
|
||||
exec gh repo list $ORG --json=name --jq='.[].name'
|
||||
stdout $SCRIPT_NAME-$RANDOM_STRING-renamed
|
||||
17
acceptance/testdata/repo/repo-set-default.txtar
vendored
Normal file
17
acceptance/testdata/repo/repo-set-default.txtar
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# Create and clone a repository with a file so it has a default branch
|
||||
exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --add-readme --private --clone
|
||||
|
||||
# Defer repo cleanup
|
||||
defer gh repo delete --yes $ORG/$SCRIPT_NAME-$RANDOM_STRING
|
||||
|
||||
# Ensure that no default is set
|
||||
cd $SCRIPT_NAME-$RANDOM_STRING
|
||||
exec gh repo set-default --view
|
||||
stderr 'no default repository has been set; use `gh repo set-default` to select one'
|
||||
|
||||
# Set the default
|
||||
exec gh repo set-default $ORG/$SCRIPT_NAME-$RANDOM_STRING
|
||||
|
||||
# Check that the default is set
|
||||
exec gh repo set-default --view
|
||||
stdout $ORG/$SCRIPT_NAME-$RANDOM_STRING
|
||||
Loading…
Add table
Add a link
Reference in a new issue