MCPcopy Create free account
hub / github.com/go-git/go-git / TestCommitSign

Method TestCommitSign

worktree_commit_test.go:341–375  ·  view source on GitHub ↗
(c *C)

Source from the content-addressed store, hash-verified

339}
340
341func (s *WorktreeSuite) TestCommitSign(c *C) {
342 fs := memfs.New()
343 storage := memory.NewStorage()
344
345 r, err := Init(storage, fs)
346 c.Assert(err, IsNil)
347
348 w, err := r.Worktree()
349 c.Assert(err, IsNil)
350
351 util.WriteFile(fs, "foo", []byte("foo"), 0644)
352
353 _, err = w.Add("foo")
354 c.Assert(err, IsNil)
355
356 key := commitSignKey(c, true)
357 hash, err := w.Commit("foo\n", &CommitOptions{Author: defaultSignature(), SignKey: key})
358 c.Assert(err, IsNil)
359
360 // Verify the commit.
361 pks := new(bytes.Buffer)
362 pkw, err := armor.Encode(pks, openpgp.PublicKeyType, nil)
363 c.Assert(err, IsNil)
364
365 err = key.Serialize(pkw)
366 c.Assert(err, IsNil)
367 err = pkw.Close()
368 c.Assert(err, IsNil)
369
370 expectedCommit, err := r.CommitObject(hash)
371 c.Assert(err, IsNil)
372 actual, err := expectedCommit.Verify(pks.String())
373 c.Assert(err, IsNil)
374 c.Assert(actual.PrimaryKey, DeepEquals, key.PrimaryKey)
375}
376
377func (s *WorktreeSuite) TestCommitSignBadKey(c *C) {
378 fs := memfs.New()

Callers

nothing calls this directly

Calls 12

NewStorageFunction · 0.92
InitFunction · 0.85
commitSignKeyFunction · 0.85
defaultSignatureFunction · 0.85
WorktreeMethod · 0.80
CommitObjectMethod · 0.80
CommitMethod · 0.65
EncodeMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.65
AddMethod · 0.45
VerifyMethod · 0.45

Tested by

no test coverage detected