summaryrefslogtreecommitdiff
path: root/scripts/gitlab/run_soledad_tests.sh
blob: 328fcc4db337c8b46204d73ac571860f23526a3f (plain)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/sh


# Name:
#   run_tests.sh -- run soledad tests from a given source directory
#
# Usage:
#   run_tests.sh
#
# Description:
#   This script sets up a minimal test environment from a soledad source
#   directory and runs all tests, returning the same exit status as the test
#   process. As it is intended to be called by a GitLab Runner, it expects the
#   following GitLab CI predefined variable to be set in the environment:
#
#   CI_PROJECT_DIR   The full path where the repository is cloned and where
#                    the build is ran
#
# Example:
#   CI_PROJECT_DIR=/tmp/soledad run_tests.sh


# Fail if expected variable is not a directory.
if [ ! -d "${CI_PROJECT_DIR}" ]; then
  echo "Error! Not a directory: ${CI_PROJECT_DIR}"
  exit 1
fi


# Setup pip to use wheels because it is prebuilt and thus faster to deploy.

PIP_INSTALL="pip install -U                               \
               --find-links=https://lizard.leap.se/wheels \
               --trusted-host lizard.leap.se"


# Use a fresh python virtual envinroment each time.

setup_venv() {
  venv=${1}
  virtualenv ${venv}
  . ${venv}/bin/activate
}


# Most of the dependencies are installed directly from soledad source pip
# requirement files. Some of them need alternative ways of installing because
# of distinct reasons, see below.

install_deps() {
  install_leap_common
  install_scrypt
  install_soledad_deps
}


# Install scrypt manually to avoid import problems as the ones described in
# https://leap.se/code/issues/4948

install_scrypt() {
  pip install scrypt
}


# Iterate through soledad components and use the special pip install script to
# install (mostly) all requirements for testing.
#
# TODO: Soledad tests should depend on almost nothing and have every component
#       from other leap packages mocked.

install_soledad_deps() {
  for pkg in common client server; do
    testing="--testing"
    if [ "${pkg}" = "server" ]; then
      # soledad server doesn't currently have a requirements-testing.pip file,
      # so we don't pass the option when that is the case
      testing=""
    fi
    (cd ${CI_PROJECT_DIR}/${pkg} \
     && ./pkg/pip_install_requirements.sh ${testing} --use-leap-wheels \
     && python setup.py develop)
  done
}


# We have to manually install leap.common from source because:
#
#   - the leap.common package is not currently set as a "testing dependency"
#     for soledad; and
#
#   - having another package from the leap namespace installed from egg or
#     wheels may confuse the python interpreter when importing modules.

install_leap_common() {
  temp=`mktemp -d`
  host="git://github.com/leapcode"
  proj="leap_pycommon"
  git clone ${host}/${proj} ${temp}/${proj}
  (cd ${temp}/${proj} \
   && ./pkg/pip_install_requirements.sh \
   && python setup.py develop)
}


# Run soledad tests. The exit status of the following function is used as the
# script's exit status.

run_tests() {
  trial leap.soledad.common.tests
}


# Cleanup leftovers before finishing.

cleanup_venv() {
  venv=${1}
  rm -rf ${venv}
}


main() {
  venv="`mktemp -d`/venv"
  setup_venv ${venv}
  install_deps
  run_tests
  status=$?
  cleanup_venv ${venv}
  exit ${status}
}


main