Unverified Commit 10a07568 authored by zauberstuhl's avatar zauberstuhl Committed by GitHub

Merge pull request #5 from thefederationinfo/add_more_coverage

Add more test coverage
parents 5c54bb7c 029b0338
......@@ -7,7 +7,10 @@ services:
- postgresql
- docker
install:
- git clone --depth 1 https://github.com/sstephenson/bats.git
- cd bats && sudo ./install.sh /usr/local
- |
sudo curl -o /usr/local/bin/jq -L \
https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64
git clone --depth 1 https://github.com/sstephenson/bats.git
cd bats && sudo ./install.sh /usr/local
script:
- cd $TRAVIS_BUILD_DIR && bats --tap .
#!/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 ]
}
FROM thefederation/diaspora_image:v1.0.2
FROM debian:jessie
MAINTAINER Lukas Matt <lukas@zauberstuhl.de>
ENV DEBIAN_FRONTEND noninteractive
ENV RAILS_ENV production
ENV DISABLE_DATABASE_ENVIRONMENT_CHECK 1
COPY post_like_comment.rb /diaspora/post_like_comment.rb
COPY share_with.rb /diaspora/share_with.rb
RUN apt-get update
RUN apt-get -y upgrade
RUN apt-get -y install libreadline-dev cmake build-essential libssl-dev libcurl4-openssl-dev libxml2-dev libxslt-dev imagemagick ghostscript curl libmagickwand-dev git libpq-dev redis-server nodejs postgresql-client
RUN mkdir /tmp/ruby && cd /tmp/ruby \
&& curl -L --progress http://cache.ruby-lang.org/pub/ruby/2.4/ruby-2.4.2.tar.gz | tar xz \
&& cd ruby-2.4.2 \
&& ./configure --disable-install-rdoc \
&& make -j2 \
&& make install
RUN gem install bundler
RUN git clone --depth 1 https://github.com/diaspora/diaspora.git -b master
WORKDIR /diaspora
RUN cp config/database.yml.example config/database.yml \
&& cp config/diaspora.yml.example config/diaspora.yml
RUN bundle install --with postgresql
RUN sed -i "s/#rails_environment:.*/rails_environment: 'production'/" config/diaspora.yml
RUN sed -i "s/#url:/url:/" config/diaspora.yml
RUN sed -i "0,/#certificate_authorities/ s/#certificate_authorities:/certificate_authorities:/" config/diaspora.yml
RUN sed -i "s/#require_ssl:.*/require_ssl: false/" config/diaspora.yml
RUN sed -i "s/#serve:.*/serve: true/" config/diaspora.yml
RUN bundle exec rails assets:precompile
RUN curl -LO http://download.redis.io/redis-stable.tar.gz
RUN tar -xvzf redis-stable.tar.gz
RUN cd redis-stable && make
RUN cd redis-stable && make install
RUN rm -rf redis-stable
COPY schema.sql /diaspora/schema.sql
COPY start.sh /start.sh
......
FROM debian:jessie
MAINTAINER Lukas Matt <lukas@zauberstuhl.de>
ENV DEBIAN_FRONTEND noninteractive
ENV RAILS_ENV production
RUN apt-get update
RUN apt-get -y upgrade
RUN apt-get -y install libreadline-dev cmake build-essential libssl-dev libcurl4-openssl-dev libxml2-dev libxslt-dev imagemagick ghostscript curl libmagickwand-dev git libpq-dev redis-server nodejs postgresql-client
RUN mkdir /tmp/ruby && cd /tmp/ruby \
&& curl -L --progress http://cache.ruby-lang.org/pub/ruby/2.4/ruby-2.4.2.tar.gz | tar xz \
&& cd ruby-2.4.2 \
&& ./configure --disable-install-rdoc \
&& make -j2 \
&& make install
RUN gem install bundler
RUN git clone --depth 1 https://github.com/diaspora/diaspora.git -b master
WORKDIR /diaspora
RUN cp config/database.yml.example config/database.yml \
&& cp config/diaspora.yml.example config/diaspora.yml
RUN bundle install --with postgresql
RUN sed -i "s/#rails_environment:.*/rails_environment: 'production'/" config/diaspora.yml
RUN sed -i "s/#url:/url:/" config/diaspora.yml
RUN sed -i "0,/#certificate_authorities/ s/#certificate_authorities:/certificate_authorities:/" config/diaspora.yml
RUN sed -i "s/#require_ssl:.*/require_ssl: false/" config/diaspora.yml
RUN sed -i "s/#serve:.*/serve: true/" config/diaspora.yml
RUN bundle exec rake db:create db:migrate assets:precompile
RUN curl -LO http://download.redis.io/redis-stable.tar.gz
RUN tar -xvzf redis-stable.tar.gz
RUN cd redis-stable && make
RUN cd redis-stable && make install
RUN rm -rf redis-stable
# Building
Requires a local postgres database then run:
```
docker build --network=host -t thefederation/diaspora_image:<tag> .
```
user = User.find_by(username: ARGV[0])
publicPost = StatusMessageCreationService.new(user).create(
status_message: {
text: "StatusMessageCreationService publicPost"
},
public: true
)
aspectIds = Aspect.find_each.collect {|obj| obj.id if obj.user_id == 1 }
privatePost = StatusMessageCreationService.new(user).create(
status_message: {
text: "StatusMessageCreationService privatePost"
},
public: false,
aspect_ids: aspectIds
)
CommentService.new(user).create(publicPost.id, "publicComment")
CommentService.new(user).create(privatePost.id, "privateComment")
LikeService.new(user).create(publicPost.id)
LikeService.new(user).create(privatePost.id)
user = User.find_by(username: ARGV[0])
person = Person.find_or_fetch_by_identifier(ARGV[1])
Aspect.find_each {|obj|
if user.id == obj.user_id
user.share_with(person, obj)
end
}
#!/usr/bin/env bats
#
# All API calls are documented here: https://ganggo.github.io/api/
#
load test_helper
endpoint="http://localhost:9000"
@test "curl and psql client exists" {
command -v psql
[ "$?" -eq 0 ]
command -v curl
[ "$?" -eq 0 ]
}
@test "create database" {
@test "$btf create database" {
psql -U postgres -c "create database g1;"
[ "$?" -eq 0 ]
}
@test "start ganggo#1 server" {
start_app "g1" "9000" "testing_ganggo:v1.0.0-ganggo"
@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 "start diaspora#1 server" {
start_app "d1" "3000" "testing_diaspora:v1.0.3-diaspora"
@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"
......@@ -34,31 +30,35 @@ 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"
[ "$HTTP_STATUS_CODE" == "000200" ]
token=$(echo $HTTP_BODY |cut -d'"' -f 4)
token=$(json_value "token")
echo "body = $HTTP_BODY"
echo "token = $token"
[ "$token" != "" ]
[ "$token" != "null" ]
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"
[ "$HTTP_STATUS_CODE" == "000200" ]
personID=$(echo $HTTP_BODY |sed -r 's/.*"ID":\s*([0-9]+),.*/\1/g')
personID=$(json_value "ID")
echo "body = $HTTP_BODY"
echo "personID = $personID"
[ "$personID" -gt 0 ]
......@@ -66,7 +66,7 @@ endpoint="http://localhost:9000"
post "aspect_name=test" "$endpoint/api/v0/aspects"
echo "expected 200, got $HTTP_STATUS_CODE"
[ "$HTTP_STATUS_CODE" == "000200" ]
aspectID=$(echo $HTTP_BODY |sed -r 's/.*"ID":\s*([0-9]+),.*/\1/g')
aspectID=$(json_value "ID")
echo "body = $HTTP_BODY"
echo "aspectID = $aspectID"
[ "$aspectID" -gt 0 ]
......@@ -76,30 +76,85 @@ endpoint="http://localhost:9000"
[ "$HTTP_STATUS_CODE" == "000200" ]
}
@test "create post and check federation" {
function send_type() {
type=$1
aspectID=0
[ "$type" == "private" ] && aspectID=1
# create post via ganggo
post "post=helloworld&aspectID=0" "$endpoint/api/v0/posts"
post "post=helloworld&aspectID=$aspectID" "$endpoint/api/v0/posts"
echo "expected 200, got $HTTP_STATUS_CODE"
[ "$HTTP_STATUS_CODE" == "000200" ]
postID=$(json_value "ID")
echo "body = $HTTP_BODY"
echo "postID = $postID"
[ "$postID" -gt 0 ]
guid=$(json_value "Guid")
echo "guid = $guid"
[ "$guid" != "null" ]
# check post in diaspora
function cmd() {
public="true"
[ "$type" == "private" ] && public="false"
query "d1" "select count(*) from posts
where guid = '$guid' and public = $public;"
}
code=$(wait_for cmd "1")
echo "expected 0, got $code"
[ "$code" -eq "0" ]
# create comment
post "comment=hellod1" "$endpoint/api/v0/posts/$postID/comments"
echo "expected 200, got $HTTP_STATUS_CODE"
[ "$HTTP_STATUS_CODE" == "000200" ]
guid=$(json_value "Guid")
echo "body = $HTTP_BODY"
echo "guid = $guid"
[ "$guid" != "null" ]
# check comment
function cmd() {
query "d1" "select count(*) from comments
where guid = '$guid';"
}
code=$(wait_for cmd "1")
echo "expected 0, got $code"
[ "$code" -eq "0" ]
# check post in diaspora
# create like
post "" "$endpoint/api/v0/posts/$postID/likes/true"
echo "expected 200, got $HTTP_STATUS_CODE"
[ "$HTTP_STATUS_CODE" == "000200" ]
guid=$(json_value "Guid")
echo "body = $HTTP_BODY"
echo "guid = $guid"
[ "$guid" != "null" ]
# check like
function cmd() {
query "d1" "select count(*) from posts;"
query "d1" "select count(*) from likes
where guid = '$guid';"
}
code=$(wait_for cmd "1")
echo "expected 0, got $code"
[ "$code" -eq "0" ]
}
@test "stop and delete containers" {
@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 "drop databases" {
@test "$btf drop databases" {
psql -U postgres -c "drop database g1;"
[ "$?" -eq 0 ]
psql -U postgres -c "drop database d1;"
......
curl_params="/tmp/curl_params"
export btf=$(basename $BATS_TEST_FILENAME)
# will run on every test and
# verify installed dependencies
function setup() {
# postgresql client
command -v psql
[ "$?" -eq 0 ]
# curl http client
command -v curl
[ "$?" -eq 0 ]
# json parser
command -v jq
[ "$?" -eq 0 ]
# git binary
command -v git
[ "$?" -eq 0 ]
}
curl_params="/tmp/curl_params"
# fetch "POST" "data1=one&data2=two" "http://server/endpoint"
function fetch() {
tmp=$(mktemp)
......@@ -54,3 +72,25 @@ function wait_for() {
function query() {
psql -t -d $1 -U postgres -c "$2" |tr -d '\n\r '
}
# json_value "ID"
function json_value() {
echo $HTTP_BODY | jq -r ".$1"
}
# latest_tag "diaspora"
function latest_tag() {
git tag |sort -r |while read tag; do
label=$(echo $tag |cut -d- -f2)
if [ "$label" == "$1" ]; then
echo $tag
return
fi
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