Skip to content

Commit

Permalink
merge-test: Allow schema in prepInput
Browse files Browse the repository at this point in the history
  • Loading branch information
achim-k committed Sep 28, 2023
1 parent d78e67b commit 3a14afb
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions go/cli/mcap/cmd/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,19 @@ import (
"github.com/stretchr/testify/assert"
)

func prepInput(t *testing.T, w io.Writer, schemaID uint16, channelID uint16, topic string) {
func prepInput(t *testing.T, w io.Writer, schema *mcap.Schema, channelID uint16, topic string) {
writer, err := mcap.NewWriter(w, &mcap.WriterOptions{
Chunked: true,
})
assert.Nil(t, err)

assert.Nil(t, writer.WriteHeader(&mcap.Header{Profile: "testprofile"}))
if schemaID != 0 {
assert.Nil(t, writer.WriteSchema(&mcap.Schema{
ID: schemaID,
}))
if schema.ID != 0 {
assert.Nil(t, writer.WriteSchema(schema))
}
assert.Nil(t, writer.WriteChannel(&mcap.Channel{
ID: channelID,
SchemaID: schemaID,
SchemaID: schema.ID,
Topic: topic,
}))
for i := 0; i < 100; i++ {
Expand All @@ -42,9 +40,9 @@ func TestMCAPMerging(t *testing.T) {
buf1 := &bytes.Buffer{}
buf2 := &bytes.Buffer{}
buf3 := &bytes.Buffer{}
prepInput(t, buf1, 1, 1, "/foo")
prepInput(t, buf2, 1, 1, "/bar")
prepInput(t, buf3, 1, 1, "/baz")
prepInput(t, buf1, &mcap.Schema{ID:1}, 1, "/foo")
prepInput(t, buf2, &mcap.Schema{ID:1}, 1, "/bar")
prepInput(t, buf3, &mcap.Schema{ID:1}, 1, "/baz")
merger := newMCAPMerger(mergeOpts{
chunked: chunked,
})
Expand Down Expand Up @@ -136,8 +134,8 @@ func TestChannelsWithSameSchema(t *testing.T) {
func TestMultiChannelInput(t *testing.T) {
buf1 := &bytes.Buffer{}
buf2 := &bytes.Buffer{}
prepInput(t, buf1, 1, 1, "/foo")
prepInput(t, buf2, 1, 1, "/bar")
prepInput(t, buf1, &mcap.Schema{ID:1}, 1, "/foo")
prepInput(t, buf2, &mcap.Schema{ID:1}, 1, "/bar")
merger := newMCAPMerger(mergeOpts{})
multiChannelInput := &bytes.Buffer{}
inputs := []namedReader{
Expand All @@ -146,7 +144,7 @@ func TestMultiChannelInput(t *testing.T) {
}
assert.Nil(t, merger.mergeInputs(multiChannelInput, inputs))
buf3 := &bytes.Buffer{}
prepInput(t, buf3, 2, 2, "/baz")
prepInput(t, buf3, &mcap.Schema{ID:2}, 2, "/baz")
output := &bytes.Buffer{}
inputs2 := []namedReader{
{"multiChannelInput", multiChannelInput},
Expand All @@ -172,8 +170,8 @@ func TestMultiChannelInput(t *testing.T) {
func TestSchemalessChannelInput(t *testing.T) {
buf1 := &bytes.Buffer{}
buf2 := &bytes.Buffer{}
prepInput(t, buf1, 0, 1, "/foo")
prepInput(t, buf2, 1, 1, "/bar")
prepInput(t, buf1, &mcap.Schema{ID:0}, 1, "/foo")
prepInput(t, buf2, &mcap.Schema{ID:1}, 1, "/bar")
merger := newMCAPMerger(mergeOpts{})
output := &bytes.Buffer{}
inputs := []namedReader{
Expand Down Expand Up @@ -264,7 +262,7 @@ func TestBadInputGivesNamedErrors(t *testing.T) {
"bad magic",
func() *bytes.Buffer {
buf := &bytes.Buffer{}
prepInput(t, buf, 0, 1, "/foo")
prepInput(t, buf, &mcap.Schema{ID:0}, 1, "/foo")
buf.Bytes()[0] = 0x00
return buf
},
Expand All @@ -274,7 +272,7 @@ func TestBadInputGivesNamedErrors(t *testing.T) {
"bad content",
func() *bytes.Buffer {
buf := &bytes.Buffer{}
prepInput(t, buf, 0, 1, "/foo")
prepInput(t, buf, &mcap.Schema{ID:0}, 1, "/foo")
for i := 3000; i < 4000; i++ {
buf.Bytes()[i] = 0x00
}
Expand Down

0 comments on commit 3a14afb

Please sign in to comment.