Skip to content

Commit

Permalink
tests: add spread tests for validation-sets (#4924)
Browse files Browse the repository at this point in the history
Adds a spread test for `edit-validation-sets` and
`list-validation-sets`.

Signed-off-by: Callahan Kovacs <[email protected]>
Co-authored-by: Alex Lowe <[email protected]>
  • Loading branch information
mr-cal and lengau authored Jul 25, 2024
1 parent 6a38887 commit 4ee3c14
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 8 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/spread.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ jobs:
name: Run spread
env:
SPREAD_GOOGLE_KEY: ${{ secrets.SPREAD_GOOGLE_KEY }}
SNAPCRAFT_ASSERTION_KEY: "${{ secrets.SNAPCRAFT_ASSERTION_KEY }}"
SNAPCRAFT_STORE_CREDENTIALS_STAGING: "${{ secrets.SNAPCRAFT_STORE_CREDENTIALS_STAGING }}"
SNAPCRAFT_STORE_CREDENTIALS_STAGING_CANDID: "${{ secrets.SNAPCRAFT_STORE_CREDENTIALS_STAGING_CANDID }}"
SNAPCRAFT_STORE_CREDENTIALS_STAGING_LEGACY: "${{ secrets.SNAPCRAFT_STORE_CREDENTIALS_STAGING_LEGACY }}"
run: spread google:ubuntu-22.04-64:tests/spread/general/store
run: |
spread google:ubuntu-22.04-64:tests/spread/store/
- name: Discard spread workers
if: always()
Expand Down
9 changes: 9 additions & 0 deletions spread.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,15 @@ suites:
sudo apt-get install git
sudo apt-mark auto git
tests/spread/store/:
summary: tests of store-related snapcraft commands
manual: true
environment:
STORE_DASHBOARD_URL: https://dashboard.staging.snapcraft.io
STORE_API_URL: https://api.staging.snapcraft.io
STORE_UPLOAD_URL: https://storage.staging.snapcraftcontent.com
UBUNTU_ONE_SSO_URL: https://login.staging.ubuntu.com

docs/howto/code/:
summary: tests how-to guides from the docs
systems:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
summary: Test the store workflow

manual: true
summary: Test the store workflow to register, upload, and release a snap

environment:
# use a core22 snap with components but no component hooks
Expand All @@ -9,10 +7,6 @@ environment:
SNAPCRAFT_STORE_CREDENTIALS/ubuntu_one: "$(HOST: echo ${SNAPCRAFT_STORE_CREDENTIALS_STAGING})"
SNAPCRAFT_STORE_CREDENTIALS/legacy: "$(HOST: echo ${SNAPCRAFT_STORE_CREDENTIALS_STAGING_LEGACY})"
SNAPCRAFT_STORE_CREDENTIALS/candid: "$(HOST: echo ${SNAPCRAFT_STORE_CREDENTIALS_STAGING_CANDID})"
STORE_DASHBOARD_URL: https://dashboard.staging.snapcraft.io
STORE_API_URL: https://api.staging.snapcraft.io
STORE_UPLOAD_URL: https://storage.staging.snapcraftcontent.com
UBUNTU_ONE_SSO_URL: https://login.staging.ubuntu.com

prepare: |
if [[ -z "$SNAPCRAFT_STORE_CREDENTIALS" ]]; then
Expand Down
12 changes: 12 additions & 0 deletions tests/spread/store/validation-sets/editor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#! /bin/bash

validation_set_file="$1"

# flip-flop between two valid revisions of `test-snapcraft-assertions` in the staging store: 1 and 2
if grep -q "^ revision:.*1" "$validation_set_file"; then
(( revision=2 ))
else
(( revision=1 ))
fi

sed -i "s/ revision:.*/ revision: $revision/g" "$validation_set_file"
41 changes: 41 additions & 0 deletions tests/spread/store/validation-sets/task.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
summary: test the validation-set commands

environment:
SNAPCRAFT_ASSERTION_KEY: "$(HOST: echo ${SNAPCRAFT_ASSERTION_KEY})"
SNAPCRAFT_STORE_CREDENTIALS: "$(HOST: echo ${SNAPCRAFT_STORE_CREDENTIALS_STAGING})"

prepare: |
if [[ -z "$SNAPCRAFT_STORE_CREDENTIALS" ]]; then
ERROR "No credentials set in env SNAPCRAFT_STORE_CREDENTIALS"
fi
if [[ -z "$SNAPCRAFT_ASSERTION_KEY" ]]; then
ERROR "No gpg key set in env SNAPCRAFT_ASSERTION_KEY"
fi
# setup snap gpg dir
mkdir -p "$HOME/.snap/gnupg"
chmod 700 "$HOME/.snap/gnupg"
# import a registered key
echo "$SNAPCRAFT_ASSERTION_KEY" | base64 --decode > store-key.txt
gpg --homedir "$HOME/.snap/gnupg" --import store-key.txt
rm -f store-key.txt
snap install yq
execute: |
# ensure snapcraft is logged in and can access the store
snapcraft whoami
# snapcraft will use a fake file editor
export EDITOR="$PWD/editor.sh"
snapcraft edit-validation-sets "$(snapcraft whoami | yq .id)" testset 1 --key-name testspreadkey
snapcraft list-validation-sets | MATCH testset
restore: |
rm -rf "$HOME/.snap/gnupg"
snap remove --purge yq

0 comments on commit 4ee3c14

Please sign in to comment.