Ejemplo n.º 1
0
func TestAsChunkMarshalsTheStatusToChunks(t *testing.T) {
	st := stream.NewStatus()
	st.Arguments.Add("foo", amf0.NewString("bar"))

	c, err := st.AsChunk()

	expected := []byte{
		0x02, 0x00, 0x08, 0x6f, 0x6e, 0x53, 0x74, 0x61, 0x74, 0x75,
		0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x05, 0x03, 0x00, 0x03, 0x66, 0x6f, 0x6f, 0x02, 0x00, 0x03,
		0x62, 0x61, 0x72, 0x00, 0x00, 0x09,
	}

	assert.Nil(t, err)
	assert.Equal(t, chunk.Chunk{
		Header: &chunk.Header{
			BasicHeader: chunk.BasicHeader{
				StreamId: 5,
			},
			MessageHeader: chunk.MessageHeader{
				Length:   uint32(len(expected)),
				TypeId:   0x14,
				StreamId: 1,
			},
		},
		Data: expected,
	}, *c)
}
Ejemplo n.º 2
0
func TestParseFailsWhenNoMatchingCommandIsPresent(t *testing.T) {
	p := conn.NewParser(map[string]conn.ReceviableFactory{
	// No types
	})

	r, err := p.Parse(amf0.NewString("not-a-type"), new(bytes.Buffer))

	assert.Nil(t, r)
	assert.Equal(t, "rtmp/cmd/conn: unknown command name: not-a-type",
		err.Error())
}
Ejemplo n.º 3
0
func TestEncodeToBytesDoesNotMangleOutput(t *testing.T) {
	s := amf0.NewString("hello world")

	buf := new(bytes.Buffer)

	n, e1 := amf0.Encode(s, buf)
	out, e2 := amf0.EncodeToBytes(s)

	assert.Len(t, out, n)
	assert.Equal(t, buf.Bytes(), out)
	assert.Equal(t, e1, e2)
}
Ejemplo n.º 4
0
func TestDataMarshalsTheStatusesData(t *testing.T) {
	st := stream.NewStatus()
	st.Arguments.Add("foo", amf0.NewString("bar"))

	data, err := st.Data()

	assert.Nil(t, err)
	assert.Equal(t, []byte{
		0x03, 0x00, 0x03, 0x66, 0x6f, 0x6f, 0x02, 0x00, 0x03, 0x62,
		0x61, 0x72, 0x00, 0x00, 0x09,
	}, data)
}
Ejemplo n.º 5
0
func TestParseFailsWhenDataIsUnmarshalable(t *testing.T) {
	p := conn.NewParser(map[string]conn.ReceviableFactory{
		"createStream": func() conn.Receivable {
			return new(conn.CreateStreamCommand)
		},
	})

	// Error: use an empty buffer to ensure that an EOF is thrown
	r, err := p.Parse(amf0.NewString("createStream"), new(bytes.Buffer))

	assert.Nil(t, r)
	assert.Equal(t, io.EOF, err)
}
Ejemplo n.º 6
0
func TestParseParsesReadersIntoReceivables(t *testing.T) {
	p := conn.NewParser(map[string]conn.ReceviableFactory{
		"createStream": func() conn.Receivable {
			return new(conn.CreateStreamCommand)
		},
	})

	r, err := p.Parse(
		amf0.NewString("createStream"),
		bytes.NewReader(CreatePayload),
	)

	assert.Nil(t, err)

	switch typ := r.(type) {
	case *conn.CreateStreamCommand:
		assert.Equal(t, float64(4), typ.TransactionId)
		assert.Nil(t, typ.Metadata)
	default:
		t.Fatalf("rtmp/cmd/conn: unknown type %T", typ)
	}
}