git-lfs/commands/clean_test.go

50 lines
1.1 KiB
Go
Raw Normal View History

2014-06-04 18:53:57 +00:00
package commands
import (
"bytes"
"github.com/bmizerany/assert"
"io/ioutil"
2014-06-04 19:03:47 +00:00
"os"
2014-06-04 18:53:57 +00:00
"path/filepath"
"testing"
)
func TestClean(t *testing.T) {
repo := NewRepository(t, "empty")
2014-06-04 18:57:20 +00:00
defer repo.Test()
2014-06-04 18:53:57 +00:00
content := "HI\n"
oid := "f712374589a4f37f0fd6b941a104c7ccf43f68b1fdecb4d5cd88b80acbf98fc2"
2014-06-04 19:03:47 +00:00
prePushHookFile := filepath.Join(repo.Path, ".git", "hooks", "pre-push")
2014-06-04 18:53:57 +00:00
2014-08-07 17:01:06 +00:00
cmd := repo.Command("clean", "somefile")
2014-06-04 18:53:57 +00:00
cmd.Input = bytes.NewBufferString(content)
2014-08-14 17:15:22 +00:00
cmd.Output = `version http://git-media.io/v/2
oid sha256:` + oid + `
size 3`
2014-06-04 18:53:57 +00:00
cmd.After(func() {
2014-06-04 19:03:47 +00:00
// assert hooks
stat, err := os.Stat(prePushHookFile)
assert.Equal(t, nil, err)
assert.Equal(t, false, stat.IsDir())
2014-06-04 18:53:57 +00:00
})
cmd = repo.Command("clean")
cmd.Input = bytes.NewBufferString(content)
2014-08-14 17:15:22 +00:00
cmd.Output = `version http://git-media.io/v/2
oid sha256:` + oid + `
size 3`
customHook := []byte("echo 'yo'")
cmd.Before(func() {
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 18:53:57 +00:00
}