refactor: перемещены все тестовые скрипты в scripts/
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
#!/bin/bash
|
||||
# Тест всех линтеров /console/api/ai/check
|
||||
API="https://fission.kube5s.ru/console/api/ai/check"
|
||||
PASS=0; FAIL=0
|
||||
|
||||
chk() {
|
||||
local id="$1" lang="$2" expect="$3"
|
||||
local code="$4"
|
||||
local escaped
|
||||
escaped=$(printf '%s' "$code" | python3 -c "import sys,json; print(json.dumps(sys.stdin.read()))")
|
||||
local resp
|
||||
resp=$(curl -s -X POST "$API" \
|
||||
-H "X-Test-Sub: livetest@test.local" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"language\":\"${lang}\",\"code\":${escaped}}")
|
||||
local ok_val result_val
|
||||
ok_val=$(python3 -c "import sys,json; d=json.loads('$resp'.replace(\"'\",\"'\")); print(d.get('ok','?'))" 2>/dev/null) || \
|
||||
ok_val=$(echo "$resp" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('ok','?'))")
|
||||
result_val=$(echo "$resp" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('result','')[:100])" 2>/dev/null)
|
||||
local status
|
||||
if [[ "$expect" == "ok" && "$ok_val" == "True" ]]; then status="PASS"; ((PASS++))
|
||||
elif [[ "$expect" == "fail" && "$ok_val" == "False" ]]; then status="PASS"; ((PASS++))
|
||||
else status="FAIL"; ((FAIL++)); fi
|
||||
echo "[$status] $id | $lang | exp=$expect got=$ok_val | $result_val"
|
||||
}
|
||||
|
||||
echo "=== NODEJS ==="
|
||||
chk N01 nodejs ok 'module.exports = async function(ctx) { return { status: 200, body: "ok" }; };'
|
||||
chk N02 nodejs ok 'module.exports = (ctx) => ({ status: 200 });'
|
||||
chk N03 nodejs fail 'module.exports = function(ctx) { const x = @@@; };'
|
||||
chk N04 nodejs fail 'module.exports = function(ctx) {'
|
||||
chk N05 nodejs fail 'const x = {a: 1,, b: 2};'
|
||||
chk N06 nodejs fail 'function foo( { return 1; }'
|
||||
|
||||
echo ""
|
||||
echo "=== PYTHON ==="
|
||||
chk P01 python ok $'def main(ctx, ev):\n return {"status": 200}'
|
||||
chk P02 python ok $'def main(data):\n x = data.get("name", "World")\n return "Hello " + x'
|
||||
chk P03 python fail $'def main(data):\nreturn 1'
|
||||
chk P04 python fail $'def main(data):\n x = @@@'
|
||||
chk P05 python fail $'def main(data)\n return 1'
|
||||
chk P06 python fail $'import os\ndef main(\n return 1'
|
||||
|
||||
echo ""
|
||||
echo "=== RUBY ==="
|
||||
chk R01 ruby ok $'def handler(ctx)\n { status: 200, body: "ok" }\nend'
|
||||
chk R02 ruby ok $'def handler(context)\n name = context[:name] || "World"\n "Hello #{name}"\nend'
|
||||
chk R03 ruby fail $'def handler(ctx\n { status: 200 }\nend'
|
||||
chk R04 ruby fail $'def handler(ctx)\n { status: 200 body: "x" }\nend'
|
||||
chk R05 ruby fail $'class Foo\n def bar(\nend'
|
||||
|
||||
echo ""
|
||||
echo "=== PHP ==="
|
||||
chk H01 php ok $'<?php\nfunction handler(array $ctx): array { return ["status" => 200]; }'
|
||||
chk H02 php ok $'<?php\nfunction handler(array $ctx): array {\n $name = $ctx["name"] ?? "World";\n return ["status" => 200, "body" => "Hello $name"];\n}'
|
||||
chk H03 php fail $'<?php\nfunction handler(array $ctx): array {\n $name = $ctx["name"] ?? "World"\n return ["status" => 200];\n}'
|
||||
chk H04 php fail $'<?php\n$x = @@@;'
|
||||
chk H05 php fail $'<?php\nfunction foo( { return 1; }'
|
||||
|
||||
echo ""
|
||||
echo "=== GO ==="
|
||||
chk G01 go ok $'package main\nimport "net/http"\nfunc Handler(w http.ResponseWriter, r *http.Request) {}'
|
||||
chk G02 go ok $'package main\nimport (\n "net/http"\n "fmt"\n)\nfunc Handler(w http.ResponseWriter, r *http.Request) {\n fmt.Fprintf(w, "ok")\n}'
|
||||
chk G03 go fail $'package main\nfunc Handler( {'
|
||||
chk G04 go fail $'package main\nimport (\n "net/http"\nfunc Handler(w http.ResponseWriter) {}'
|
||||
chk G05 go fail $'package main\nfunc Handler(w http.ResponseWriter, r *http.Request) {\n x := @@@\n}'
|
||||
|
||||
echo ""
|
||||
echo "=== ГРАНИЧНЫЕ ==="
|
||||
chk E01 nodejs fail ''
|
||||
chk E02 python fail 'asd @@@'
|
||||
chk E03 ruby fail 'def foo(;;; end'
|
||||
chk E04 php fail '<?php echo @@@'
|
||||
|
||||
echo ""
|
||||
echo "========================"
|
||||
echo "PASS=$PASS FAIL=$FAIL"
|
||||
echo "========================"
|
||||
Reference in New Issue
Block a user