MCPcopy
hub / github.com/go-git/go-git / TestEncodeExtraHeaders

Method TestEncodeExtraHeaders

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

Source from the content-addressed store, hash-verified

1008}
1009
1010func (s *SuiteCommit) TestEncodeExtraHeaders(c *C) {
1011 object := &plumbing.MemoryObject{}
1012 object.SetType(plumbing.CommitObject)
1013 object.Write([]byte(`tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904
1014author John Doe <john.doe@example.com> 1755280730 -0700
1015committer John Doe <john.doe@example.com> 1755280730 -0700
1016continuedheader to be
1017 continued
1018continuedheader to be
1019 continued
1020 on
1021 more than
1022 a single line
1023simpleflag
1024 value no key
1025
1026initial commit
1027`))
1028
1029 commit, err := DecodeCommit(s.Storer, object)
1030 c.Assert(err, IsNil)
1031
1032 c.Assert(commit.ExtraHeaders, DeepEquals, []ExtraHeader{
1033 ExtraHeader{
1034 Key: "continuedheader",
1035 Value: "to be\ncontinued",
1036 },
1037 ExtraHeader{
1038 Key: "continuedheader",
1039 Value: "to be\ncontinued\non\nmore than\na single line",
1040 },
1041 ExtraHeader{
1042 Key: "simpleflag",
1043 Value: "",
1044 },
1045 ExtraHeader{
1046 Key: "",
1047 Value: "value no key",
1048 },
1049 })
1050
1051 // Similar to TestString since no signature
1052 encoded := &plumbing.MemoryObject{}
1053 err = commit.EncodeWithoutSignature(encoded)
1054 er, err := encoded.Reader()
1055 c.Assert(err, IsNil)
1056 payload, err := io.ReadAll(er)
1057 c.Assert(err, IsNil)
1058
1059 c.Assert(string(payload), Equals, `tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904
1060author John Doe <john.doe@example.com> 1755280730 -0700
1061committer John Doe <john.doe@example.com> 1755280730 -0700
1062continuedheader to be
1063 continued
1064continuedheader to be
1065 continued
1066 on
1067 more than

Callers

nothing calls this directly

Calls 5

SetTypeMethod · 0.95
WriteMethod · 0.95
ReaderMethod · 0.95
DecodeCommitFunction · 0.85

Tested by

no test coverage detected