diff options
Diffstat (limited to 'reference_test.go')
| -rw-r--r-- | reference_test.go | 79 |
1 files changed, 60 insertions, 19 deletions
diff --git a/reference_test.go b/reference_test.go index 5720a66..b6721e1 100644 --- a/reference_test.go +++ b/reference_test.go @@ -8,26 +8,20 @@ import ( ) func TestRefModification(t *testing.T) { + t.Parallel() repo := createTestRepo(t) defer cleanupTestRepo(t, repo) commitId, treeId := seedTestRepo(t, repo) - loc, err := time.LoadLocation("Europe/Berlin") - checkFatal(t, err) - sig := &Signature{ - Name: "Rand Om Hacker", - Email: "[email protected]", - When: time.Date(2013, 03, 06, 14, 30, 0, 0, loc), - } - _, err = repo.CreateReference("refs/tags/tree", treeId, true, sig, "testTreeTag") + _, err := repo.References.Create("refs/tags/tree", treeId, true, "testTreeTag") checkFatal(t, err) - tag, err := repo.LookupReference("refs/tags/tree") + tag, err := repo.References.Lookup("refs/tags/tree") checkFatal(t, err) checkRefType(t, tag, ReferenceOid) - ref, err := repo.LookupReference("HEAD") + ref, err := repo.References.Lookup("HEAD") checkFatal(t, err) checkRefType(t, ref, ReferenceSymbolic) @@ -51,15 +45,16 @@ func TestRefModification(t *testing.T) { t.Fatalf("Wrong ref target") } - _, err = tag.Rename("refs/tags/renamed", false, nil, "") + _, err = tag.Rename("refs/tags/renamed", false, "") checkFatal(t, err) - tag, err = repo.LookupReference("refs/tags/renamed") + tag, err = repo.References.Lookup("refs/tags/renamed") checkFatal(t, err) checkRefType(t, ref, ReferenceOid) } func TestReferenceIterator(t *testing.T) { + t.Parallel() repo := createTestRepo(t) defer cleanupTestRepo(t, repo) @@ -84,13 +79,13 @@ func TestReferenceIterator(t *testing.T) { commitId, err := repo.CreateCommit("HEAD", sig, sig, message, tree) checkFatal(t, err) - _, err = repo.CreateReference("refs/heads/one", commitId, true, sig, "headOne") + _, err = repo.References.Create("refs/heads/one", commitId, true, "headOne") checkFatal(t, err) - _, err = repo.CreateReference("refs/heads/two", commitId, true, sig, "headTwo") + _, err = repo.References.Create("refs/heads/two", commitId, true, "headTwo") checkFatal(t, err) - _, err = repo.CreateReference("refs/heads/three", commitId, true, sig, "headThree") + _, err = repo.References.Create("refs/heads/three", commitId, true, "headThree") checkFatal(t, err) iter, err := repo.NewReferenceIterator() @@ -138,12 +133,13 @@ func TestReferenceIterator(t *testing.T) { } func TestReferenceOwner(t *testing.T) { + t.Parallel() repo := createTestRepo(t) defer cleanupTestRepo(t, repo) commitId, _ := seedTestRepo(t, repo) - ref, err := repo.CreateReference("refs/heads/foo", commitId, true, nil, "") + ref, err := repo.References.Create("refs/heads/foo", commitId, true, "") checkFatal(t, err) owner := ref.Owner() @@ -157,15 +153,16 @@ func TestReferenceOwner(t *testing.T) { } func TestUtil(t *testing.T) { + t.Parallel() repo := createTestRepo(t) defer cleanupTestRepo(t, repo) commitId, _ := seedTestRepo(t, repo) - ref, err := repo.CreateReference("refs/heads/foo", commitId, true, nil, "") + ref, err := repo.References.Create("refs/heads/foo", commitId, true, "") checkFatal(t, err) - ref2, err := repo.DwimReference("foo") + ref2, err := repo.References.Dwim("foo") checkFatal(t, err) if ref.Cmp(ref2) != 0 { @@ -176,13 +173,57 @@ func TestUtil(t *testing.T) { t.Fatalf("refs/heads/foo has no foo shorthand") } - hasLog, err := repo.HasLog("refs/heads/foo") + hasLog, err := repo.References.HasLog("refs/heads/foo") checkFatal(t, err) if !hasLog { t.Fatalf("branches have logs by default") } } +func TestIsNote(t *testing.T) { + t.Parallel() + repo := createTestRepo(t) + defer cleanupTestRepo(t, repo) + + commitID, _ := seedTestRepo(t, repo) + + sig := &Signature{ + Name: "Rand Om Hacker", + Email: "[email protected]", + When: time.Now(), + } + + refname, err := repo.Notes.DefaultRef() + checkFatal(t, err) + + _, err = repo.Notes.Create(refname, sig, sig, commitID, "This is a note", false) + checkFatal(t, err) + + ref, err := repo.References.Lookup(refname) + checkFatal(t, err) + + if !ref.IsNote() { + t.Fatalf("%s should be a note", ref.Name()) + } + + ref, err = repo.References.Create("refs/heads/foo", commitID, true, "") + checkFatal(t, err) + + if ref.IsNote() { + t.Fatalf("%s should not be a note", ref.Name()) + } +} + +func TestReferenceIsValidName(t *testing.T) { + t.Parallel() + if !ReferenceIsValidName("HEAD") { + t.Errorf("HEAD should be a valid reference name") + } + if ReferenceIsValidName("HEAD1") { + t.Errorf("HEAD1 should not be a valid reference name") + } +} + func compareStringList(t *testing.T, expected, actual []string) { for i, v := range expected { if actual[i] != v { |
