6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-07 11:48:28 +00:00

Add CloneRepo function and unit tests for cloned repos status

This commit is contained in:
Grzegorz Dlugoszewski
2020-05-19 14:12:38 +02:00
parent a0f09ef74d
commit dfc8437408
5 changed files with 130 additions and 32 deletions

View File

@@ -1,6 +1,7 @@
package main
import (
"reflect"
"testing"
)
@@ -29,3 +30,49 @@ func TestNewLocalBranch(t *testing.T) {
t.Errorf("Wrong branch status, got %+v; want %+v", status, want)
}
}
func TestClonedBranches(t *testing.T) {
origin := newTestRepo(t)
createFile(t, origin, "file")
stageFile(t, origin, "file")
createCommit(t, origin, "Initial commit")
repo, err := CloneRepo(origin.Path(), newTempDir(t))
checkFatal(t, err)
createBranch(t, repo, "branch")
branches, err := Branches(repo)
checkFatal(t, err)
master := branches["master"]
wantMaster := BranchStatus{
Name: "master",
IsRemote: false,
HasUpstream: true,
}
originMaster := branches["origin/master"]
wantOriginMaster := BranchStatus{
Name: "origin/master",
IsRemote: true,
HasUpstream: false,
}
branch := branches["branch"]
wantBranch := BranchStatus{
Name: "branch",
IsRemote: false,
HasUpstream: false,
}
if !reflect.DeepEqual(master, wantMaster) {
t.Errorf("Wrong branch status, got %+v; want %+v", master, wantMaster)
}
if !reflect.DeepEqual(originMaster, wantOriginMaster) {
t.Errorf("Wrong branch status, got %+v; want %+v", originMaster, wantOriginMaster)
}
if !reflect.DeepEqual(branch, wantBranch) {
t.Errorf("Wrong branch status, got %+v; want %+v", branch, wantBranch)
}
}