From f27cddcb9279f0d1840b221af476a87a890c7460 Mon Sep 17 00:00:00 2001 From: bagtoad <47394200+BagToad@users.noreply.github.com> Date: Thu, 24 Oct 2024 08:43:40 -0600 Subject: [PATCH 1/2] Add acceptance test for gpg-key --- acceptance/acceptance_test.go | 11 +++++++- acceptance/testdata/gpg-key/gpg-key.txtar | 32 +++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 acceptance/testdata/gpg-key/gpg-key.txtar diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index bdd631703..2d9e8aeb0 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -86,7 +86,7 @@ func TestRepo(t *testing.T) { if err := tsEnv.fromEnv(); err != nil { t.Fatal(err) } - + testscript.Run(t, testScriptParamsFor(tsEnv, "repo")) } @@ -108,6 +108,15 @@ func TestVariables(t *testing.T) { testscript.Run(t, testScriptParamsFor(tsEnv, "variable")) } +func TestGPGKeys(t *testing.T) { + var tsEnv testScriptEnv + if err := tsEnv.fromEnv(); err != nil { + t.Fatal(err) + } + + testscript.Run(t, testScriptParamsFor(tsEnv, "gpg-key")) +} + func testScriptParamsFor(tsEnv testScriptEnv, command string) testscript.Params { var files []string if tsEnv.script != "" { diff --git a/acceptance/testdata/gpg-key/gpg-key.txtar b/acceptance/testdata/gpg-key/gpg-key.txtar new file mode 100644 index 000000000..dff028bab --- /dev/null +++ b/acceptance/testdata/gpg-key/gpg-key.txtar @@ -0,0 +1,32 @@ +skip 'it modifies the user''s personal GitHub account GPG keys' + +# This test requires the admin:gpg_key scope to add and delete GPG keys to and +# from the user's personal GitHub account. +# This test uses a GPG key that generated for this test only. The private key +# has been deleted + +# Add the gpg key to GH account +exec gh gpg-key add gpg-key.pub + +# Defer deleting the gpg key from GH account +defer gh gpg-key delete --yes 24C30F9C9115E747 + +# Verify the gpg key was added to GH account +exec gh gpg-key list +stdout 24C30F9C9115E747 + +-- gpg-key.pub -- +-----BEGIN PGP PUBLIC KEY BLOCK----- + +mDMEZxpWhhYJKwYBBAHaRw8BAQdAmYiobR2ai/lVWOBtlAPRG1ZEMG5Effavpt5w +n+wQ//W0R0dIIENMSSBhY2NlcHRhbmNlIHRlc3QgKGZvciBHSCBDTEkgYWNjZXB0 +YW5jZSB0ZXN0aW5nKSA8Y2xpQGdpdGh1Yi5jb20+iJkEExYKAEEWIQTEAQLLUl1x +MDSmbL0kww+ckRXnRwUCZxpWhgIbAwUJAAFRgAULCQgHAgIiAgYVCgkICwIEFgID +AQIeBwIXgAAKCRAkww+ckRXnRxkuAP9GiFi/etWxRjnkomdTaOU8Ccd6oHspuEzB +PFxOJdYslQD+MXgY5UhM/q2iEVj0tiVsfRzDqB+g2weaF5EpqIwWcQ+4OARnGlaG +EgorBgEEAZdVAQUBAQdA3D1vnVTc9URDQw/oAd1mG/zRX7vF4QrjFqFIt7uMf2gD +AQgHiH4EGBYKACYWIQTEAQLLUl1xMDSmbL0kww+ckRXnRwUCZxpWhgIbDAUJAAFR +gAAKCRAkww+ckRXnRxVuAQCngnR11jh2mob0FN0rPWce2juoJsh5gPB2d7LS4r5P +VwEA6F2FeetcP51EyKyQGTp3GpmZgk0uCGJa1G5uqT+9mgc= +=RLWi +-----END PGP PUBLIC KEY BLOCK----- \ No newline at end of file From 4100992d4004b28c507fe638a5ef3782a9a9d22e Mon Sep 17 00:00:00 2001 From: William Martin Date: Thu, 24 Oct 2024 17:00:54 +0200 Subject: [PATCH 2/2] Add Acceptance test for label command --- acceptance/acceptance_test.go | 9 +++++++++ acceptance/testdata/label/label.txtar | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 acceptance/testdata/label/label.txtar diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index 2d9e8aeb0..70ddbe4dc 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -117,6 +117,15 @@ func TestGPGKeys(t *testing.T) { testscript.Run(t, testScriptParamsFor(tsEnv, "gpg-key")) } +func TestLabels(t *testing.T) { + var tsEnv testScriptEnv + if err := tsEnv.fromEnv(); err != nil { + t.Fatal(err) + } + + testscript.Run(t, testScriptParamsFor(tsEnv, "label")) +} + func testScriptParamsFor(tsEnv testScriptEnv, command string) testscript.Params { var files []string if tsEnv.script != "" { diff --git a/acceptance/testdata/label/label.txtar b/acceptance/testdata/label/label.txtar new file mode 100644 index 000000000..dd72133da --- /dev/null +++ b/acceptance/testdata/label/label.txtar @@ -0,0 +1,25 @@ +# Setup useful env vars +env REPO=${SCRIPT_NAME}-${RANDOM_STRING} + +# Create a repository +exec gh repo create ${ORG}/${REPO} --private + +# Defer repo cleanup +defer gh repo delete --yes ${ORG}/${REPO} + +# Set the GH_REPO env var to reduce redunant flags +env GH_REPO=${ORG}/${REPO} + +# Create a custom label +exec gh label create 'acceptance-test' --description 'First Description' + +# List the labels and check our custom label is there +exec gh label list +stdout 'acceptance-test\tFirst Description' + +# Edit the label +exec gh label edit 'acceptance-test' --description 'Edited Description' + +# List the labels and check our custom label has been updated +exec gh label list +stdout 'acceptance-test\tEdited Description'