git-lfs/t
Matthew Versluys 88e3e1b286 Allow locking/unlocking of nonexistent files
If a file is renamed or removed, a lock can be obtained and released for that file even though it doesn't exist.

Updated tests to verify that a file that doesn't exist can be locked, a file that was locked an removed can be unlocked and a file that doesn't exist can be locked and unlocked.
2020-05-10 19:41:36 -07:00
..
cmd t: ensure local binary always used in tests 2020-03-27 17:28:40 -07:00
fixtures Modify logic of 'migrate info' to process extensionless files 2019-01-08 12:44:06 +03:00
git-lfs-test-server-api Check error when creating local storage directory 2020-02-10 16:07:59 +00:00
Makefile t: add a test helper equivalent to realpath(1) 2019-09-09 14:30:54 +00:00
README.md t/README.md: link to 'Test Lifecycle' appropriately 2018-07-16 16:39:51 -05:00
t-alternates.sh Ensure proper alternate handling with gitobj 2019-08-15 17:39:32 +00:00
t-askpass.sh Merge branch 'master' into ttaylorr/prove 2018-07-17 12:54:38 -05:00
t-attributes.sh commands/track: read all attributes files to parse macros 2018-12-03 17:18:50 +00:00
t-batch-error-handling.sh t: avoid using shell variables in printf's first argument 2018-09-10 14:57:10 +00:00
t-batch-retries-ratelimit.sh Add a test to check that git lfs clone handles rate limits 2019-01-08 17:36:16 +03:00
t-batch-retries.sh t: avoid using shell variables in printf's first argument 2018-09-10 14:57:10 +00:00
t-batch-transfer.sh Fix typo 'the the' 2019-08-22 00:24:14 +02:00
t-batch-unknown-oids.sh t: avoid using shell variables in printf's first argument 2018-09-10 14:57:10 +00:00
t-checkout.sh filepathfilter: don't say file is both accepted and rejected 2018-11-02 18:40:15 +00:00
t-cherry-pick-commits.sh t: remove unnecessary GIT_TRACE_PACK_ACCESS 2020-02-11 09:19:47 +03:00
t-chunked-transfer-encoding.sh t: avoid using shell variables in printf's first argument 2018-09-10 14:57:10 +00:00
t-clean.sh t: load shell scripts from $(dirname) instead of 't' 2018-07-10 13:51:40 -05:00
t-clone-deprecated.sh t: load shell scripts from $(dirname) instead of 't' 2018-07-10 13:51:40 -05:00
t-clone.sh t: fix flaky tests in CI 2019-10-30 20:21:12 +00:00
t-commit-delete-push.sh t: load shell scripts from $(dirname) instead of 't' 2018-07-10 13:51:40 -05:00
t-config.sh lfsapi: allow specifying multiple insteadOf aliases 2019-03-07 19:07:53 +00:00
t-content-type.sh Always provide a Content-Type when uploading files 2018-09-04 15:03:35 +00:00
t-credentials-no-prompt.sh t: load shell scripts from $(dirname) instead of 't' 2018-07-10 13:51:40 -05:00
t-credentials.sh t: fix flaky tests due to race condition 2019-09-09 14:30:54 +00:00
t-custom-transfers.sh t: fix flaky tests due to race condition 2019-09-09 14:30:54 +00:00
t-dedup.sh t/t-dedup.sh: test lfs extensions prevent dedup 2020-02-28 12:02:37 -08:00
t-duplicate-oids.sh t-duplicate-oids: use correct awk indexing 2020-01-14 19:40:42 +00:00
t-env.sh Fix unittest expected results 2019-12-12 19:10:44 +09:00
t-expired.sh t: avoid using shell variables in printf's first argument 2018-09-10 14:57:10 +00:00
t-ext.sh t: load shell scripts from $(dirname) instead of 't' 2018-07-10 13:51:40 -05:00
t-extra-header.sh Properly handle config options for URLs with upper case letters 2019-04-02 16:06:14 +00:00
t-fetch-include.sh t: avoid using shell variables in printf's first argument 2018-09-10 14:57:10 +00:00
t-fetch-paths.sh t: avoid using shell variables in printf's first argument 2018-09-10 14:57:10 +00:00
t-fetch-recent.sh t: load shell scripts from $(dirname) instead of 't' 2018-07-10 13:51:40 -05:00
t-fetch-refspec.sh t: load shell scripts from $(dirname) instead of 't' 2018-07-10 13:51:40 -05:00
t-fetch.sh Check error when creating local storage directory 2020-02-10 16:07:59 +00:00
t-filter-branch.sh t: avoid using shell variables in printf's first argument 2018-09-10 14:57:10 +00:00
t-filter-process.sh filter-process: avoid hang when using git hash-object --stdin 2019-11-04 19:55:45 +00:00
t-fsck.sh t: add a test for shell characters in paths 2019-09-11 18:23:57 +00:00
t-happy-path.sh t: avoid using shell variables in printf's first argument 2018-09-10 14:57:10 +00:00
t-install-custom-hooks-path-unsupported.sh t: load shell scripts from $(dirname) instead of 't' 2018-07-10 13:51:40 -05:00
t-install-custom-hooks-path.sh Interpret relative hook paths as relative to working tree 2019-11-21 17:19:55 +00:00
t-install.sh install: don't print error if run outside repository 2020-01-03 15:55:26 +00:00
t-lock.sh Allow locking/unlocking of nonexistent files 2020-05-10 19:41:36 -07:00
t-locks.sh locking: use a download token when searching locks 2019-07-17 21:41:56 +00:00
t-logs.sh t: load shell scripts from $(dirname) instead of 't' 2018-07-10 13:51:40 -05:00
t-ls-files.sh commands: don't honor lfs.fetch* for ls-files 2020-03-31 13:55:24 +00:00
t-malformed-pointers.sh t: load shell scripts from $(dirname) instead of 't' 2018-07-10 13:51:40 -05:00
t-mergetool.sh t: load shell scripts from $(dirname) instead of 't' 2018-07-10 13:51:40 -05:00
t-migrate-export.sh Reset the text attribute on export 2019-11-12 15:18:21 +00:00
t-migrate-fixup.sh git: avoid trying to rewrite remote tags as remote branches 2020-04-15 13:42:17 +00:00
t-migrate-import-no-rewrite.sh commands/migrate: produce syntactically valid commits 2018-10-11 19:59:58 +00:00
t-migrate-import.sh migrate import: set text to unspecified for excluded fields 2020-04-09 17:25:24 +00:00
t-migrate-info.sh Modify logic of 'migrate info' to process extensionless files 2019-01-08 12:44:06 +03:00
t-object-authenticated.sh t: load shell scripts from $(dirname) instead of 't' 2018-07-10 13:51:40 -05:00
t-pointer.sh commands/command_pointer.go: introduce --check option 2019-01-31 19:36:01 -08:00
t-post-checkout.sh t: load shell scripts from $(dirname) instead of 't' 2018-07-10 13:51:40 -05:00
t-post-commit.sh walker: don't recurse into submodules 2019-06-14 17:26:29 +00:00
t-post-merge.sh t: load shell scripts from $(dirname) instead of 't' 2018-07-10 13:51:40 -05:00
t-pre-push.sh Allow literal local paths as remotes 2020-05-06 13:56:40 +00:00
t-progress-meter.sh t: avoid using shell variables in printf's first argument 2018-09-10 14:57:10 +00:00
t-progress.sh t: load shell scripts from $(dirname) instead of 't' 2018-07-10 13:51:40 -05:00
t-prune-worktree.sh tasklog/log.go: print "done" messages with a trailing period 2019-08-23 17:04:37 -04:00
t-prune.sh tasklog/log.go: print "done" messages with a trailing period 2019-08-23 17:04:37 -04:00
t-pull.sh t: fix flaky tests in CI 2019-10-30 20:21:12 +00:00
t-push-bad-dns.sh t: load shell scripts from $(dirname) instead of 't' 2018-07-10 13:51:40 -05:00
t-push-failures-local.sh Don't fail if we lack objects the server has 2019-07-15 20:47:04 +00:00
t-push-failures-remote.sh t: avoid using shell variables in printf's first argument 2018-09-10 14:57:10 +00:00
t-push-file-with-branch-name.sh t: load shell scripts from $(dirname) instead of 't' 2018-07-10 13:51:40 -05:00
t-push.sh tq: add exponential backoff for retries 2020-04-15 14:10:16 -07:00
t-reference-clone.sh t: avoid using shell variables in printf's first argument 2018-09-10 14:57:10 +00:00
t-resume-http-range.sh tq: retry on oversize file 2019-02-22 14:46:10 +00:00
t-resume-tus.sh t: avoid using shell variables in printf's first argument 2018-09-10 14:57:10 +00:00
t-smudge.sh Fix remote autoselection when not on a branch 2019-08-07 15:49:37 +00:00
t-ssh.sh t: avoid using shell variables in printf's first argument 2018-09-10 14:57:10 +00:00
t-standalone-file.sh Add support for local paths 2019-11-14 17:23:12 +00:00
t-status.sh Clarify output shown by git lfs status 2019-12-15 21:59:53 -08:00
t-submodule-lfsconfig.sh t: avoid using shell variables in printf's first argument 2018-09-10 14:57:10 +00:00
t-submodule-recurse.sh Test submodule.recurse option 2020-03-10 01:37:20 +01:00
t-submodule.sh t: switch several tests to use canonical names 2019-09-09 14:30:55 +00:00
t-track-attrs.sh t: load shell scripts from $(dirname) instead of 't' 2018-07-10 13:51:40 -05:00
t-track-wildcards.sh t: load shell scripts from $(dirname) instead of 't' 2018-07-10 13:51:40 -05:00
t-track.sh track: detect duplicate patterns with --filename 2020-01-23 16:47:41 +00:00
t-umask.sh TST: Trim security context when checking permissions. 2019-01-15 01:20:13 -05:00
t-uninstall.sh commands/uninstall: add a --skip-repo option 2018-10-17 18:53:04 +00:00
t-unlock.sh Allow locking/unlocking of nonexistent files 2020-05-10 19:41:36 -07:00
t-untrack.sh Fix a redirection typo which has plagued the poor t-untrack.sh before it infects the other kids 2018-08-21 18:10:40 +03:00
t-unusual-filenames.sh t: load shell scripts from $(dirname) instead of 't' 2018-07-10 13:51:40 -05:00
t-update.sh t: load shell scripts from $(dirname) instead of 't' 2018-07-10 13:51:40 -05:00
t-upload-redirect.sh fix upload retry 'file already closed' issue' 2020-02-26 11:13:54 +08:00
t-verify.sh t: avoid using shell variables in printf's first argument 2018-09-10 14:57:10 +00:00
t-version.sh t: load shell scripts from $(dirname) instead of 't' 2018-07-10 13:51:40 -05:00
t-worktree.sh Fix unittest expected results 2019-12-12 19:10:44 +09:00
t-zero-len-file.sh t: avoid using shell variables in printf's first argument 2018-09-10 14:57:10 +00:00
testenv.sh tasklog: don't log progress status when stdout is not a tty 2018-11-14 14:35:29 -08:00
testhelpers.sh t: add a test helper to print the canonical path 2019-09-09 14:30:54 +00:00
testlib.sh t: add an environment variable to dump test output 2018-09-18 20:48:18 +00:00

t

This directory contains one of the two types of tests that the Git LFS project uses to protect against regression. The first, scattered in *_test.go files throughout the repository are unit tests, and written in Go, 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.

You can run all tests in this directory with any of the following:

$ make
$ make test
$ make PROVE_EXTRA_ARGS=-j9 test

Or 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.sh

Alternatively, 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-*.sh

Test File(s)

There are a few important kinds of files to know about in the t 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 t/cmd/testutils.go is automatically linked and included during the build process of each file in cmd.

  • 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,. t/t-push.sh, t/t-pull.sh, etc.)

  • testenv.sh: loads environment variables useful during tests. This file is sourced by testlib.sh.

  • testhelpers.sh: loads shell functions useful during tests, like setup_remote_repo, and clone_repo.

  • testlib.sh: loads the begin_test, end_test, and similar functions useful for instantiating a particular test.

Test Lifecycle

When a test is run, the following occurs, in order:

  1. Missing test binaries are compiled into the bin directory in the repository root. Note: this does not include the git-lfs binary, which is re-compiled via script/boostrap.

  2. An integration server is started by either (1) the Makefile or (2) the cmd/lfstest-count-test.go program, which keeps track of the number of running tests and starts an integration server any time the number of active tests goes from 0 to 1, and stops the server when it goes from n to 0.

  3. After sourcing t/testlib.sh (& loading t/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.)

  4. An individual test will finish, and (if running under prove) another will be started in its place. Once all tests are done, t/test_count will go to 0, and the test server will be torn down.

Test Environment

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 a tmp directory and the remote repository data in test/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.

Writing new tests

A new test file should be named t/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