From: Paul Gevers Date: Tue, 8 Sep 2020 20:30:04 +0000 (+0200) Subject: Add autopkgtest X-Git-Tag: archive/raspbian/2.0.44-1+rpi1~1^2~18 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=8be2400669f7f7dd0effa6e1cbdd9300b7d74e73;p=siridb-server.git Add autopkgtest --- diff --git a/debian/tests/control b/debian/tests/control new file mode 100644 index 00000000..3fa074bc --- /dev/null +++ b/debian/tests/control @@ -0,0 +1,3 @@ +Tests: http-api +Depends: @, curl +Restrictions: needs-root, isolation-container diff --git a/debian/tests/http-api b/debian/tests/http-api new file mode 100644 index 00000000..3f359c68 --- /dev/null +++ b/debian/tests/http-api @@ -0,0 +1,198 @@ +#!/bin/sh +set -e + +RES=0 + +echo '* fixing /etc/siridb/siridb.conf' +sed --in-place 's/http_api_port = 0/http_api_port = 9020/' /etc/siridb/siridb.conf + +echo '* restarting siridb-server' +service siridb-server restart + +echo '* run queries' +echo ' get-version' +curl --silent --show-error --location --output res.txt \ + --request GET 'http://localhost:9020/get-version' \ + --header 'Content-Type: application/json' \ + --header 'Authorization: Basic c2E6c2lyaQ==' || RES=1 +cat res.txt +echo + +echo ' new-database' +curl --silent --show-error --location --output res.txt \ + --request POST 'http://localhost:9020/new-database' \ + --header 'Content-Type: application/json' \ + --header 'Authorization: Basic c2E6c2lyaQ==' \ + --header 'Content-Type: text/plain' \ + --data-raw '{ + "dbname": "sampledb", + "time_precision": "s", + "buffer_size": 8192, + "duration_num": "1w", + "duration_log": "3d" +}' || RES=1 +cat res.txt +echo +expect='"OK"' +if [ "$(cat res.txt)" != "$expect" ] ; then RES=1 ; echo "FAILED: expected $expect" ; fi + +echo ' new-account' +curl --silent --show-error --location --output res.txt \ + --request POST 'http://localhost:9020/new-account' \ + --header 'Content-Type: application/json' \ + --header 'Authorization: Basic c2E6c2lyaQ==' \ + --header 'Content-Type: text/plain' \ + --data-raw '{ + "account": "bob", + "password": "passwd4bob" +}' || RES=1 +cat res.txt +echo +expect='"OK"' +if [ "$(cat res.txt)" != "$expect" ] ; then RES=1 ; echo "FAILED: expected $expect" ; fi + +echo ' change-password' +curl --silent --show-error --location --output res.txt \ + --request POST 'http://localhost:9020/change-password' \ + --header 'Content-Type: application/json' \ + --header 'Authorization: Basic c2E6c2lyaQ==' \ + --header 'Content-Type: text/plain' \ + --data-raw '{ + "account": "bob", + "password": "pass" +}' || RES=1 +cat res.txt +echo +expect='"OK"' +if [ "$(cat res.txt)" != "$expect" ] ; then RES=1 ; echo "FAILED: expected $expect" ; fi + +echo ' drop-account' +curl --silent --show-error --location --output res.txt \ + --request POST 'http://localhost:9020/drop-account' \ + --header 'Content-Type: application/json' \ + --header 'Authorization: Basic c2E6c2lyaQ==' \ + --header 'Content-Type: text/plain' \ + --data-raw '{ + "account": "bob" +}' || RES=1 +cat res.txt +echo +expect='"OK"' +if [ "$(cat res.txt)" != "$expect" ] ; then RES=1 ; echo "FAILED: expected $expect" ; fi + +echo ' drop-database' +curl --silent --show-error --location --output res.txt \ + --request POST 'http://localhost:9020/drop-database' \ + --header 'Content-Type: application/json' \ + --header 'Authorization: Basic c2E6c2lyaQ==' \ + --header 'Content-Type: text/plain' \ + --data-raw '{ + "database": "sampledb", + "ignore_offline": false +}' || RES=1 +cat res.txt +echo +expect='"OK"' +if [ "$(cat res.txt)" != "$expect" ] ; then RES=1 ; echo "FAILED: expected $expect" ; fi + +echo ' drop-database again' +curl --silent --show-error --location --output res.txt \ + --request POST 'http://localhost:9020/drop-database' \ + --header 'Content-Type: application/json' \ + --header 'Authorization: Basic c2E6c2lyaQ==' \ + --header 'Content-Type: text/plain' \ + --data-raw '{ + "database": "sampledb", + "ignore_offline": false +}' || RES=1 +cat res.txt +echo +expect='{"error_msg":"cannot find database '"'"'sampledb'"'"'"}' +if [ "$(cat res.txt)" != "$expect" ] ; then RES=1 ; echo "FAILED: expected $expect" ; fi + +echo ' get-accounts' +curl --silent --show-error --location --output res.txt \ + --request GET 'http://localhost:9020/get-accounts' \ + --header 'Content-Type: application/json' \ + --header 'Authorization: Basic c2E6c2lyaQ==' +cat res.txt +echo +expect='["sa"]' +if [ "$(cat res.txt)" != "$expect" ] ; then RES=1 ; echo "FAILED: expected $expect" ; fi + +echo ' new-database for queries' +curl --silent --show-error --location --output res.txt \ + --request POST 'http://localhost:9020/new-database' \ + --header 'Content-Type: application/json' \ + --header 'Authorization: Basic c2E6c2lyaQ==' \ + --header 'Content-Type: text/plain' \ + --data-raw '{ + "dbname": "sampledb", + "time_precision": "s", + "buffer_size": 8192, + "duration_num": "1w", + "duration_log": "3d" +}' || RES=1 +cat res.txt +echo +expect='"OK"' +if [ "$(cat res.txt)" != "$expect" ] ; then RES=1 ; echo "FAILED: expected $expect" ; fi + +echo ' get-databases' +curl --silent --show-error --location --output res.txt \ + --request GET 'http://localhost:9020/get-databases' \ + --header 'Content-Type: application/json' \ + --header 'Authorization: Basic c2E6c2lyaQ==' +cat res.txt +echo +expect='["sampledb"]' +if [ "$(cat res.txt)" != "$expect" ] ; then RES=1 ; echo "FAILED: expected $expect" ; fi + +echo ' query data (nothing there)' +curl --silent --show-error --location --output res.txt \ + --request POST 'http://localhost:9020/query/sampledb' \ + --header 'Content-Type: application/json' \ + --header 'Authorization: Basic aXJpczpzaXJp' \ + --header 'Content-Type: text/plain' \ + --data-raw '{ + "q": "select count() from '\''aggr'\''", + "t": "ms" +}' || RES=1 +cat res.txt +echo +expect='{}' +if [ "$(cat res.txt)" != "$expect" ] ; then RES=1 ; echo "FAILED: expected $expect" ; fi + +echo ' insert data' +curl --silent --show-error --location --output res.txt \ + --request POST 'http://localhost:9020/insert/sampledb' \ + --header 'Content-Type: application/json' \ + --header 'Authorization: Basic aXJpczpzaXJp' \ + --header 'Content-Type: text/plain' \ + --data-raw '{ + "aggr": [ + [1578933215, 42], + [1578933223, 123] + ] +}' || RES=1 +cat res.txt +echo +expect='{"success_msg":"Successfully inserted 2 point(s)."}' +if [ "$(cat res.txt)" != "$expect" ] ; then RES=1 ; echo "FAILED: expected $expect" ; fi + +echo ' query data' +curl --silent --show-error --location --output res.txt \ + --request POST 'http://localhost:9020/query/sampledb' \ + --header 'Content-Type: application/json' \ + --header 'Authorization: Basic aXJpczpzaXJp' \ + --header 'Content-Type: text/plain' \ + --data-raw '{ + "q": "select count() from '\''aggr'\''", + "t": "ms" +}' || RES=1 +cat res.txt +echo +expect='{"aggr":[[1578933223000,2]]}' +if [ "$(cat res.txt)" != "$expect" ] ; then RES=1 ; echo "FAILED: expected $expect" ; fi + +exit $RES