git-lfs/commands/path_test.go

67 lines
1.6 KiB
Go
Raw Normal View History

2014-06-04 17:40:09 +00:00
package commands
import (
"github.com/bmizerany/assert"
2014-06-05 16:50:20 +00:00
"io/ioutil"
"os"
2014-06-04 17:40:09 +00:00
"path/filepath"
"testing"
)
func TestPath(t *testing.T) {
repo := NewRepository(t, "attributes")
2014-06-04 18:57:20 +00:00
defer repo.Test()
2014-06-04 17:40:09 +00:00
2014-06-05 16:50:20 +00:00
prePushHookFile := filepath.Join(repo.Path, ".git", "hooks", "pre-push")
customHook := []byte("echo 'yo'")
2014-06-04 17:40:09 +00:00
cmd := repo.Command("path")
cmd.Output = "Listing paths\n" +
" *.mov (.git/info/attributes)\n" +
" *.jpg (.gitattributes)\n" +
" *.gif (a/.gitattributes)\n" +
" *.png (a/b/.gitattributes)"
cmd.Before(func() {
2014-06-05 16:50:20 +00:00
// write attributes file in .git
2014-06-04 17:40:09 +00:00
path := filepath.Join(".git", "info", "attributes")
repo.WriteFile(path, "*.mov filter=media -crlf\n")
2014-06-05 16:50:20 +00:00
// 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))
2014-06-04 17:40:09 +00:00
})
}
func TestPathOnEmptyRepository(t *testing.T) {
repo := NewRepository(t, "empty")
2014-06-04 18:57:20 +00:00
defer repo.Test()
2014-06-04 17:40:09 +00:00
2014-06-05 16:50:20 +00:00
prePushHookFile := filepath.Join(repo.Path, ".git", "hooks", "pre-push")
2014-06-04 17:40:09 +00:00
cmd := repo.Command("path", "add", "*.gif")
cmd.Output = "Adding path *.gif"
cmd.After(func() {
2014-06-05 16:50:20 +00:00
// assert path was added
2014-06-04 17:40:09 +00:00
assert.Equal(t, "*.gif filter=media -crlf\n", repo.ReadFile(".gitattributes"))
expected := "Listing paths\n *.gif (.gitattributes)\n"
assert.Equal(t, expected, repo.MediaCmd("path"))
2014-06-05 16:50:20 +00:00
// assert hook was created
stat, err := os.Stat(prePushHookFile)
assert.Equal(t, nil, err)
assert.Equal(t, false, stat.IsDir())
2014-06-04 17:40:09 +00:00
})
cmd = repo.Command("path")
cmd.Output = "Listing paths"
}