yihao.dai 51f69f32d0
feat: Add CDC support (#44124)
This PR implements a new CDC service for Milvus 2.6, providing log-based
cross-cluster replication.

issue: https://github.com/milvus-io/milvus/issues/44123

---------

Signed-off-by: bigsheeper <yihao.dai@zilliz.com>
Signed-off-by: chyezh <chyezh@outlook.com>
Co-authored-by: chyezh <chyezh@outlook.com>
2025-09-16 16:32:01 +08:00

47 lines
1.1 KiB
Go

package contextutil
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc/metadata"
)
func TestWithClusterID(t *testing.T) {
ctx := WithClusterID(context.Background(), "test-cluster-id")
md, ok := metadata.FromOutgoingContext(ctx)
assert.True(t, ok)
assert.NotNil(t, md)
ctx = metadata.NewIncomingContext(context.Background(), md)
clusterID, err := GetClusterID(ctx)
assert.Nil(t, err)
assert.Equal(t, "test-cluster-id", clusterID)
// panic case.
assert.NotPanics(t, func() { WithClusterID(context.Background(), "") })
}
func TestGetClusterID(t *testing.T) {
// empty context.
clusterID, err := GetClusterID(context.Background())
assert.Error(t, err)
assert.Empty(t, clusterID)
// key not exist.
md := metadata.New(map[string]string{})
clusterID, err = GetClusterID(metadata.NewIncomingContext(context.Background(), md))
assert.Error(t, err)
assert.Empty(t, clusterID)
// invalid value.
md = metadata.New(map[string]string{
clusterIDKey: "",
})
clusterID, err = GetClusterID(metadata.NewIncomingContext(context.Background(), md))
assert.Error(t, err)
assert.Empty(t, clusterID)
}