Commit 029b0338 authored by zauberstuhl's avatar zauberstuhl

Add test file diaspora-ganggo.tx-rx.bats

parent 157bf73e
#!/usr/bin/env bats
load test_helper
gngg_endpnt="http://localhost:9000"
@test "$btf create database" {
psql -U postgres -c "create database g1;"
[ "$?" -eq 0 ]
}
@test "$btf start ganggo#1 server" {
start_app "g1" "9000" "testing_ganggo:"$(latest_tag "ganggo")
[ "$?" -eq 0 ]
code=$(wait_for "docker logs g1" "Listening on")
echo "expected 0, got $code"
[ "$code" -eq "0" ]
}
@test "$btf start diaspora#1 server" {
start_app "d1" "3000" "testing_diaspora:"$(latest_tag "diaspora")
[ "$?" -eq 0 ]
code=$(wait_for "docker logs d1" "Starting Diaspora in production")
echo "expected 0, got $code"
[ "$code" -eq "0" ]
# unicorn timeout
sleep 15
}
@test "$btf create ganggo user" {
post "username=g1&password=pppppp&confirm=pppppp" "$gngg_endpnt/users/sign_up"
echo "expected 302, got $HTTP_STATUS_CODE"
[ "$HTTP_STATUS_CODE" == "000302" ]
}
@test "$btf create diaspora user" {
skip "exists already"
}
@test "$btf setup user relations" {
rails_runner "d1" "user = User.find_by(username: 'd1');
person = Person.find_or_fetch_by_identifier('g1@localhost:9000');
Aspect.find_each {|obj| user.share_with(person, obj)};"
[ "$?" -eq 0 ]
}
function send_type() {
type=$1
# should we send it publicly or limited
if [ "$type" == "private" ]; then
postType="public: false, aspect_ids: aspectIds"
else
postType="public: true"
fi
# send post via diaspora
postID=$(rails_runner "d1" "user = User.find_by(username: 'd1');
aspectIds = Aspect.find_each.collect {|obj| obj.id if obj.user_id == 1 }
puts StatusMessageCreationService.new(user).create(
status_message: {text: 'hello world'}, $postType
).id;")
echo "postID = $postID"
[ "$?" -eq 0 ]
[ "$postID" -gt 0 ]
# check if ganggo received it
function cmd() {
query "g1" "select count(*) from posts where public = true;"
}
code=$(wait_for cmd "1")
echo "expected 0, got $code"
[ "$code" -eq "0" ]
# send comment
guid=$(rails_runner "d1" "user = User.find_by(username: 'd1');
puts CommentService.new(user)
.create($postID, 'commenttext').guid;")
echo "guid = $guid"
[ "$?" -eq 0 ]
# XXX how to check guid
#[ "$guid" != "null" ]
# check comment
function cmd() {
query "g1" "select count(*) from comments where guid = '$guid';"
}
code=$(wait_for cmd "1")
echo "expected 0, got $code"
[ "$code" -eq "0" ]
# send like
guid=$(rails_runner "d1" "user = User.find_by(username: 'd1');
puts LikeService.new(user).create($postID).guid;")
echo "guid = $guid"
[ "$?" -eq 0 ]
# XXX how to check guid
#[ "$guid" != "null" ]
# check comment
function cmd() {
query "g1" "select count(*) from likes where guid = '$guid';"
}
code=$(wait_for cmd "1")
echo "expected 0, got $code"
[ "$code" -eq "0" ]
}
@test "$btf create public entities and check federation" {
send_type public
}
@test "$btf create private entities and check federation" {
send_type private
}
@test "$btf stop and delete containers" {
stop_app "g1 d1"
[ "$?" -eq 0 ]
remove_app "g1 d1"
[ "$?" -eq 0 ]
}
@test "$btf drop databases" {
psql -U postgres -c "drop database g1;"
[ "$?" -eq 0 ]
psql -U postgres -c "drop database d1;"
[ "$?" -eq 0 ]
}
......@@ -7,12 +7,12 @@ load test_helper
endpoint="http://localhost:9000"
@test "create database" {
@test "$btf create database" {
psql -U postgres -c "create database g1;"
[ "$?" -eq 0 ]
}
@test "start ganggo#1 server" {
@test "$btf start ganggo#1 server" {
start_app "g1" "9000" "testing_ganggo:"$(latest_tag "ganggo")
[ "$?" -eq 0 ]
code=$(wait_for "docker logs g1" "Listening on")
......@@ -20,7 +20,7 @@ endpoint="http://localhost:9000"
[ "$code" -eq "0" ]
}
@test "start diaspora#1 server" {
@test "$btf start diaspora#1 server" {
start_app "d1" "3000" "testing_diaspora:"$(latest_tag "diaspora")
[ "$?" -eq 0 ]
code=$(wait_for "docker logs d1" "Starting Diaspora in production")
......@@ -30,14 +30,18 @@ endpoint="http://localhost:9000"
sleep 15
}
@test "create user" {
@test "$btf create user" {
post "username=g1&password=pppppp&confirm=pppppp" "$endpoint/users/sign_up"
echo "expected 302, got $HTTP_STATUS_CODE"
[ "$HTTP_STATUS_CODE" == "000302" ]
}
@test "$btf create diaspora user" {
skip "exists already"
}
# according to https://ganggo.github.io/api/#api-Oauth-ApiOAuth_Create
@test "fetch user token" {
@test "$btf fetch user token" {
post "grant_type=password&username=g1&password=pppppp&client_id=bats" \
"$endpoint/api/v0/oauth/tokens"
echo "expected 200, got $HTTP_STATUS_CODE"
......@@ -49,7 +53,7 @@ endpoint="http://localhost:9000"
echo "-H access_token:$token" > $curl_params
}
@test "setup user relations" {
@test "$btf setup user relations" {
# search and discover a person
post "handle=d1@localhost:3000" "$endpoint/api/v0/search"
echo "expected 200, got $HTTP_STATUS_CODE"
......@@ -135,22 +139,22 @@ function send_type() {
[ "$code" -eq "0" ]
}
@test "create public entities and check federation" {
@test "$btf create public entities and check federation" {
send_type public
}
@test "create private entities and check federation" {
@test "$btf create private entities and check federation" {
send_type private
}
@test "stop and delete containers" {
@test "$btf stop and delete containers" {
stop_app "g1 d1"
[ "$?" -eq 0 ]
remove_app "g1 d1"
[ "$?" -eq 0 ]
}
@test "drop databases" {
@test "$btf drop databases" {
psql -U postgres -c "drop database g1;"
[ "$?" -eq 0 ]
psql -U postgres -c "drop database d1;"
......
export btf=$(basename $BATS_TEST_FILENAME)
# will run on every test and
# verify installed dependencies
function setup() {
......@@ -87,3 +89,8 @@ function latest_tag() {
done
echo null
}
# rails_runner "d1" "puts 'Hello World!'"
function rails_runner() {
docker exec $1 bundle exec rails runner "$2"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment