Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: add spread tests for registries #5091

Merged
merged 2 commits into from
Oct 4, 2024
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
12 changes: 12 additions & 0 deletions tests/spread/store/registries/editor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#! /bin/bash

registries_file="$1"

# flip-flop between 'access' being read and write
if grep -q "^ *access:.*read" "$registries_file"; then
access="write"
else
access="read"
fi

sed -i "s/^\([[:space:]]*\)access:.*/\1access: $access/g" "$registries_file"
42 changes: 42 additions & 0 deletions tests/spread/store/registries/task.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
summary: test the registries 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
gpg --homedir "$HOME/.snap/gnupg" --import <(echo "$SNAPCRAFT_ASSERTION_KEY" | base64 --decode)

snap install yq
# registries only available in edge
snap refresh snapd --edge

execute: |
# ensure snapcraft is logged in and can access the store
snapcraft whoami

# snapcraft will use a fake file editor
mr-cal marked this conversation as resolved.
Show resolved Hide resolved
export EDITOR="$PWD/editor.sh"

snapcraft edit-registries "$(snapcraft whoami | yq .id)" testset --key-name testspreadkey

snapcraft list-registries | MATCH testset

restore: |
rm -rf "$HOME/.snap/gnupg"

snap remove --purge yq
snap refresh snapd --stable
4 changes: 1 addition & 3 deletions tests/spread/store/validation-sets/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ prepare: |
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
gpg --homedir "$HOME/.snap/gnupg" --import <(echo "$SNAPCRAFT_ASSERTION_KEY" | base64 --decode)
snap install yq
Expand Down
Loading