replace track tests
This commit is contained in:
parent
615b4d814e
commit
14e4d00b72
@ -1,105 +0,0 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/bmizerany/assert"
|
||||
)
|
||||
|
||||
func TestTrack(t *testing.T) {
|
||||
repo := NewRepository(t, "attributes")
|
||||
defer repo.Test()
|
||||
|
||||
prePushHookFile := filepath.Join(repo.Path, ".git", "hooks", "pre-push")
|
||||
customHook := []byte("echo 'yo'")
|
||||
|
||||
cmd := repo.Command("track")
|
||||
cmd.Output = "Listing tracked paths\n" +
|
||||
" *.mov (.git/info/attributes)\n" +
|
||||
" *.jpg (.gitattributes)\n" +
|
||||
" *.gif (a/.gitattributes)\n" +
|
||||
" *.png (a/b/.gitattributes)"
|
||||
|
||||
cmd.Before(func() {
|
||||
// write attributes file in .git
|
||||
path := filepath.Join(".git", "info", "attributes")
|
||||
repo.WriteFile(path, "*.mov filter=lfs -crlf\n")
|
||||
|
||||
// add hook
|
||||
err := ioutil.WriteFile(prePushHookFile, customHook, 0755)
|
||||
assert.Equal(t, nil, err)
|
||||
})
|
||||
|
||||
cmd.After(func() {
|
||||
by, err := ioutil.ReadFile(prePushHookFile)
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Equal(t, string(customHook), string(by))
|
||||
})
|
||||
}
|
||||
|
||||
func TestTrackOnEmptyRepository(t *testing.T) {
|
||||
repo := NewRepository(t, "empty")
|
||||
defer repo.Test()
|
||||
|
||||
prePushHookFile := filepath.Join(repo.Path, ".git", "hooks", "pre-push")
|
||||
|
||||
cmd := repo.Command("track", "*.gif")
|
||||
cmd.Output = "Tracking *.gif"
|
||||
|
||||
cmd.Before(func() {
|
||||
// write attributes file in .git
|
||||
path := filepath.Join(".gitattributes")
|
||||
repo.WriteFile(path, "*.mov filter=lfs diff=lfs merge=lfs -crlf\n")
|
||||
})
|
||||
|
||||
cmd.After(func() {
|
||||
// assert path was added
|
||||
assert.Equal(t, "*.mov filter=lfs diff=lfs merge=lfs -crlf\n*.gif filter=lfs diff=lfs merge=lfs -crlf\n", repo.ReadFile(".gitattributes"))
|
||||
|
||||
expected := "Listing tracked paths\n *.mov (.gitattributes)\n *.gif (.gitattributes)\n"
|
||||
|
||||
assert.Equal(t, expected, repo.MediaCmd("track"))
|
||||
|
||||
// assert hook was created
|
||||
stat, err := os.Stat(prePushHookFile)
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Equal(t, false, stat.IsDir())
|
||||
})
|
||||
|
||||
cmd = repo.Command("track")
|
||||
cmd.Output = "Listing tracked paths"
|
||||
}
|
||||
|
||||
func TestTrackWithoutTrailingLinebreak(t *testing.T) {
|
||||
repo := NewRepository(t, "empty")
|
||||
defer repo.Test()
|
||||
|
||||
prePushHookFile := filepath.Join(repo.Path, ".git", "hooks", "pre-push")
|
||||
|
||||
cmd := repo.Command("track", "*.gif")
|
||||
cmd.Output = "Tracking *.gif"
|
||||
|
||||
cmd.Before(func() {
|
||||
repo.WriteFile(".gitattributes", "*.mov filter=lfs -crlf")
|
||||
})
|
||||
|
||||
cmd.After(func() {
|
||||
// assert path was added
|
||||
assert.Equal(t, "*.mov filter=lfs -crlf\n*.gif filter=lfs diff=lfs merge=lfs -crlf\n", repo.ReadFile(".gitattributes"))
|
||||
|
||||
expected := "Listing tracked paths\n *.mov (.gitattributes)\n *.gif (.gitattributes)\n"
|
||||
|
||||
assert.Equal(t, expected, repo.MediaCmd("track"))
|
||||
|
||||
// assert hook was created
|
||||
stat, err := os.Stat(prePushHookFile)
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Equal(t, false, stat.IsDir())
|
||||
})
|
||||
|
||||
cmd = repo.Command("track")
|
||||
cmd.Output = "Listing tracked paths"
|
||||
}
|
50
test/test-track.sh
Executable file
50
test/test-track.sh
Executable file
@ -0,0 +1,50 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "test/testlib.sh"
|
||||
|
||||
begin_test "track"
|
||||
(
|
||||
set -e
|
||||
|
||||
# no need to setup a remote repo, since this test doesn't need to push or pull
|
||||
|
||||
mkdir track
|
||||
cd track
|
||||
git init
|
||||
|
||||
git lfs track "*.jpg"
|
||||
cat .gitattributes | grep "*.jpg"
|
||||
mkdir -p a/b
|
||||
|
||||
echo "*.mov filter=lfs -crlf" > .git/info/attributes
|
||||
echo "*.gif filter=lfs -crlf" > a/.gitattributes
|
||||
echo "*.png filter=lfs -crlf" > a/b/.gitattributes
|
||||
|
||||
out=$(git lfs track)
|
||||
echo "$out" | grep "Listing tracked paths"
|
||||
echo "$out" | grep "*.mov (.git/info/attributes)"
|
||||
echo "$out" | grep "*.jpg (.gitattributes)"
|
||||
echo "$out" | grep "*.gif (a/.gitattributes)"
|
||||
echo "$out" | grep "*.png (a/b/.gitattributes)"
|
||||
)
|
||||
end_test
|
||||
|
||||
begin_test "track without trailing linebreak"
|
||||
(
|
||||
set -e
|
||||
|
||||
mkdir no-linebreak
|
||||
cd no-linebreak
|
||||
git init
|
||||
printf "*.mov filter=lfs -crlf" > .gitattributes
|
||||
|
||||
git lfs track "*.gif"
|
||||
|
||||
expected="*.mov filter=lfs -crlf
|
||||
*.gif filter=lfs diff=lfs merge=lfs -crlf"
|
||||
|
||||
if [ "$expected" != "$(cat .gitattributes)" ]; then
|
||||
exit 1
|
||||
fi
|
||||
)
|
||||
end_test
|
Loading…
Reference in New Issue
Block a user