MCPcopy Create free account
hub / github.com/libgit2/git2go / TestReferenceIterator

Function TestReferenceIterator

reference_test.go:56–133  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

54}
55
56func TestReferenceIterator(t *testing.T) {
57 t.Parallel()
58 repo := createTestRepo(t)
59 defer cleanupTestRepo(t, repo)
60
61 loc, err := time.LoadLocation("Europe/Berlin")
62 checkFatal(t, err)
63 sig := &Signature{
64 Name: "Rand Om Hacker",
65 Email: "random@hacker.com",
66 When: time.Date(2013, 03, 06, 14, 30, 0, 0, loc),
67 }
68
69 idx, err := repo.Index()
70 checkFatal(t, err)
71 err = idx.AddByPath("README")
72 checkFatal(t, err)
73 treeId, err := idx.WriteTree()
74 checkFatal(t, err)
75
76 message := "This is a commit\n"
77 tree, err := repo.LookupTree(treeId)
78 checkFatal(t, err)
79 commitId, err := repo.CreateCommit("HEAD", sig, sig, message, tree)
80 checkFatal(t, err)
81
82 _, err = repo.References.Create("refs/heads/one", commitId, true, "headOne")
83 checkFatal(t, err)
84
85 _, err = repo.References.Create("refs/heads/two", commitId, true, "headTwo")
86 checkFatal(t, err)
87
88 _, err = repo.References.Create("refs/heads/three", commitId, true, "headThree")
89 checkFatal(t, err)
90
91 iter, err := repo.NewReferenceIterator()
92 checkFatal(t, err)
93
94 var list []string
95 expected := []string{
96 "refs/heads/master",
97 "refs/heads/one",
98 "refs/heads/three",
99 "refs/heads/two",
100 }
101
102 // test some manual iteration
103 nameIter := iter.Names()
104 name, err := nameIter.Next()
105 for err == nil {
106 list = append(list, name)
107 name, err = nameIter.Next()
108 }
109 if !IsErrorCode(err, ErrorCodeIterOver) {
110 t.Fatal("Iteration not over")
111 }
112
113 sort.Strings(list)

Callers

nothing calls this directly

Calls 15

NamesMethod · 0.95
NextMethod · 0.95
createTestRepoFunction · 0.85
cleanupTestRepoFunction · 0.85
checkFatalFunction · 0.85
IsErrorCodeFunction · 0.85
compareStringListFunction · 0.85
AddByPathMethod · 0.80
WriteTreeMethod · 0.80
LookupTreeMethod · 0.80
CreateCommitMethod · 0.80
NewReferenceIteratorMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…