-
Notifications
You must be signed in to change notification settings - Fork 315
/
note_test.go
117 lines (90 loc) · 2.58 KB
/
note_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package git
import (
"fmt"
"reflect"
"testing"
"time"
)
func TestCreateNote(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
commitId, _ := seedTestRepo(t, repo)
commit, err := repo.LookupCommit(commitId)
checkFatal(t, err)
note, noteId := createTestNote(t, repo, commit)
compareStrings(t, "I am a note\n", note.Message())
compareStrings(t, noteId.String(), note.Id().String())
compareStrings(t, "alice", note.Author().Name)
compareStrings(t, "[email protected]", note.Author().Email)
compareStrings(t, "alice", note.Committer().Name)
compareStrings(t, "[email protected]", note.Committer().Email)
}
func TestNoteIterator(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
seedTestRepo(t, repo)
notes := make([]*Note, 5)
for i := range notes {
commitId, _ := updateReadme(t, repo, fmt.Sprintf("README v%d\n", i+1))
commit, err := repo.LookupCommit(commitId)
checkFatal(t, err)
note, _ := createTestNote(t, repo, commit)
notes[i] = note
}
iter, err := repo.NewNoteIterator("")
checkFatal(t, err)
for {
noteId, commitId, err := iter.Next()
if err != nil {
if !IsErrorCode(err, ErrorCodeIterOver) {
checkFatal(t, err)
}
break
}
note, err := repo.Notes.Read("", commitId)
checkFatal(t, err)
if !reflect.DeepEqual(note.Id(), noteId) {
t.Errorf("expected note oid '%v', actual '%v'", note.Id(), noteId)
}
}
}
func TestRemoveNote(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
commitId, _ := seedTestRepo(t, repo)
commit, err := repo.LookupCommit(commitId)
checkFatal(t, err)
note, _ := createTestNote(t, repo, commit)
_, err = repo.Notes.Read("", commit.Id())
checkFatal(t, err)
err = repo.Notes.Remove("", note.Author(), note.Committer(), commitId)
checkFatal(t, err)
_, err = repo.Notes.Read("", commit.Id())
if err == nil {
t.Fatal("note remove failed")
}
}
func TestDefaultNoteRef(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
ref, err := repo.Notes.DefaultRef()
checkFatal(t, err)
compareStrings(t, "refs/notes/commits", ref)
}
func createTestNote(t *testing.T, repo *Repository, commit *Commit) (*Note, *Oid) {
loc, err := time.LoadLocation("Europe/Berlin")
sig := &Signature{
Name: "alice",
Email: "[email protected]",
When: time.Date(2015, 01, 05, 13, 0, 0, 0, loc),
}
noteId, err := repo.Notes.Create("", sig, sig, commit.Id(), "I am a note\n", false)
checkFatal(t, err)
note, err := repo.Notes.Read("", commit.Id())
checkFatal(t, err)
return note, noteId
}