Skip to content

Commit

Permalink
test: use node to shorten
Browse files Browse the repository at this point in the history
  • Loading branch information
tpluscode committed Nov 28, 2023
1 parent 480ffff commit bf619aa
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 30 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 20
- run: npm ci
- run: bash ./test/profiles.sh
37 changes: 7 additions & 30 deletions test/profiles.sh
Original file line number Diff line number Diff line change
@@ -1,45 +1,22 @@
#!/usr/bin/env bash

set -x

SCRIPT_PATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
FAILED=0

SHACL_PLAYGROUND_URL="https://shacl-playground.zazuko.com/"
SHORTENER="https://s.zazuko.com/api/v1/shorten/"

function urlencode() {
set +x
local string="${1}"
local strlen=${#string}
local encoded=""
local pos c o

for (( pos=0 ; pos<strlen ; pos++ )); do
c=${string:$pos:1}
case "$c" in
[-_.~a-zA-Z0-9] ) o="${c}" ;;
* ) printf -v o '%%%02x' "'$c"
esac
encoded+="${o}"
done
echo "${encoded}"
}

function getPlaygroundUrl() {
local playgroundUrl="$SHACL_PLAYGROUND_URL#page=2&shapesGraph=$(urlencode "$1")&dataGraph=$(urlencode "$2")&dataGraphFormat=text%2Fturtle"
curl -s $SHORTENER --data-raw "url=$playgroundUrl"
}

function reportFailure() {
playground=$(getPlaygroundUrl "$1" "$2")
playground=$("$SCRIPT_PATH"/shorten-report.js "$1" "$2")
echo "❌ FAIL - check report on $playground"
}

# iterate over valid cases, run validation and monitor exit code
for file in "$SCRIPT_PATH"/*/valid*.ttl; do
echo "Test case $file"
if ! barnard59 cube check-metadata --profile validation/profile-opendataswiss.ttl < "$file" > /dev/null 2>&1; then
{
barnard59 cube check-metadata --profile validation/profile-opendataswiss.ttl > /dev/null 2>&1
success=$?
} < "$file"

if [ $success -ne 0 ] ; then
reportFailure "$(cat validation/profile-opendataswiss.ttl)" "$(cat "$file")"
FAILED=1
fi
Expand Down
27 changes: 27 additions & 0 deletions test/shorten-report.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env node

const SHACL_PLAYGROUND_URL = 'https://shacl-playground.zazuko.com/'
const SHORTENER = 'https://s.zazuko.com/api/v1/shorten/'

;(async function () {
const params = new URLSearchParams({
shapesGraph: process.argv[2],
dataGraph: process.argv[3],
dataGraphFormat: 'text/turtle',
page: 2
})

const playgroundUrl = new URL(SHACL_PLAYGROUND_URL)
playgroundUrl.hash = params.toString()

const response = await fetch(SHORTENER, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: new URLSearchParams({
url: playgroundUrl.toString()
})
})
process.stdout.write(await response.text())
})()

0 comments on commit bf619aa

Please sign in to comment.