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

Function TestCreateCommitBuffer

repository_test.go:8–60  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6)
7
8func TestCreateCommitBuffer(t *testing.T) {
9 t.Parallel()
10 repo := createTestRepo(t)
11 defer cleanupTestRepo(t, repo)
12
13 loc, err := time.LoadLocation("Europe/Berlin")
14 checkFatal(t, err)
15 sig := &Signature{
16 Name: "Rand Om Hacker",
17 Email: "random@hacker.com",
18 When: time.Date(2013, 03, 06, 14, 30, 0, 0, loc),
19 }
20
21 idx, err := repo.Index()
22 checkFatal(t, err)
23 err = idx.AddByPath("README")
24 checkFatal(t, err)
25 err = idx.Write()
26 checkFatal(t, err)
27 treeId, err := idx.WriteTree()
28 checkFatal(t, err)
29
30 message := "This is a commit\n"
31 tree, err := repo.LookupTree(treeId)
32 checkFatal(t, err)
33
34 for encoding, expected := range map[MessageEncoding]string{
35 MessageEncodingUTF8: `tree b7119b11e8ef7a1a5a34d3ac87f5b075228ac81e
36author Rand Om Hacker <random@hacker.com> 1362576600 +0100
37committer Rand Om Hacker <random@hacker.com> 1362576600 +0100
38
39This is a commit
40`,
41 MessageEncoding("ASCII"): `tree b7119b11e8ef7a1a5a34d3ac87f5b075228ac81e
42author Rand Om Hacker <random@hacker.com> 1362576600 +0100
43committer Rand Om Hacker <random@hacker.com> 1362576600 +0100
44encoding ASCII
45
46This is a commit
47`,
48 } {
49 encoding := encoding
50 expected := expected
51 t.Run(string(encoding), func(t *testing.T) {
52 buf, err := repo.CreateCommitBuffer(sig, sig, encoding, message, tree)
53 checkFatal(t, err)
54
55 if expected != string(buf) {
56 t.Errorf("mismatched commit buffer, expected %v, got %v", expected, string(buf))
57 }
58 })
59 }
60}
61
62func TestCreateCommitFromIds(t *testing.T) {
63 t.Parallel()

Callers

nothing calls this directly

Calls 10

createTestRepoFunction · 0.85
cleanupTestRepoFunction · 0.85
checkFatalFunction · 0.85
MessageEncodingTypeAlias · 0.85
AddByPathMethod · 0.80
WriteTreeMethod · 0.80
LookupTreeMethod · 0.80
CreateCommitBufferMethod · 0.80
IndexMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…