port smudge tests
This commit is contained in:
parent
aa563200a8
commit
645dc9a881
@ -1,100 +0,0 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/bmizerany/assert"
|
||||
)
|
||||
|
||||
func TestSmudge(t *testing.T) {
|
||||
repo := NewRepository(t, "empty")
|
||||
defer repo.Test()
|
||||
|
||||
prePushHookFile := filepath.Join(repo.Path, ".git", "hooks", "pre-push")
|
||||
progressFile := filepath.Join(repo.Path, ".git", "progress")
|
||||
|
||||
// simple smudge example
|
||||
cmd := repo.Command("smudge", "somefile")
|
||||
cmd.Input = bytes.NewBufferString("version https://git-lfs.github.com/spec/v1\noid sha256:SOMEOID\nsize 7\n")
|
||||
cmd.Output = "simple"
|
||||
cmd.Env = append(cmd.Env, "GIT_LFS_PROGRESS="+progressFile)
|
||||
|
||||
cmd.Before(func() {
|
||||
path := filepath.Join(repo.Path, ".git", "lfs", "objects", "SO", "ME")
|
||||
file := filepath.Join(path, "SOMEOID")
|
||||
assert.Equal(t, nil, os.MkdirAll(path, 0755))
|
||||
assert.Equal(t, nil, ioutil.WriteFile(file, []byte("simple\n"), 0755))
|
||||
})
|
||||
|
||||
cmd.After(func() {
|
||||
// assert hook is created
|
||||
stat, err := os.Stat(prePushHookFile)
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Equal(t, false, stat.IsDir())
|
||||
|
||||
// assert progress file
|
||||
progress, err := ioutil.ReadFile(progressFile)
|
||||
assert.Equal(t, nil, err)
|
||||
progLines := bytes.Split(progress, []byte("\n"))
|
||||
assert.Equal(t, 2, len(progLines))
|
||||
assert.Equal(t, "smudge 1/1 7/7 somefile", string(progLines[0]))
|
||||
assert.Equal(t, "", string(progLines[1]))
|
||||
})
|
||||
|
||||
// smudge with custom hook
|
||||
cmd = repo.Command("smudge")
|
||||
cmd.Input = bytes.NewBufferString("version https://git-lfs.github.com/spec/v1\noid sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393\nsize 9")
|
||||
cmd.Output = "whatever"
|
||||
customHook := []byte("echo 'yo'")
|
||||
|
||||
cmd.Before(func() {
|
||||
path := filepath.Join(repo.Path, ".git", "lfs", "objects", "4d", "7a")
|
||||
file := filepath.Join(path, "4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393")
|
||||
assert.Equal(t, nil, os.MkdirAll(path, 0755))
|
||||
assert.Equal(t, nil, ioutil.WriteFile(file, []byte("whatever\n"), 0755))
|
||||
assert.Equal(t, nil, ioutil.WriteFile(prePushHookFile, customHook, 0755))
|
||||
})
|
||||
|
||||
cmd.After(func() {
|
||||
// assert custom hook is not overwritten
|
||||
by, err := ioutil.ReadFile(prePushHookFile)
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Equal(t, string(customHook), string(by))
|
||||
})
|
||||
}
|
||||
|
||||
func TestSmudgeInfo(t *testing.T) {
|
||||
repo := NewRepository(t, "empty")
|
||||
defer repo.Test()
|
||||
|
||||
mediaPath := filepath.Join(repo.Path, ".git", "lfs", "objects", "4d", "7a")
|
||||
mediaFile := filepath.Join(mediaPath, "4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393")
|
||||
|
||||
// smudge --info with Git LFS pointer format, without local file
|
||||
cmd := repo.Command("smudge", "--info")
|
||||
cmd.Input = bytes.NewBufferString("version https://git-lfs.github.com/spec/v1\noid sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393\nsize 123\n")
|
||||
cmd.Output = "123 --"
|
||||
|
||||
// smudge --info with Git LFS pointer format, with local file
|
||||
cmd = repo.Command("smudge", "--info")
|
||||
cmd.Input = bytes.NewBufferString("version https://git-lfs.github.com/spec/v1\noid sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393\nsize 123\n")
|
||||
cmd.Output = "9 " + mediaFile
|
||||
|
||||
cmd.Before(func() {
|
||||
assert.Equal(t, nil, os.MkdirAll(mediaPath, 0755))
|
||||
assert.Equal(t, nil, ioutil.WriteFile(mediaFile, []byte("whatever\n"), 0755))
|
||||
})
|
||||
}
|
||||
|
||||
func TestSmudgePassesInvalidData(t *testing.T) {
|
||||
repo := NewRepository(t, "empty")
|
||||
defer repo.Test()
|
||||
|
||||
cmd := repo.Command("smudge", "somefile")
|
||||
cmd.Input = bytes.NewBufferString("this is not a pointer file\n")
|
||||
cmd.Output = "this is not a pointer file"
|
||||
}
|
48
test/test-smudge.sh
Executable file
48
test/test-smudge.sh
Executable file
@ -0,0 +1,48 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "test/testlib.sh"
|
||||
|
||||
begin_test "smudge"
|
||||
(
|
||||
set -e
|
||||
|
||||
reponame="$(basename "$0" ".sh")"
|
||||
setup_remote_repo "$reponame"
|
||||
clone_repo "$reponame" repo
|
||||
|
||||
git lfs track "*.dat"
|
||||
echo "smudge a" > a.dat
|
||||
git add .gitattributes a.dat
|
||||
git commit -m "add a.dat"
|
||||
|
||||
# smudge works even though it hasn't been pushed, by reading from .git/lfs/objects
|
||||
output="$(pointer fcf5015df7a9089a7aa7fe74139d4b8f7d62e52d5a34f9a87aeffc8e8c668254 9 | git lfs smudge)"
|
||||
[ "smudge a" == "$output" ]
|
||||
|
||||
git push origin master
|
||||
|
||||
# download it from the git lfs server
|
||||
rm -rf .git/lfs/objects
|
||||
output="$(pointer fcf5015df7a9089a7aa7fe74139d4b8f7d62e52d5a34f9a87aeffc8e8c668254 9 | git lfs smudge)"
|
||||
[ "smudge a" == "$output" ]
|
||||
)
|
||||
end_test
|
||||
|
||||
begin_test "smudge --info"
|
||||
(
|
||||
set -e
|
||||
|
||||
cd repo
|
||||
output="$(pointer aaaaa15df7a9089a7aa7fe74139d4b8f7d62e52d5a34f9a87aeffc8e8c668254 123 | git lfs smudge --info)"
|
||||
[ "123 --" == "$output" ]
|
||||
)
|
||||
end_test
|
||||
|
||||
begin_test "smudge with invalid pointer"
|
||||
(
|
||||
set -e
|
||||
|
||||
cd repo
|
||||
[ "wat" == "$(echo "wat" | git lfs smudge)" ]
|
||||
)
|
||||
end_test
|
Loading…
Reference in New Issue
Block a user