Skip to content

Port tests - #336

Merged
technoweenie merged 14 commits into
masterfrom
port-tests
May 27, 2015
Merged

technoweenie merged 14 commits into
masterfrom
port-tests

Conversation

@technoweenie

Copy link
Copy Markdown
Contributor

This moves all the tests from the commands package to the new shell tests.

  • clean
  • env
  • init - I removed these tests because they test that the global git config is updated. I don't want tests to modify existing global git configs.
  • ls-files
  • pointer
  • pre-push
  • push
  • smudge
  • status
  • update
  • version - also removed, since every test run calls this

@michael-k

Copy link
Copy Markdown
Contributor

I'm not happy with this. Shell scripts are horrible in many ways. Some arguments, why we shouldn't rely on shell scripts:

  • It should be fun to write tests, with shell scripts (for integration tests), it's not.
  • There is no way to see any coverage. (Yeah, there's rarely coverage for integration tests. This means, that we still need *_test.go files to run internal tests on the files in commands/.)
  • Learning shell scripting might be to big an obstacle for some developers.

If there's no way to make the *_test.go files work, I'd vote in favor of separate go files (e.g. one per integration test), executed with go run filename.go. We could still use exec where necessary and would be close to the functionality of shell scripts, but the code would be in go.

@technoweenie

Copy link
Copy Markdown
Contributor Author

Honestly, I'm not a huge fan of the shell tests either. I'd be down for support both sh and go tests so we can experiment with some single file go tests like you suggested. If we find a pattern that works, we can then move tests back to go one by one. But there's nothing about the current Go test stuff that I want to keep.

@technoweenie

Copy link
Copy Markdown
Contributor Author

FWIW here's another attempt at Go tests containing simpler declarative statements like the shell tests.

https://github.com/github/git-lfs/pull/291/files#diff-85b5fd21f7c36d3ba95b3a6fc0225941

I'm merging this so we can move forward on some other PRs. Still open to the idea of exploring single file go tests, though.

technoweenie added a commit that referenced this pull request May 27, 2015
@technoweenie
technoweenie merged commit 7f11548 into master May 27, 2015
@technoweenie
technoweenie deleted the port-tests branch May 27, 2015 19:57
@technoweenie technoweenie mentioned this pull request May 27, 2015
3 tasks done
@michael-k

Copy link
Copy Markdown
Contributor

👍

chrisd8088 added a commit to chrisd8088/git-lfs that referenced this pull request Feb 20, 2024
The "git lfs ls-files" command was added in PR git-lfs#122 (technically,
the precursor "git media ls-files" command) and its test suite
converted to shell tests in PR git-lfs#336; however, the basic functionality
of the command has never had tests which confirm it handles files
in subdirectories appropriately.  (Some tests added in later PRs which
do check files in subdirectories under specific conditions, such as
with the --exclude option or with non-ASCII characters in subdirectory
names.)

As we expect to expand this command's test suite in subsequent commits
in this PR, we first add a new test which simply confirms that the
normal output of the command, and the output with the --debug option,
perform as expected when files have been both added and removed within
a subdirectory.

We also add a test which confirms the same behaviour when the --json
option is used.  The use of a separate test for this option was
preferred in PR git-lfs#5007 when the --json option was first introduced (rather
than overloading the existing tests, as was done for the --debug option
when it was added in PR git-lfs#2540), so we follow that model here as well.
chrisd8088 added a commit to chrisd8088/git-lfs that referenced this pull request Jun 23, 2026
In a prior commit in this PR we introduced a new Go test helper
program named "lfstest-getlimit" which can return the value of
either the size of the read buffer used to decode Git LFS pointers
or the maximum length of a Git packet line.

We can now update a number of tests in our shell test suite to make
use of this helper utility.  Many of these tests previously relied on
hard-coded constants to create test data of various sizes to validate
the Git LFS client's ability to handle filter input data from Git
which fills or does not fill the client's pointer read buffer.

We rewrite one test in particular, the "clean pseudo pointer with
extra data" test in our "t/t-clean.sh" script, because its initial
version was written at a time when the size of the read buffer used
to decode Git LFS pointers was only 512 bytes, and the test has never
been appropriately revised.

The original version of this test was a Go test function named
TestCleanPointerWithWhitespaceAndExtra() that was added in commit
e09e5e1 of PR git-lfs#271.  The Go test
function was first rewritten as part of a shell test in commit
8b54aee of PR git-lfs#336, and then
converted into a separate shell test in commit
a251b2e of PR git-lfs#447.

Later, in commit f58db7f of PR git-lfs#684,
the size of the buffer used by the DecodeFrom() function in the "lfs"
package was changed from 512 bytes to the value specified by the
"blobSizeCutoff" constant.  At that point in time the constant was
already set to its current value of 1024 bytes.  However, the
"clean pseudo pointer with extra data" test was never updated to
reflect the larger size of the pointer read buffer.

We therefore now rewrite this test to retrieve the size of the
pointer read buffer using our new "lfstest-getlimit" utility, and
then create an invalid pointer larger than the size of the buffer.
Note that the test is intended in part to check that the client
ignores the fact that the initial portion of the input data appears
to be a valid Git LFS pointer.  The exact content of this initial
portion is not significant, however, so we change the value of the
"size" field in the invalid pointer from 1024 to 9999, which more
clearly indicates that this value is arbitrary and not related
to the size of the client's read buffer.

What is important for the soundness of the test, though, is that the
total length of the invalid pointer data exceeds the buffer's size.
To align with the original design of the test, we insert a large
number of linefeed characters after the initial portion of the test
data, which requires us to work around the fact that the shell will
strip trailing whitespace from a command substitution.  To avoid our
linefeed characters being removed from the value we assign to the
"fill" shell variable, we append the string "EOF", and then remove
this suffix when interpolating the variable's value into the final
version of the test data that we pass to the "git lfs clean" command.

To maintain consistency between our tests, we also update the
preceding "clean pseudo pointer" test in the "t/t-clean.sh" script to
change the arbitrary value of the "size" field in its invalid pointer
data from 1024 to 9999.  This test's invalid pointer data is not
intended to exceed the size of the client's read buffer, so we do
not need to invoke our new "lfstest-getlimit" helper utility.  The
data only needs to begin with an apparently valid set of pointer fields,
but as with the following test, the exact value of the "size" field is
not significant, which is more clearly indicated by the value 9999.

Both of these tests previously used hard-coded SHA-256 hash values
to check the output of the "git lfs clean" command, which should
simply process the invalid pointer data as a regular file and not
a Git LFS pointer.  Since we have changed the input data in both
tests, we need to recalculate the expected SHA-256 hashes.  While
we could continue to use hard-coded hash values, we instead make use
of our test helper functions to now calculate these hash values
dynamically.

We then update a number of other tests in several scripts to make
use of our new "lfstest-getlimit" helper utility.  All of these
tests previously used hard-coded values to create data of a specific
length in order to demonstrate that the Git LFS client does not
exhibit undesired behaviour when its input data fills or does not
fill a given internal buffer.

Note, though, that in the "malformed pointers" test we still have
one instance where we create a file of a specific size using a
hard-coded constant value.  In this instance, the test checks that
the Git LFS client can process invalid pointer data from Git which
exceeds the default capacity of a pipe, which is normally 64 kB,
at least on Linux and macOS.

We should be able to dynamically determine the capacity of a pipe
on Linux using the fcntl(2) system call and the F_GETPIPE_SZ operation,
and on Windows using the GetNamedPipeInfo() system call and the
"lpInBufferSize" and "lpOutBufferSize" parameters:

  https://man7.org/linux/man-pages/man2/F_GETPIPE_SZ.2const.html
  https://learn.microsoft.com/en-us/windows/win32/api/namedpipeapi/nf-namedpipeapi-getnamedpipeinfo#parameters

However, on macOS we would apparently have to experimentally feed
data into a pipe to try to determine the pipe's capacity.  This is
beyond the scope of the current PR, though, so for the present
time we leave this one instance of a hard-coded buffer size in
our shell tests.  We add a comment which explains the intent of this
check, however, as a reminder to revisit this issue in the future.

To help clarify the behaviour of the many tests where we simply need
to generate a file of a specific length, we now adopt the use of the
head(1) command to read a specific number of zero bytes from the
"/dev/zero" pseudo-device instead of using the dd(1) command as we
have done previously.  The result is the same in all cases, but the
"dd" command requires several somewhat obscure options, while the
"head" command only requires a single byte-count argument.

In addition to these changes to the tests, we also add or update
the comments in the tests.  In each case, we try to more fully
document the purpose of the test, with links to the original issues
and PRs for which the test was developed.

Finally, we revise the names of two of the tests in our
"t/t-filter-process.sh" script.  We rename the "filter process: add a
file with 1024 bytes" test to "filter process: non-pointer file of
maximum pointer size", since the size of the file created by the test
is now variable rather than fixed, and the intent of the test is
to check that the Git LFS client properly handles filter input which
happens to be exactly the same size as that of the pointer read
buffer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants