This directory contains one of the two types of tests that the Git LFS project uses to protect against regression. The first, scattered in the source files throughout the repository are unit tests, designed to uncover failures at the unit level.
The second kind (and the one contained in this directory) are integration
tests, which are designed to exercise Git LFS in an end-to-end fashion,
running the git, and git-lfs binaries, along with a mock Git server.
These integration tests are copied from the t folder of the original
git-lfs project, with some modifications. Re-using their test suite
ensures that this implementation is compatible in functionality.
The vendored snapshot is pinned to upstream commit
12137348e03e290e6535f3eaeffb6c4c20de96ce. To refresh
against a newer upstream commit, sync each t-*.sh file individually
(local modifications exist — diff before overwriting), bump the pin
above, and re-run the suite to surface any new failures for the
scoreboard.
You can run all tests in this directory with any of the following:
$ make
$ make test
$ make PROVE_EXTRA_ARGS=-j9 testOr run a single test (for example, t-checkout.sh) by any of the following:
$ make ./t-checkout.sh
$ make PROVE_EXTRA_ARGS=-v ./t-checkout.sh
$ ./t-checkout.shAlternatively, one can run a selection of tests (via explicitly listing them or making use of the built-in shell globbing) by any of the following:
$ make ./t-*.sh
$ make PROVE_EXTRA_ARGS=-j9 ./t-*.sh
$ ./t-*.shThere are a few important kinds of files to know about in the tests directory:
-
cmd/: contains the source code of binaries that are useful during test time, like the mocked Git server, or the test counting binary. For more about the contents of this directory, see test lifecycle below.The file
tests/cmd/testutils.gois automatically linked and included during the build process of each file incmd. -
fixtures/: contains shell scripts that load fixture repositories useful for testing against. -
t-*.sh: file(s) containing zero or more tests, typically related to a similar topic (c.f,.tests/t-push.sh,tests/t-pull.sh, etc.) -
testenv.sh: loads environment variables useful during tests. This file is sourced bytestlib.sh. -
testhelpers.sh: loads shell functions useful during tests, likesetup_remote_repo, andclone_repo. -
testlib.sh: loads thebegin_test,end_test, and similar functions useful for instantiating a particular test.
When a test is run, the following occurs, in order:
-
Missing test binaries are compiled into the
bindirectory in the repository root. Note: this does not include thegit-lfsbinary, which is re-compiled viascript/boostrap. -
An integration server is started by either (1) the
Makefileor (2) thecmd/lfstest-count-test.goprogram, which keeps track of the number of running tests and starts an integration server any time the number of active tests goes from0to1, and stops the server when it goes fromnto0. -
After sourcing
tests/testlib.sh(& loadingtests/testenv.sh), each test is run in sequence per file. (In other words, multiple test files can be run in parallel, but the tests in a single file are run in sequence.) -
An individual test will finish, and (if running under
prove) another will be started in its place. Once all tests are done,tests/test_countwill go to0, and the test server will be torn down.
There are a few environment variables that you can set to change the test suite behavior:
-
GIT_LFS_TEST_DIR=path- This sets the directory that is used as the current working directory of the tests. By default, this will be in your temp dir. It's recommended that this is set to a directory outside of any Git repository. -
KEEPTRASH=1- This will leave the local repository data in atmpdirectory and the remote repository data intest/remote.
Also ensure that your noproxy environment variable contains 127.0.0.1 host,
to allow git commands to reach the local Git server lfstest-gitserver.
A new test file should be named tests/t-*.sh, where * is the topic of Git LFS
being tested. It should look as follows:
#!/usr/bin/env bash
. "$(dirname "$0")/testlib.sh"
begin_test "my test"
(
set -e
# ...
)
end_test