提交 07dc8ae4 编写于 作者: M Mislav Marohnić

Streamline Sauce Labs API interactions

Every request now goes through general-purpose `saucelabs-api` command
which, by default, dumps the data in line-based format suitable for
parsing on the command line. If `--raw` is passed, raw JSON is returned
instead.
上级 b3885b4e
......@@ -19,16 +19,35 @@ trap "kill $sauce_pid" INT EXIT
while [ ! -f "$sauce_ready" ]; do sleep .01; done
rm -f "$sauce_ready"
job=$(./script/saucelabs-start "http://localhost:$port/test/test.html")
while true
do
result=$(echo "$job" | ./script/saucelabs-status)
[[ $result == *"\"completed\": true"* ]] && break
job="$(./script/saucelabs-api --raw "js-tests" <<JSON
{ "public": "public",
"build": "$TRAVIS_BUILD_NUMBER",
"tags": ["$TRAVIS_PULL_REQUEST", "$TRAVIS_BRANCH"],
"tunnel-identifier": "$TRAVIS_JOB_NUMBER",
"platforms": [["$SAUCE_PLATFORM", "$SAUCE_BROWSER", "$SAUCE_VERSION"]],
"url": "http://localhost:$port/test/test.html",
"framework": "mocha"
}
JSON
)"
while true; do
result=$(./script/saucelabs-api "js-tests/status" <<<"$job")
grep -q "^completed: true" <<<"$result" && break
sleep 1
echo -n "."
done
echo -n ""
echo "$result" | ./script/saucelabs-result
echo
awk '
/result\.tests:/ { tests+=$(NF) }
/result\.passes:/ { passes+=$(NF) }
/result\.pending:/ { pending+=$(NF) }
/result\.failures:/ { failures+=$(NF) }
/\.url:/ { print $(NF) }
END {
printf "%d passed, %d pending, %d failures\n", passes, pending, failures
if (failures > 0 || tests != passes + pending) exit 1
}
' <<<"$result"
#!/bin/bash
set -e
raw=""
if [ "$1" = "--raw" ]; then
raw="1"
shift 1
fi
endpoint="$1"
curl -fs -X POST "https://saucelabs.com/rest/v1/$SAUCE_USERNAME/${endpoint}" \
-u "$SAUCE_USERNAME:$SAUCE_ACCESS_KEY" \
-H "Content-Type: application/json" -d "@-" | \
{
if [ -n "$raw" ]; then
cat
else
ruby -rjson -e '
dump = lambda do |obj, ns|
case obj
when Array then obj.each_with_index { |v, i| dump.call(v, [ns, i]) }
when Hash then obj.each { |k, v| dump.call(v, [ns, k]) }
else puts "%s: %s" % [ ns.flatten.compact.join("."), obj.to_s ]
end
end
dump.call JSON.parse(STDIN.read), nil
'
fi
}
#!/usr/bin/env ruby
require 'json'
obj = JSON.parse(ARGF.read)
test = obj['js tests'][0]
warn test['url']
warn test['platform']
warn test['result'].inspect
if test['result'] && (test['result']['passes'] + test['result']['pending']) == test['result']['tests']
exit 0
else
exit 1
end
#!/bin/bash
set -e
url="https://saucelabs.com/rest/v1/$SAUCE_USERNAME/js-tests"
auth="$SAUCE_USERNAME:$SAUCE_ACCESS_KEY"
header="Content-Type: application/json"
data=$(cat <<JSON
{
"public": "public",
"build": "$TRAVIS_BUILD_NUMBER",
"tags": ["$TRAVIS_PULL_REQUEST", "$TRAVIS_BRANCH"],
"tunnel-identifier": "$TRAVIS_JOB_NUMBER",
"platforms": [["$SAUCE_PLATFORM", "$SAUCE_BROWSER", "$SAUCE_VERSION"]],
"url": "$1",
"framework": "mocha"
}
JSON
)
curl -fs "$url" -X POST -u "$auth" -H "$header" -d "$data"
#!/bin/bash
set -e
url="https://saucelabs.com/rest/v1/$SAUCE_USERNAME/js-tests/status"
auth="$SAUCE_USERNAME:$SAUCE_ACCESS_KEY"
header="Content-Type: application/json"
curl -fs "$url" -X POST -u "$auth" -H "$header" -d "@-"
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册