766c22dfa9
* Use test.Repo and AddCommits to set up complex multi-branch tests * Can commit in the past for history tests, branch, merge and tag * Can generate random data for files or use what you give it * Returns full detail of the commits created including SHAs and OIDs * Can pipe JSON from a batch file into lfstest-testutils to get the same functionality in acceptance tests * get_date bash util to create commit dates easily on BSD/Mac and GNU * see test-push.sh for bash example and scanner_git_test.go for go test
77 lines
2.1 KiB
Go
77 lines
2.1 KiB
Go
package lfs_test // to avoid import cycles
|
|
|
|
// This is for doing complete git-level tests using test utils
|
|
// Needs to be a separate file from scanner_test so that we can use a diff package
|
|
// which avoids import cycles with testutils
|
|
|
|
import (
|
|
"testing"
|
|
|
|
. "github.com/github/git-lfs/lfs"
|
|
"github.com/github/git-lfs/test"
|
|
"github.com/github/git-lfs/vendor/_nuts/github.com/technoweenie/assert"
|
|
)
|
|
|
|
func TestScanUnpushed(t *testing.T) {
|
|
repo := test.NewRepo(t)
|
|
repo.Pushd()
|
|
defer func() {
|
|
repo.Popd()
|
|
repo.Cleanup()
|
|
}()
|
|
|
|
inputs := []*test.CommitInput{
|
|
{ // 0
|
|
Files: []*test.FileInput{
|
|
{Filename: "file1.txt", Size: 20},
|
|
},
|
|
},
|
|
{ // 1
|
|
NewBranch: "branch2",
|
|
Files: []*test.FileInput{
|
|
{Filename: "file1.txt", Size: 25},
|
|
},
|
|
},
|
|
{ // 2
|
|
ParentBranches: []string{"master"}, // back on master
|
|
Files: []*test.FileInput{
|
|
{Filename: "file1.txt", Size: 30},
|
|
},
|
|
},
|
|
{ // 3
|
|
NewBranch: "branch3",
|
|
Files: []*test.FileInput{
|
|
{Filename: "file1.txt", Size: 32},
|
|
},
|
|
},
|
|
}
|
|
repo.AddCommits(inputs)
|
|
|
|
// Add a couple of remotes and test state depending on what's pushed
|
|
repo.AddRemote("origin")
|
|
repo.AddRemote("upstream")
|
|
|
|
pointers, err := ScanUnpushed()
|
|
assert.Equal(t, nil, err, "Should be no error calling ScanUnpushed")
|
|
assert.Equal(t, 4, len(pointers), "Should be 4 pointers because none pushed")
|
|
|
|
test.RunGitCommand(t, true, "push", "origin", "branch2")
|
|
// Branch2 will have pushed 2 commits
|
|
pointers, err = ScanUnpushed()
|
|
assert.Equal(t, nil, err, "Should be no error calling ScanUnpushed")
|
|
assert.Equal(t, 2, len(pointers), "Should be 2 pointers")
|
|
|
|
test.RunGitCommand(t, true, "push", "upstream", "master")
|
|
// Master pushes 1 more commit
|
|
pointers, err = ScanUnpushed()
|
|
assert.Equal(t, nil, err, "Should be no error calling ScanUnpushed")
|
|
assert.Equal(t, 1, len(pointers), "Should be 1 pointer")
|
|
|
|
test.RunGitCommand(t, true, "push", "origin", "branch3")
|
|
// All pushed (somewhere)
|
|
pointers, err = ScanUnpushed()
|
|
assert.Equal(t, nil, err, "Should be no error calling ScanUnpushed")
|
|
assert.Equal(t, 0, len(pointers), "Should be 0 pointers unpushed")
|
|
|
|
}
|