testproject.bats 1.95 KB
Newer Older
Lukas Matt's avatar
Lukas Matt committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
# vim:ft=sh
#
# this test file is related to https://feneas.git.feneas.org/federation/testsuite

load test_helper

@test "$btf create databases" {
  for tp in tp1 tp2; do
    create_database $tp
    [ "$?" -eq 0 ]
  done
}

@test "$btf start testproject#1 server" {
  start_app tp1 3000 testproject$(latest_tag testproject)
  [ "$?" -eq 0 ]
  # NOTE You can also wait for certain log output!
  # Incase your server is only operational after
  # a special message then you can use the wait_for
  # function from the test_helper file:
  #
  #   wait_for <command> <search-text>
  #
  # for this project that could look something like this:
  #
26 27 28 29
  cmd="docker logs $(container_id tp1)"
  text="CREATE TABLE"
  code=$(wait_for "$cmd" "$text")
  [ "$code" -eq "0" ]
Lukas Matt's avatar
Lukas Matt committed
30 31 32 33 34
}

@test "$btf start testproject#2 server" {
  start_app tp2 3000 testproject$(latest_tag testproject)
  [ "$?" -eq 0 ]
Lukas Matt's avatar
Lukas Matt committed
35
  cmd="docker logs $(container_id tp2)"
36 37 38
  text="CREATE TABLE"
  code=$(wait_for "$cmd" "$text")
  [ "$code" -eq "0" ]
Lukas Matt's avatar
Lukas Matt committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
}

@test "$btf test initial count, it should be zero" {
  for tp in tp1 tp2; do
    get "http://$(container_ip $tp):3000"
    echo "expected 200, got $HTTP_STATUS_CODE"
    [ "$HTTP_STATUS_CODE" == "200" ]
    echo "expected 0, got $HTTP_BODY"
    [ "$HTTP_BODY" == "0" ]
  done
}

@test "$btf increase count on tp1 via tp2" {
  get "http://$(container_ip tp2):3000/add@$(container_ip tp1):3000"
  [ "$HTTP_STATUS_CODE" == "200" ]
}

@test "$btf test count on tp1, it should be one" {
Lukas Matt's avatar
Lukas Matt committed
57 58 59
  cmd='get "http://'$(container_ip tp1)':3000"'
  code=$(wait_for "$cmd" "1")
  [ "$code" -eq "0" ]
Lukas Matt's avatar
Lukas Matt committed
60 61 62
}

@test "$btf check the database on tp1 too" {
Lukas Matt's avatar
Lukas Matt committed
63 64 65
  cmd='query tp1 "select count(*) from testtable;"'
  code=$(wait_for "$cmd" "1")
  [ "$code" -eq "0" ]
Lukas Matt's avatar
Lukas Matt committed
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
}

@test "$btf stop and delete the containers" {
  for tp in tp1 tp2; do
    stop_app $tp
    [ "$?" -eq 0 ]
    remove_app $tp
    [ "$?" -eq 0 ]
  done
}

@test "$btf drop databases" {
  for tp in tp1 tp2; do
    drop_database $tp
    [ "$?" -eq 0 ]
  done
}