port push tests

This commit is contained in:
Rick Olson 2015-05-26 15:09:24 -06:00
parent 736ed89a90
commit aa563200a8
2 changed files with 63 additions and 130 deletions

@ -1,130 +0,0 @@
package commands
import (
"io/ioutil"
"path/filepath"
"strings"
"testing"
)
func TestPushWithEmptyQueue(t *testing.T) {
repo := NewRepository(t, "empty")
defer repo.Test()
cmd := repo.Command("push", "origin", "master")
cmd.Output = ""
}
func TestPushToMaster(t *testing.T) {
repo := NewRepository(t, "empty")
defer repo.Test()
cmd := repo.Command("push", "--dry-run", "origin", "master")
cmd.Output = "push a.dat"
cmd.Before(func() {
repo.GitCmd("remote", "remove", "origin")
originPath := filepath.Join(Root, "commands", "repos", "empty.git")
repo.GitCmd("remote", "add", "origin", originPath)
repo.GitCmd("fetch")
repo.WriteFile(filepath.Join(repo.Path, ".gitattributes"), "*.dat filter=lfs -crlf\n")
// Add a Git LFS file
repo.WriteFile(filepath.Join(repo.Path, "a.dat"), "some data")
repo.GitCmd("add", "a.dat")
repo.GitCmd("commit", "-m", "a")
})
}
func TestPushToNewBranch(t *testing.T) {
repo := NewRepository(t, "empty")
defer repo.Test()
cmd := repo.Command("push", "--dry-run", "origin", "newbranch")
cmd.Output = "push a.dat\npush b.dat"
cmd.Before(func() {
repo.GitCmd("remote", "remove", "origin")
originPath := filepath.Join(Root, "commands", "repos", "empty.git")
repo.GitCmd("remote", "add", "origin", originPath)
repo.GitCmd("fetch")
repo.WriteFile(filepath.Join(repo.Path, ".gitattributes"), "*.dat filter=lfs -crlf\n")
repo.GitCmd("add", ".gitattributes")
repo.GitCmd("commit", "-m", "attributes")
// Add a Git LFS file
repo.WriteFile(filepath.Join(repo.Path, "a.dat"), "some data")
repo.GitCmd("add", "a.dat")
repo.GitCmd("commit", "-m", "a")
// Branch off
repo.GitCmd("checkout", "-b", "newbranch")
repo.WriteFile(filepath.Join(repo.Path, "b.dat"), "some more data")
repo.GitCmd("add", "b.dat")
repo.GitCmd("commit", "-m", "b")
})
}
func TestPushStdin(t *testing.T) {
repo := NewRepository(t, "empty")
defer repo.Test()
cmd := repo.Command("push", "--stdin", "--dry-run", "origin", "https://git-remote.com")
cmd.Input = strings.NewReader("refs/heads/master master refs/heads/master 2206c37dddba83f58b1ada72709a6b60cf8b058e")
cmd.Output = ""
prePushHookFile := filepath.Join(repo.Path, ".git", "hooks", "pre-push")
cmd.Before(func() {
err := ioutil.WriteFile(prePushHookFile, []byte("#!/bin/sh\ngit lfs push --stdin \"$@\"\n"), 0755)
if err != nil {
t.Fatalf("Error writing pre-push in Before(): %s", err)
}
})
cmd.After(func() {
by, err := ioutil.ReadFile(prePushHookFile)
if err != nil {
t.Fatalf("Error writing pre-push in After(): %s", err)
}
if string(by) != "#!/bin/sh\ngit lfs pre-push \"$@\"\n" {
t.Errorf("Unexpected pre-push hook:\n%s", string(by))
}
})
}
func TestPushStdinWithUnexpectedHook(t *testing.T) {
repo := NewRepository(t, "empty")
defer repo.Test()
cmd := repo.Command("push", "--stdin", "--dry-run", "origin", "https://git-remote.com")
cmd.Input = strings.NewReader("refs/heads/master master refs/heads/master 2206c37dddba83f58b1ada72709a6b60cf8b058e")
cmd.Output = ""
prePushHookFile := filepath.Join(repo.Path, ".git", "hooks", "pre-push")
cmd.Before(func() {
err := ioutil.WriteFile(prePushHookFile, []byte("sup\n"), 0755)
if err != nil {
t.Fatalf("Error writing pre-push in Before(): %s", err)
}
})
cmd.After(func() {
by, err := ioutil.ReadFile(prePushHookFile)
if err != nil {
t.Fatalf("Error writing pre-push in After(): %s", err)
}
if string(by) != "sup\n" {
t.Errorf("Unexpected pre-push hook:\n%s", string(by))
}
})
}

63
test/test-push.sh Executable file

@ -0,0 +1,63 @@
#!/bin/sh
. "test/testlib.sh"
begin_test "push"
(
set -e
reponame="$(basename "$0" ".sh")"
setup_remote_repo "$reponame"
clone_repo "$reponame" repo
git lfs track "*.dat"
echo "push a" > a.dat
git add .gitattributes a.dat
git commit -m "add a.dat"
git lfs push origin master 2>&1 |
tee push.log |
grep "(1 of 1 files) 7 B / 7 B 100.00 %" || {
cat push.log
exit 1
}
git checkout -b push-b
echo "push b" > b.dat
git add b.dat
git commit -m "add b.dat"
git lfs push origin push-b 2>&1 |
tee push.log |
grep "(2 of 2 files) 14 B / 14 B 100.00 %" || {
cat push.log
exit 1
}
)
end_test
begin_test "push dry-run"
(
set -e
reponame="$(basename "$0" ".sh")-dry-run"
setup_remote_repo "$reponame"
clone_repo "$reponame" repo-dry-run
git lfs track "*.dat"
echo "push a" > a.dat
git add .gitattributes a.dat
git commit -m "add a.dat"
[ "push a.dat" == "$(git lfs push --dry-run origin master 2>&1)" ]
git checkout -b push-b
echo "push b" > b.dat
git add b.dat
git commit -m "add b.dat"
git lfs push --dry-run origin push-b 2>&1 | tee push.log
grep "push a.dat" push.log
grep "push b.dat" push.log
)
end_test