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

CLI Tests: Deploy all Python Content Types #816

Closed
wants to merge 21 commits into from
Closed
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
11 changes: 10 additions & 1 deletion .github/workflows/contract.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,20 @@ jobs:
with:
name: bin
path: bin
- uses: actions/checkout@v4
with:
repository: rstudio/connect-content
ref: 'kg-add-python-apis'
path: 'test'
sparse-checkout: bundles
sparse-checkout-cone-mode: false
token: ${{ secrets.CONNECT_PAT }}
- run: chmod -R +x ./bin
- run: echo "${FUZZBUCKET_SSH_KEY}" > test/cy/fuzzbucket-ssh-key && chmod 600 test/cy/fuzzbucket-ssh-key
- run: just cy install
- run: just cy test
- run: just cy test-contract
# disable cypress contract tests until new deploy workflow
# - run: just cy test-contract
- run: just bats install
- run: just bats test
- run: just bats test-contract
Expand Down
22 changes: 22 additions & 0 deletions test/bats/contract/accounts.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bats

load '../node_modules/bats-support/load'
load '../node_modules/bats-assert/load'

# list-accounts should return the account from env
@test "list accounts" {
run ${EXE} list-accounts
assert_success
assert_output --partial "Nickname: \"env\""
assert_output --partial "Configured via: CONNECT_SERVER environment variable"
assert_output --partial "Authentication: Connect API key"
}

# test-account should pass with env
@test "test accounts" {
run ${EXE} test-account env
assert_success
assert_output --partial "Name: Administrator Smith"
assert_output --partial "Username: admin"
assert_output --partial "Email: [email protected]"
}
41 changes: 18 additions & 23 deletions test/bats/contract/deploy.bats
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,19 @@

load '../node_modules/bats-support/load'
load '../node_modules/bats-assert/load'
source ../bundles/${CONTENT}/test/.publisher-env
CONTENT_PATH='../bundles/'

# list-accounts should return the account from env
@test "list accounts" {
run ${EXE} list-accounts
assert_success
assert_output --partial "Nickname: \"env\""
assert_output --partial "Configured via: CONNECT_SERVER environment variable"
assert_output --partial "Authentication: Connect API key"
}
# these python apis cannot be detected by publisher
# known issue #794

# test-account should pass with env
@test "test accounts" {
run ${EXE} test-account env
assert_success
assert_output --partial "Name: Administrator Smith"
assert_output --partial "Username: admin"
assert_output --partial "Email: [email protected]"
}

# deploy content with the env account
@test "deploy content" {
run ${EXE} deploy ../sample-content/fastapi-simple/ -n ci_deploy
@test "deploy ${CONTENT}" {
if [[ ${CONTENT} == *"quart"* || ${CONTENT} == *"pycnic"* || ${CONTENT} == *"bottle"* ]]; then
skip "${CONTENT} can't be detected - #794"
fi
run ${EXE} deploy ${CONTENT_PATH}/${CONTENT} -n ci_deploy
assert_success
assert_output --partial "Test Deployment... [OK]"
# now test the deployment via api
Expand All @@ -33,12 +24,15 @@ load '../node_modules/bats-assert/load'
run curl --silent --show-error -L --max-redirs 0 --fail \
-X GET \
-H "Authorization: Key ${CONNECT_API_KEY}" "${CONNECT_SERVER}/__api__/v1/content/${GUID}"
assert_output --partial "\"app_mode\":\"python-fastapi\""
assert_output --partial "\"app_mode\":\"${CONTENT_TYPE}\""
}

# redeploy content from previous test
@test "redeploy content" {
run ${EXE} redeploy ci_deploy ../sample-content/fastapi-simple/
@test "redeploy ${CONTENT}" {
if [[ ${CONTENT} == *"quart"* || ${CONTENT} == *"pycnic"* || ${CONTENT} == *"bottle"* ]]; then
skip "${CONTENT} can't be detected - #794"
fi
run ${EXE} redeploy ci_deploy ${CONTENT_PATH}${CONTENT}
assert_success
assert_output --partial "Test Deployment... [OK]"
# now test the deployment via api
Expand All @@ -48,6 +42,7 @@ load '../node_modules/bats-assert/load'
run curl --silent --show-error -L --max-redirs 0 --fail \
-X GET \
-H "Authorization: Key ${CONNECT_API_KEY}" "${CONNECT_SERVER}/__api__/v1/content/${GUID}"
assert_output --partial "\"app_mode\":\"python-fastapi\""
assert_output --partial "\"app_mode\":\"${CONTENT_TYPE}\""
# cleanup
run rm -rf ${CONTENT_PATH}${CONTENT}/.posit/ ${CONTENT_PATH}${CONTENT}/.positignore
}

27 changes: 23 additions & 4 deletions test/bats/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ alias c := clean
alias i := install
alias t := test

export CONTENT := env_var_or_default("CONTENT", "all")
export CONTENT_REPO := env_var_or_default("CONTENT_REPO", "/work/connect-content")

_ci := env_var_or_default("CI", "false")

_debug := env_var_or_default("DEBUG", "false")
Expand Down Expand Up @@ -47,22 +50,38 @@ run *args:


# Executes bats deploy tests
# Content being tested lives in the connect-content githu repo
test-contract:
#!/usr/bin/env bash
set -eou pipefail
{{ _with_debug }}

exe=$(just ../../executable-path)

export CONNECT_SERVER="$(python ../setup/connect_setup.py)"
export CONNECT_API_KEY="$(python ../setup/gen_apikey.py 'admin')"

if [ ! -f $exe ]; then
echo "error: Missing executable $exe. Run \`just build\`." 1>&2
exit 1
fi
pip install -r ../setup/requirements.txt
export CONNECT_SERVER="$(python ../setup/connect_setup.py)"
export CONNECT_API_KEY="$(python ../setup/gen_apikey.py 'admin')"

EXE=$exe npm run contract
EXE=$exe npm run accounts
if [[ "${CONTENT}" == "all" ]]; then
cp -R "${HOME}${CONTENT_REPO}/bundles" ../
content_list=$(python ../deploy_helper.py "${HOME}${CONTENT_REPO}/bundles")
for i in ${content_list}
do
# only test when we have a .publisher-env file for the content
if [[ -f ../bundles/${i}/test/.publisher-env ]]; then
export CONTENT=${i}
EXE=$exe npm run deploy
fi
done
rm -rf ../bundles
else
EXE=$exe npm run deploy
fi

# Executes bats local tests
test:
Expand Down
3 changes: 2 additions & 1 deletion test/bats/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"private": true,
"scripts": {
"contract": "bats -r -T -t ./contract",
"deploy": "bats -r -T -t ./contract/deploy.bats",
"accounts": "bats -r -T -t ./contract/accounts.bats",
"cli": "bats -r -T -t ./cli"
},
"devDependencies": {
Expand Down
12 changes: 12 additions & 0 deletions test/deploy_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os
import sys

# Specify the directory path
directory_path = sys.argv[1]

# Get a list of directories
subdirectories = [d for d in os.listdir(directory_path)
if os.path.isdir(os.path.join(directory_path, d))]

# Print the list of directories
print(str(subdirectories).replace("[","").replace("]","").replace("'","").replace(",",""))
3 changes: 3 additions & 0 deletions test/setup/connect_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def get_ip(box_name):
def connect_ready(box_name, max_attempts, interval):
connect_box=get_ip(box_name)
update_config="fuzzbucket-client ssh " + box_name + " " + ssh_options + " sudo sed -i 's/CONNECT_IP/" + connect_box + "/g' /etc/rstudio-connect/rstudio-connect.gcfg"
restart_connect = "fuzzbucket-client ssh " + box_name + " " + ssh_options + " sudo systemctl restart rstudio-connect"
attempts = 0
while attempts < max_attempts:
try:
Expand All @@ -68,6 +69,7 @@ def connect_ready(box_name, max_attempts, interval):
logging.info("Installing Connect on " + connect_box)
subprocess.check_output(install_connect, shell=True, text=True)
subprocess.check_output(update_config, shell=True, text=True)
subprocess.check_output(restart_connect, shell=True, text=True)
return response.text
except requests.RequestException:
pass
Expand All @@ -79,6 +81,7 @@ def connect_ready(box_name, max_attempts, interval):
api_key=get_api_key('admin')
connect_version=get_connect_version()
install_connect = "fuzzbucket-client ssh " + box_name + " " + ssh_options + " sudo -E UNATTENDED=1 bash installer-ci.sh -d " + connect_version

response = connect_ready(box_name, 20, 5)

if response:
Expand Down
Loading