commands,t: add migrate info --top option tests
We can simplify one line in the migrateInfoCommand() function where it resets the "entries" list of informational entries to be output to include no more entries than the setting of the --top option, because we have already clamped the migrateInfoTopN value to be between zero and the total number of entries. So we can drop the second call to tools.MaxInt() here; there is no chance migrateInfoTopN could be less than zero at this point. To confirm our changes and any future ones work as advertised, we then add one test and revise one other. The new test checks that the --top option works in multiple cases, including when its value is zero or below zero, or when it is greater than the number of available entries to be printed by the "git lfs migrate info" command. The revised test is changed so that it confirms that only the highest available entry is printed when --top=1 is specified. Previously, because the --above option is also set in this test, there was only one matching entry to be printed, and so the --top=1 was redundant. If --top=2 had been specified, the test would still have passed.
This commit is contained in:
parent
552614aee8
commit
b8f8686c6b
@ -108,7 +108,7 @@ func migrateInfoCommand(cmd *cobra.Command, args []string) {
|
||||
|
||||
migrateInfoTopN = tools.ClampInt(migrateInfoTopN, 0, len(entries))
|
||||
|
||||
entries = entries[:tools.MaxInt(0, migrateInfoTopN)]
|
||||
entries = entries[:migrateInfoTopN]
|
||||
|
||||
entries.Print(os.Stdout)
|
||||
}
|
||||
|
@ -282,10 +282,52 @@ begin_test "migrate info (above threshold, top)"
|
||||
|
||||
setup_multiple_local_branches
|
||||
|
||||
base64 < /dev/urandom | head -c 160 > b.bin
|
||||
git add b.bin
|
||||
git commit -m "b.bin"
|
||||
|
||||
original_head="$(git rev-parse HEAD)"
|
||||
|
||||
# Ensure command reports only single highest entry due to --top=1 argument.
|
||||
diff -u <(git lfs migrate info --above=130B --top=1 2>&1 | tail -n 1) <(cat <<-EOF
|
||||
*.md 140 B 1/1 files(s) 100%
|
||||
*.bin 160 B 1/1 files(s) 100%
|
||||
EOF)
|
||||
|
||||
migrated_head="$(git rev-parse HEAD)"
|
||||
|
||||
assert_ref_unmoved "HEAD" "$original_head" "$migrated_head"
|
||||
)
|
||||
end_test
|
||||
|
||||
begin_test "migrate info (top)"
|
||||
(
|
||||
set -e
|
||||
|
||||
setup_multiple_local_branches
|
||||
|
||||
base64 < /dev/urandom | head -c 160 > b.bin
|
||||
git add b.bin
|
||||
git commit -m "b.bin"
|
||||
|
||||
original_head="$(git rev-parse HEAD)"
|
||||
|
||||
# Ensure command reports nothing if --top argument is less than zero.
|
||||
[ "0" -eq "$(git lfs migrate info --everything --top=-1 2>/dev/null | wc -l)" ]
|
||||
|
||||
# Ensure command reports nothing if --top argument is zero.
|
||||
[ "0" -eq "$(git lfs migrate info --everything --top=0 2>/dev/null | wc -l)" ]
|
||||
|
||||
# Ensure command reports no more entries than specified by --top argument.
|
||||
diff -u <(git lfs migrate info --everything --top=2 2>&1 | tail -n 2) <(cat <<-EOF
|
||||
*.md 170 B 2/2 files(s) 100%
|
||||
*.bin 160 B 1/1 files(s) 100%
|
||||
EOF)
|
||||
|
||||
# Ensure command succeeds if --top argument is greater than total number of entries.
|
||||
diff -u <(git lfs migrate info --everything --top=10 2>&1 | tail -n 3) <(cat <<-EOF
|
||||
*.md 170 B 2/2 files(s) 100%
|
||||
*.bin 160 B 1/1 files(s) 100%
|
||||
*.txt 120 B 1/1 files(s) 100%
|
||||
EOF)
|
||||
|
||||
migrated_head="$(git rev-parse HEAD)"
|
||||
|
Loading…
Reference in New Issue
Block a user