97f53041205fca480e4ecf0692e4d0f44e743606
[scm/test.git] / test / testenv.sh
1 #!/usr/bin/env bash
2 # Including in script/integration and every test/test-*.sh file.
3
4 set -e
5
6 UNAME=$(uname -s)
7 IS_WINDOWS=0
8 IS_MAC=0
9 SHASUM="shasum -a 256"
10 PATH_SEPARATOR="/"
11
12 if [[ $UNAME == MINGW* || $UNAME == MSYS* || $UNAME == CYGWIN* ]]
13 then
14   IS_WINDOWS=1
15
16   # Windows might be MSYS2 which does not have the shasum Perl wrapper
17   # script by default, so use sha256sum directly. MacOS on the other hand
18   # does not have sha256sum, so still use shasum as the default.
19   SHASUM="sha256sum"
20   PATH_SEPARATOR="\\"
21 elif [[ $UNAME == *Darwin* ]]
22 then
23   IS_MAC=1
24 fi
25
26 resolve_symlink() {
27   local arg=$1
28   if [ $IS_WINDOWS -eq 1 ]; then
29     printf '%s' "$arg"
30   elif [ $IS_MAC -eq 1 ]; then
31     # no readlink -f on Mac
32     local oldwd=$(pwd)
33     local target=$arg
34
35     cd `dirname $target`
36     target=`basename $target`
37     while [ -L "$target" ]
38     do
39         target=`readlink $target`
40         cd `dirname $target`
41         target=`basename $target`
42     done
43
44     local resolveddir=`pwd -P`
45     cd "$oldwd"
46     printf '%s' "$resolveddir/$target"
47
48   else
49     readlink -f "$arg"
50   fi
51
52 }
53
54 # The root directory for the git-lfs repository by default.
55 if [ -z "$ROOTDIR" ]; then
56   ROOTDIR=$(cd $(dirname "$0")/.. && pwd -P)
57 fi
58
59 # Where Git LFS outputs the compiled binaries
60 BINPATH="$ROOTDIR/bin"
61
62 # Put bin path on PATH
63 PATH="$BINPATH:$PATH"
64
65 # Always provide a test dir outside our git repo if not specified
66 TEMPDIR_PREFIX="git-lfs_TEMP.XXXXXX"
67 if [ -z "$GIT_LFS_TEST_DIR" ]; then
68     GIT_LFS_TEST_DIR=$(mktemp -d -t "$TEMPDIR_PREFIX")
69     GIT_LFS_TEST_DIR=$(resolve_symlink $GIT_LFS_TEST_DIR)
70     # cleanup either after single test or at end of integration (except on fail)
71     RM_GIT_LFS_TEST_DIR=yes
72 fi
73 # create a temporary work space
74 TMPDIR=$GIT_LFS_TEST_DIR
75
76 # This is unique to every test file, and cleared after every test run.
77 TRASHDIR="$TMPDIR/$(basename "$0")-$$"
78
79 # The directory that the test Git server works from.  This cleared at the
80 # beginning of every test run.
81 REMOTEDIR="$ROOTDIR/test/remote"
82
83 # The directory that stores credentials. Credentials are stored in files with
84 # the username:password with filenames identifying the host (port numbers are
85 # ignored).
86 #
87 #   # stores the credentials for http://127.0.0.1:*
88 #   $CREDSDIR/127.0.0.1
89 #
90 #   # stores the credentials for http://git-server.com
91 #   $CREDSDIR/git-server.com
92 #
93 CREDSDIR="$REMOTEDIR/creds"
94
95 # This is the prefix for Git config files.  See the "Test Suite" section in
96 # test/README.md
97 LFS_CONFIG="$REMOTEDIR/config"
98
99 # This file contains the URL of the test Git server. See the "Test Suite"
100 # section in test/README.md
101 LFS_URL_FILE="$REMOTEDIR/url"
102
103 # This file contains the SSL URL of the test Git server. See the "Test Suite"
104 # section in test/README.md
105 LFS_SSL_URL_FILE="$REMOTEDIR/sslurl"
106
107 # This file contains the client cert SSL URL of the test Git server. See the "Test Suite"
108 # section in test/README.md
109 LFS_CLIENT_CERT_URL_FILE="$REMOTEDIR/clientcerturl"
110
111 # This file contains the self-signed SSL cert of the TLS endpoint of the test Git server.
112 LFS_CERT_FILE="$REMOTEDIR/cert"
113
114 # This file contains the client certificate of the client cert endpoint of the test Git server.
115 LFS_CLIENT_CERT_FILE="$REMOTEDIR/client.crt"
116
117 # This file contains the client key of the client cert endpoint of the test Git server.
118 LFS_CLIENT_KEY_FILE="$REMOTEDIR/client.key"
119
120 # the fake home dir used for the initial setup
121 TESTHOME="$REMOTEDIR/home"
122
123 GIT_CONFIG_NOSYSTEM=1
124 GIT_TERMINAL_PROMPT=0
125 GIT_SSH=lfs-ssh-echo
126 APPVEYOR_REPO_COMMIT_MESSAGE="test: env test should look for GIT_SSH too"
127
128 export CREDSDIR
129 export GIT_CONFIG_NOSYSTEM
130 export GIT_SSH
131 export APPVEYOR_REPO_COMMIT_MESSAGE
132
133 mkdir -p "$TMPDIR"
134 mkdir -p "$TRASHDIR"
135
136 if [ $IS_WINDOWS -eq 1 ]; then
137   # prevent Windows OpenSSH from opening GUI prompts
138   SSH_ASKPASS=""
139 fi
140 . "test/testhelpers.sh"