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

Method TestEncode

plumbing/format/pktline/encoder_test.go:30–88  ·  view source on GitHub ↗
(c *C)

Source from the content-addressed store, hash-verified

28}
29
30func (s *SuiteEncoder) TestEncode(c *C) {
31 for i, test := range [...]struct {
32 input [][]byte
33 expected []byte
34 }{
35 {
36 input: [][]byte{
37 []byte("hello\n"),
38 },
39 expected: []byte("000ahello\n"),
40 }, {
41 input: [][]byte{
42 []byte("hello\n"),
43 pktline.Flush,
44 },
45 expected: []byte("000ahello\n0000"),
46 }, {
47 input: [][]byte{
48 []byte("hello\n"),
49 []byte("world!\n"),
50 []byte("foo"),
51 },
52 expected: []byte("000ahello\n000bworld!\n0007foo"),
53 }, {
54 input: [][]byte{
55 []byte("hello\n"),
56 pktline.Flush,
57 []byte("world!\n"),
58 []byte("foo"),
59 pktline.Flush,
60 },
61 expected: []byte("000ahello\n0000000bworld!\n0007foo0000"),
62 }, {
63 input: [][]byte{
64 []byte(strings.Repeat("a", pktline.MaxPayloadSize)),
65 },
66 expected: []byte(
67 "fff0" + strings.Repeat("a", pktline.MaxPayloadSize)),
68 }, {
69 input: [][]byte{
70 []byte(strings.Repeat("a", pktline.MaxPayloadSize)),
71 []byte(strings.Repeat("b", pktline.MaxPayloadSize)),
72 },
73 expected: []byte(
74 "fff0" + strings.Repeat("a", pktline.MaxPayloadSize) +
75 "fff0" + strings.Repeat("b", pktline.MaxPayloadSize)),
76 },
77 } {
78 comment := Commentf("input %d = %v\n", i, test.input)
79
80 var buf bytes.Buffer
81 e := pktline.NewEncoder(&buf)
82
83 err := e.Encode(test.input...)
84 c.Assert(err, IsNil, comment)
85
86 c.Assert(buf.Bytes(), DeepEquals, test.expected, comment)
87 }

Callers

nothing calls this directly

Calls 3

EncodeMethod · 0.95
NewEncoderFunction · 0.92
BytesMethod · 0.45

Tested by

no test coverage detected