6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-05 10:48:47 +00:00
Files
git-get/new/status_test.go
2020-05-28 16:21:07 +02:00

150 lines
3.1 KiB
Go

package new
import (
"reflect"
"testing"
)
func TestStatus(t *testing.T) {
var tests = []struct {
makeTestRepo func(*testing.T) *TestRepo
want *RepoStatus
}{
{NewRepoEmpty, &RepoStatus{
HasUntrackedFiles: false,
HasUncommittedChanges: false,
Branches: nil,
}},
{NewRepoWithUntracked, &RepoStatus{
HasUntrackedFiles: true,
HasUncommittedChanges: false,
Branches: nil,
}},
{NewRepoWithStaged, &RepoStatus{
HasUntrackedFiles: false,
HasUncommittedChanges: true,
Branches: nil,
}},
{NewRepoWithCommit, &RepoStatus{
HasUntrackedFiles: false,
HasUncommittedChanges: false,
Branches: []*BranchStatus{
{
Name: "master",
Upstream: "",
NeedsPull: false,
NeedsPush: false,
},
},
}},
{NewRepoWithModified, &RepoStatus{
HasUntrackedFiles: false,
HasUncommittedChanges: true,
Branches: []*BranchStatus{
{
Name: "master",
Upstream: "",
NeedsPull: false,
NeedsPush: false,
},
},
}},
{NewRepoWithIgnored, &RepoStatus{
HasUntrackedFiles: false,
HasUncommittedChanges: false,
Branches: []*BranchStatus{
{
Name: "master",
Upstream: "",
NeedsPull: false,
NeedsPush: false,
},
},
}},
{NewRepoWithLocalBranch, &RepoStatus{
HasUntrackedFiles: false,
HasUncommittedChanges: false,
Branches: []*BranchStatus{
{
Name: "local",
Upstream: "",
NeedsPull: false,
NeedsPush: false,
}, {
Name: "master",
Upstream: "",
NeedsPull: false,
NeedsPush: false,
},
},
}},
{NewRepoWithClonedBranch, &RepoStatus{
HasUntrackedFiles: false,
HasUncommittedChanges: false,
Branches: []*BranchStatus{
{
Name: "local",
Upstream: "",
NeedsPull: false,
NeedsPush: false,
}, {
Name: "master",
Upstream: "origin/master",
NeedsPull: false,
NeedsPush: false,
},
},
}},
{NewRepoWithBranchAhead, &RepoStatus{
HasUntrackedFiles: false,
HasUncommittedChanges: false,
Branches: []*BranchStatus{
{
Name: "master",
Upstream: "origin/master",
NeedsPull: false,
NeedsPush: true,
},
},
}},
{NewRepoWithBranchBehind, &RepoStatus{
HasUntrackedFiles: false,
HasUncommittedChanges: false,
Branches: []*BranchStatus{
{
Name: "master",
Upstream: "origin/master",
NeedsPull: true,
NeedsPush: false,
},
},
}},
{NewRepoWithBranchAheadAndBehind, &RepoStatus{
HasUntrackedFiles: false,
HasUncommittedChanges: false,
Branches: []*BranchStatus{
{
Name: "master",
Upstream: "origin/master",
NeedsPull: true,
NeedsPush: true,
},
},
}},
}
for _, test := range tests {
tr := test.makeTestRepo(t)
repo, err := OpenRepo(tr.Path)
checkFatal(t, err)
err = repo.LoadStatus()
checkFatal(t, err)
if !reflect.DeepEqual(repo.Status, test.want) {
t.Errorf("Wrong repo status, got: %+v; want: %+v", repo.Status, test.want)
}
}
}