<commit_before>package message_test

import (
	"crypto/rand"
	"fmt"
	"testing"
	. "github.com/tsenart/gofka/message"
	. "github.com/tsenart/gofka/testing"
)

func TestMessageSet_NewMessageSet(t *testing.T) {
	msg := NewMessage([]byte("k"), []byte("v"), NoCodec)

	_, err := NewMessageSet(0, nil)
	Equals(t, err, ErrNilMessages)

	_, err = NewMessageSet(0, msg, msg, nil)
	Equals(t, err, ErrNilMessages)

	_, err = NewMessageSet(0, []Message{}...)
	Equals(t, err, ErrNoMessages)

	_, err = NewMessageSet(0, NewMessage([]byte("k"), []byte("v"), NoCodec))
	OK(t, err)

	payload := make([]byte, 1024*1024)
	_, err = rand.Read(payload)
	OK(t, err)

	plain, err := NewMessageSet(0, NewMessage(payload, payload, NoCodec))
	OK(t, err)

	for _, codec := range []Codec{GZIPCodec} {
		comp, err := NewMessageSet(0, NewMessage(payload, payload, codec))
		OK(t, err)
		msg := fmt.Sprintf("compressed = %d bytes, uncompressed = %d bytes", comp.Size(), plain.Size())
		t.Log(msg)
		Assert(t, comp.Size() < plain.Size(), msg)
	}
}
<commit_msg>message: Add test case for ErrMultipleCodecs<commit_after>package message_test

import (
	"crypto/rand"
	"fmt"
	"testing"
	. "github.com/tsenart/gofka/message"
	. "github.com/tsenart/gofka/testing"
)

func TestMessageSet_NewMessageSet(t *testing.T) {
	msg := NewMessage([]byte("k"), []byte("v"), NoCodec)

	_, err := NewMessageSet(0, nil)
	Equals(t, err, ErrNilMessages)

	_, err = NewMessageSet(0, msg, msg, nil)
	Equals(t, err, ErrNilMessages)

	_, err = NewMessageSet(0, []Message{}...)
	Equals(t, err, ErrNoMessages)

	_, err = NewMessageSet(0,
		NewMessage([]byte("k"), []byte("v"), NoCodec),
		NewMessage([]byte("k"), []byte("v"), GZIPCodec),
	)
	Equals(t, err, ErrMultipleCodecs)

	_, err = NewMessageSet(0, NewMessage([]byte("k"), []byte("v"), NoCodec))
	OK(t, err)

	payload := make([]byte, 1024*1024)
	_, err = rand.Read(payload)
	OK(t, err)

	plain, err := NewMessageSet(0, NewMessage(payload, payload, NoCodec))
	OK(t, err)

	for _, codec := range []Codec{GZIPCodec} {
		comp, err := NewMessageSet(0, NewMessage(payload, payload, codec))
		OK(t, err)
		msg := fmt.Sprintf("compressed = %d bytes, uncompressed = %d bytes", comp.Size(), plain.Size())
		t.Log(msg)
		Assert(t, comp.Size() < plain.Size(), msg)
	}
}

{'fraction_non_alphanumeric': 0.19369169258107508, 'fraction_numerical': 0.01288316303864949, 'mean_word_length': 5.021390374331551, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3715315', 'n_tokens_mistral': 900, 'n_tokens_neox': 864, 'n_words': 182}