Files
magistrala/pkg/messaging/fluxmq/internal_metadata_integration_test.go
Dušan Borovčanin 880634e009
Continuous Delivery / lint-and-build (push) Has been cancelled
Deploy GitHub Pages / swagger-ui (push) Has been cancelled
CI Pipeline / Lint Proto (push) Has been cancelled
CI Pipeline / Detect Changes (push) Has been cancelled
Continuous Delivery / Build and Push Docker Images (push) Has been cancelled
CI Pipeline / lint-and-build (push) Has been cancelled
CI Pipeline / Test ${{ matrix.module }} (push) Has been cancelled
CI Pipeline / Upload Coverage (push) Has been cancelled
MG-3486 - RE Loop Prevention (#3559)
Signed-off-by: dusan <borovcanindusan1@gmail.com>
2026-08-01 02:33:52 +02:00

66 lines
1.8 KiB
Go

// Copyright (c) Abstract Machines
// SPDX-License-Identifier: Apache-2.0
package fluxmq
import (
"context"
"os"
"testing"
"time"
"github.com/absmach/magistrala/pkg/messaging"
"github.com/stretchr/testify/require"
)
type integrationHandler struct{}
func (*integrationHandler) Handle(*messaging.Message) error { return nil }
func (*integrationHandler) Cancel() error { return nil }
func TestInternalMetadataPreprovisionedStream(t *testing.T) {
brokerURL := os.Getenv("FLUXMQ_INTERNAL_METADATA_URL")
if brokerURL == "" {
t.Skip("set FLUXMQ_INTERNAL_METADATA_URL to run the trusted stream integration test")
}
ctx := context.Background()
ps, err := NewPubSub(ctx, brokerURL, nil, InternalMetadata(
os.Getenv("FLUXMQ_INTERNAL_METADATA_CERT"),
os.Getenv("FLUXMQ_INTERNAL_METADATA_KEY"),
os.Getenv("FLUXMQ_INTERNAL_METADATA_CA"),
))
require.NoError(t, err)
t.Cleanup(func() { _ = ps.Close() })
stamp := time.Now().UnixNano()
topic := "m/integration-domain/c/integration-channel/" + time.Unix(0, stamp).Format("150405.000000000")
handler := &integrationHandler{}
subscribeErr := ps.Subscribe(ctx, messaging.SubscriberConfig{
ID: "internal-metadata-integration",
Topic: "m/#",
DeliveryPolicy: messaging.DeliverNewPolicy,
Handler: handler,
})
if os.Getenv("FLUXMQ_INTERNAL_METADATA_EXPECT_SUBSCRIBE_ERROR") == "true" {
require.Error(t, subscribeErr)
return
}
require.NoError(t, subscribeErr)
msg := &messaging.Message{
Domain: "integration-domain",
Channel: "integration-channel",
Subtopic: time.Unix(0, stamp).Format("150405.000000000"),
Payload: []byte("metadata-round-trip"),
Publisher: "rules-engine",
Protocol: "internal",
Metadata: map[string]string{
"magistrala.re.trace": "signed-trace",
"other": "preserved",
},
}
require.NoError(t, ps.Publish(ctx, topic, msg))
}