aboutsummaryrefslogblamecommitdiffstats
path: root/plumbing/protocol/packp/sideband/muxer_test.go
blob: 38fc4bdd1fb43704acd46975a3fa27f40f468fe2 (plain) (tree)






































                                                                              
package sideband

import (
	"bytes"

	. "gopkg.in/check.v1"
)

func (s *SidebandSuite) TestMuxerWrite(c *C) {
	buf := bytes.NewBuffer(nil)

	m := NewMuxer(Sideband, buf)

	n, err := m.Write(bytes.Repeat([]byte{'F'}, (MaxPackedSize-1)*2))
	c.Assert(err, IsNil)
	c.Assert(n, Equals, 1998)
	c.Assert(buf.Len(), Equals, 2008)
}

func (s *SidebandSuite) TestMuxerWriteChannelMultipleChannels(c *C) {
	buf := bytes.NewBuffer(nil)

	m := NewMuxer(Sideband, buf)

	n, err := m.WriteChannel(PackData, bytes.Repeat([]byte{'D'}, 4))
	c.Assert(err, IsNil)
	c.Assert(n, Equals, 4)

	n, err = m.WriteChannel(ProgressMessage, bytes.Repeat([]byte{'P'}, 4))
	c.Assert(err, IsNil)
	c.Assert(n, Equals, 4)

	n, err = m.WriteChannel(PackData, bytes.Repeat([]byte{'D'}, 4))
	c.Assert(err, IsNil)
	c.Assert(n, Equals, 4)

	c.Assert(buf.Len(), Equals, 27)
	c.Assert(buf.String(), Equals, "0009\x01DDDD0009\x02PPPP0009\x01DDDD")
}