MCPcopy Index your code
hub / github.com/go-git/go-git / TestPGPSignatureSerialization

Method TestPGPSignatureSerialization

plumbing/object/commit_test.go:406–452  ·  view source on GitHub ↗
(c *C)

Source from the content-addressed store, hash-verified

404}
405
406func (s *SuiteCommit) TestPGPSignatureSerialization(c *C) {
407 pgpsignature := `-----BEGIN PGP SIGNATURE-----
408
409iQEcBAABAgAGBQJTZbQlAAoJEF0+sviABDDrZbQH/09PfE51KPVPlanr6q1v4/Ut
410LQxfojUWiLQdg2ESJItkcuweYg+kc3HCyFejeDIBw9dpXt00rY26p05qrpnG+85b
411hM1/PswpPLuBSr+oCIDj5GMC2r2iEKsfv2fJbNW8iWAXVLoWZRF8B0MfqX/YTMbm
412ecorc4iXzQu7tupRihslbNkfvfciMnSDeSvzCpWAHl7h8Wj6hhqePmLm9lAYqnKp
4138S5B/1SSQuEAjRZgI4IexpZoeKGVDptPHxLLS38fozsyi0QyDyzEgJxcJQVMXxVi
414RUysgqjcpT8+iQM1PblGfHR4XAhuOqN5Fx06PSaFZhqvWFezJ28/CLyX5q+oIVk=
415=EFTF
416-----END PGP SIGNATURE-----
417`
418 broken := beginpgp + "\nsome\ntrash\n" + endpgp + "text\n"
419
420 cases := []struct {
421 name string
422 pgpSignature string
423 authorName string
424 }{
425 {name: "pgp signature", pgpSignature: pgpsignature},
426 {name: "pgp signature with leading empty line", pgpSignature: "\n" + pgpsignature},
427 {name: "beginpgp marker in author name is not parsed as signature", authorName: beginpgp},
428 {name: "garbage between begin and end markers round-trips", pgpSignature: broken},
429 }
430
431 for _, tc := range cases {
432 c.Log(tc.name)
433
434 commit := *s.Commit
435 commit.PGPSignature = tc.pgpSignature
436 if tc.authorName != "" {
437 commit.Author.Name = tc.authorName
438 }
439
440 encoded := &plumbing.MemoryObject{}
441 decoded := &Commit{}
442 err := commit.Encode(encoded)
443 c.Assert(err, IsNil)
444
445 err = decoded.Decode(encoded)
446 c.Assert(err, IsNil)
447 c.Assert(decoded.PGPSignature, Equals, tc.pgpSignature)
448 if tc.authorName != "" {
449 c.Assert(decoded.Author.Name, Equals, tc.authorName)
450 }
451 }
452}
453
454func (s *SuiteCommit) TestStat(c *C) {
455 aCommit := s.commit(c, plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"))

Callers

nothing calls this directly

Calls 3

DecodeMethod · 0.95
LogMethod · 0.80
EncodeMethod · 0.65

Tested by

no test coverage detected