6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-04 20:19:42 +00:00

Simplify RepoStatus unit tests

This commit is contained in:
Grzegorz Dlugoszewski
2020-05-19 11:22:41 +02:00
parent 17ec470340
commit a0f09ef74d
2 changed files with 37 additions and 26 deletions

View File

@@ -11,7 +11,7 @@ type RepoStatus struct {
BranchStatuses []BranchStatus
}
func Status(path string) (RepoStatus, error) {
func NewRepoStatus(path string) (RepoStatus, error) {
var status RepoStatus
repo, err := git.OpenRepository(path)

View File

@@ -1,6 +1,7 @@
package main
import (
"reflect"
"testing"
git "github.com/libgit2/git2go/v30"
@@ -16,15 +17,17 @@ func TestStatusWithEmptyRepo(t *testing.T) {
t.Errorf("Empty repo should have no status entries")
}
status, err := Status(repo.Workdir())
status, err := NewRepoStatus(repo.Workdir())
checkFatal(t, err)
if status.HasUntrackedFiles != false {
t.Errorf("Repo should not have untracked files")
want := RepoStatus{
HasUntrackedFiles: false,
HasUncommittedChanges: false,
BranchStatuses: nil,
}
if status.HasUncommittedChanges != false {
t.Errorf("Repo should not have uncommitted changes")
if !reflect.DeepEqual(status, want) {
t.Errorf("Wrong repo status, got %+v; want %+v", status, want)
}
}
@@ -43,15 +46,17 @@ func TestStatusWithUntrackedFile(t *testing.T) {
t.Errorf("Invalid status, got %d; want %d", entries[0].Status, git.StatusWtNew)
}
status, err := Status(repo.Workdir())
status, err := NewRepoStatus(repo.Workdir())
checkFatal(t, err)
if status.HasUntrackedFiles != true {
t.Errorf("Repo should have untracked files")
want := RepoStatus{
HasUntrackedFiles: true,
HasUncommittedChanges: false,
BranchStatuses: nil,
}
if status.HasUncommittedChanges != false {
t.Errorf("Repo should not have uncommitted changes")
if !reflect.DeepEqual(status, want) {
t.Errorf("Wrong repo status, got %+v; want %+v", status, want)
}
}
@@ -79,15 +84,17 @@ func TestStatusWithStagedFile(t *testing.T) {
t.Errorf("Invalid status, got %d; want %d", entries[0].Status, git.StatusIndexNew)
}
status, err := Status(repo.Workdir())
status, err := NewRepoStatus(repo.Workdir())
checkFatal(t, err)
if status.HasUntrackedFiles != false {
t.Errorf("Repo should not have untracked files")
want := RepoStatus{
HasUntrackedFiles: false,
HasUncommittedChanges: true,
BranchStatuses: nil,
}
if status.HasUncommittedChanges != true {
t.Errorf("Repo should have uncommitted changes")
if !reflect.DeepEqual(status, want) {
t.Errorf("Wrong repo status, got %+v; want %+v", status, want)
}
}
@@ -104,15 +111,17 @@ func TestStatusWithSingleCommit(t *testing.T) {
t.Errorf("Repo with no uncommitted files should have no status entries")
}
status, err := Status(repo.Workdir())
status, err := NewRepoStatus(repo.Workdir())
checkFatal(t, err)
if status.HasUntrackedFiles != false {
t.Errorf("Repo should not have untracked files")
want := RepoStatus{
HasUntrackedFiles: false,
HasUncommittedChanges: false,
BranchStatuses: nil,
}
if status.HasUncommittedChanges != false {
t.Errorf("Repo should not have uncommitted changes")
if !reflect.DeepEqual(status, want) {
t.Errorf("Wrong repo status, got %+v; want %+v", status, want)
}
}
@@ -131,14 +140,16 @@ func TestStatusWithMultipleCommits(t *testing.T) {
if len(entries) != 0 {
t.Errorf("Repo with no uncommitted files should have no status entries")
}
status, err := Status(repo.Workdir())
status, err := NewRepoStatus(repo.Workdir())
checkFatal(t, err)
if status.HasUntrackedFiles != false {
t.Errorf("Repo should not have untracked files")
want := RepoStatus{
HasUntrackedFiles: false,
HasUncommittedChanges: false,
BranchStatuses: nil,
}
if status.HasUncommittedChanges != false {
t.Errorf("Repo should not have uncommitted changes")
if !reflect.DeepEqual(status, want) {
t.Errorf("Wrong repo status, got %+v; want %+v", status, want)
}
}