feat: migrate from msgpack to protobuf (handler-base v1.0.0)
- Replace msgpack encoding with protobuf wire format - Update field names to proto convention - Change Parameters type from map[string]any to map[string]string - Rewrite tests for proto round-trips
This commit is contained in:
34
main_test.go
34
main_test.go
@@ -8,25 +8,25 @@ import (
|
||||
|
||||
"git.daviestechlabs.io/daviestechlabs/handler-base/messages"
|
||||
"git.daviestechlabs.io/daviestechlabs/handler-base/natsutil"
|
||||
"github.com/vmihailenco/msgpack/v5"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
func TestPipelineTriggerDecode(t *testing.T) {
|
||||
req := messages.PipelineTrigger{
|
||||
RequestID: "req-001",
|
||||
req := &messages.PipelineTrigger{
|
||||
RequestId: "req-001",
|
||||
Pipeline: "document-ingestion",
|
||||
Parameters: map[string]any{"source": "s3://bucket"},
|
||||
Parameters: map[string]string{"source": "s3://bucket"},
|
||||
}
|
||||
data, err := msgpack.Marshal(&req)
|
||||
data, err := proto.Marshal(req)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
decoded, err := natsutil.Decode[messages.PipelineTrigger](data)
|
||||
if err != nil {
|
||||
var decoded messages.PipelineTrigger
|
||||
if err := natsutil.Decode(data, &decoded); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if decoded.RequestID != "req-001" {
|
||||
t.Errorf("RequestID = %q", decoded.RequestID)
|
||||
if decoded.RequestId != "req-001" {
|
||||
t.Errorf("RequestID = %q", decoded.RequestId)
|
||||
}
|
||||
if decoded.Pipeline != "document-ingestion" {
|
||||
t.Errorf("Pipeline = %q", decoded.Pipeline)
|
||||
@@ -38,22 +38,22 @@ func TestPipelineTriggerDecode(t *testing.T) {
|
||||
|
||||
func TestPipelineStatusRoundtrip(t *testing.T) {
|
||||
status := messages.PipelineStatus{
|
||||
RequestID: "req-002",
|
||||
RequestId: "req-002",
|
||||
Status: "submitted",
|
||||
RunID: "argo-abc123",
|
||||
RunId: "argo-abc123",
|
||||
Engine: "argo",
|
||||
Pipeline: "batch-inference",
|
||||
}
|
||||
data, err := msgpack.Marshal(&status)
|
||||
data, err := proto.Marshal(&status)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var got messages.PipelineStatus
|
||||
if err := msgpack.Unmarshal(data, &got); err != nil {
|
||||
if err := proto.Unmarshal(data, &got); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got.RunID != "argo-abc123" {
|
||||
t.Errorf("RunID = %q", got.RunID)
|
||||
if got.RunId != "argo-abc123" {
|
||||
t.Errorf("RunID = %q", got.RunId)
|
||||
}
|
||||
if got.Engine != "argo" {
|
||||
t.Errorf("Engine = %q", got.Engine)
|
||||
@@ -118,7 +118,7 @@ func TestSubmitArgo(t *testing.T) {
|
||||
defer ts.Close()
|
||||
|
||||
ctx := t.Context()
|
||||
runID, err := submitArgo(ctx, ts.Client(), ts.URL, "ai-ml", "document-ingestion", map[string]any{
|
||||
runID, err := submitArgo(ctx, ts.Client(), ts.URL, "ai-ml", "document-ingestion", map[string]string{
|
||||
"source": "test",
|
||||
}, "req-001")
|
||||
if err != nil {
|
||||
@@ -160,7 +160,7 @@ func TestSubmitKubeflow(t *testing.T) {
|
||||
defer ts.Close()
|
||||
|
||||
ctx := t.Context()
|
||||
runID, err := submitKubeflow(ctx, ts.Client(), ts.URL, "rag-pipeline", map[string]any{
|
||||
runID, err := submitKubeflow(ctx, ts.Client(), ts.URL, "rag-pipeline", map[string]string{
|
||||
"query": "test",
|
||||
}, "req-002")
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user