Files
wehub-resource-sync 498b235461
Build and test / Build and test AMD64 Ubuntu 22.04 (push) Failing after 0s
Publish Builder / amazonlinux2023 (push) Failing after 1s
Build and test / UT for Go (push) Has been skipped
Publish KRTE Images / KRTE (push) Failing after 1s
Build and test / Integration Test (push) Has been skipped
Build and test / Upload Code Coverage (push) Has been skipped
Publish Builder / rockylinux9 (push) Failing after 1s
Publish Builder / ubuntu22.04 (push) Failing after 0s
Publish Builder / ubuntu24.04 (push) Failing after 0s
Publish Gpu Builder / publish-gpu-builder (push) Failing after 1s
Publish Test Images / PyTest (push) Failing after 0s
Build and test / UT for Cpp (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:31:17 +08:00

72 lines
1.4 KiB
Go

package common
import (
"testing"
"github.com/stretchr/testify/assert"
"google.golang.org/protobuf/proto"
"github.com/milvus-io/milvus-proto/go-api/v3/commonpb"
)
type mockMessage struct {
topic string
properties map[string]string
payload []byte
id MessageID
}
func (m *mockMessage) Topic() string {
return m.topic
}
func (m *mockMessage) Properties() map[string]string {
return m.properties
}
func (m *mockMessage) Payload() []byte {
return m.payload
}
func (m *mockMessage) ID() MessageID {
return m.id
}
func TestGetMsgType(t *testing.T) {
t.Run("Test with properties", func(t *testing.T) {
properties := map[string]string{
MsgTypeKey: "Insert",
}
msg := &mockMessage{
properties: properties,
}
msgType, err := GetMsgType(msg)
assert.NoError(t, err)
assert.Equal(t, commonpb.MsgType_Insert, msgType)
})
t.Run("Test with payload", func(t *testing.T) {
header := &commonpb.MsgHeader{
Base: &commonpb.MsgBase{
MsgType: commonpb.MsgType_Insert,
},
}
payload, err := proto.Marshal(header)
assert.NoError(t, err)
msg := &mockMessage{
payload: payload,
}
msgType, err := GetMsgType(msg)
assert.NoError(t, err)
assert.Equal(t, commonpb.MsgType_Insert, msgType)
})
t.Run("Test with empty payload and properties", func(t *testing.T) {
msg := &mockMessage{}
msgType, err := GetMsgType(msg)
assert.Error(t, err)
assert.Equal(t, commonpb.MsgType_Undefined, msgType)
})
}