You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by zi...@apache.org on 2025/07/02 06:09:33 UTC
(pulsar-client-go) branch master updated: Fix: namespace schema compatibility strategy (#1386)
This is an automated email from the ASF dual-hosted git repository.
zike pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-client-go.git
The following commit(s) were added to refs/heads/master by this push:
new 58ac256f Fix: namespace schema compatibility strategy (#1386)
58ac256f is described below
commit 58ac256fbcb2b029477e09c4c00306478780e5f5
Author: Rui Fu <fr...@users.noreply.github.com>
AuthorDate: Wed Jul 2 14:09:27 2025 +0800
Fix: namespace schema compatibility strategy (#1386)
### Motivation
Making pulsar-client-go support both https://github.com/apache/pulsar/blob/master/pulsar-client-admin-api/src/main/java/org/apache/pulsar/common/policies/data/SchemaAutoUpdateCompatibilityStrategy.java and https://github.com/apache/pulsar/blob/master/pulsar-client-admin-api/src/main/java/org/apache/pulsar/common/policies/data/SchemaCompatibilityStrategy.java
---
pulsaradmin/pkg/admin/namespace.go | 40 ++-
pulsaradmin/pkg/admin/namespace_test.go | 154 +++++++++
pulsaradmin/pkg/admin/schema_test.go | 4 +-
pulsaradmin/pkg/utils/policies.go | 51 +--
pulsaradmin/pkg/utils/schema_strategy.go | 69 +++-
pulsaradmin/pkg/utils/schema_strategy_test.go | 437 ++++++++++++++++++++++++++
6 files changed, 712 insertions(+), 43 deletions(-)
diff --git a/pulsaradmin/pkg/admin/namespace.go b/pulsaradmin/pkg/admin/namespace.go
index e92f020c..1ab206de 100644
--- a/pulsaradmin/pkg/admin/namespace.go
+++ b/pulsaradmin/pkg/admin/namespace.go
@@ -90,14 +90,24 @@ type Namespaces interface {
// GetSchemaValidationEnforced returns schema validation enforced for namespace
GetSchemaValidationEnforced(namespace utils.NameSpaceName) (bool, error)
- // SetSchemaAutoUpdateCompatibilityStrategy sets the strategy used to check the a new schema provided
+ // SetSchemaAutoUpdateCompatibilityStrategy sets the strategy used to check the new schema provided
// by a producer is compatible with the current schema before it is installed
SetSchemaAutoUpdateCompatibilityStrategy(namespace utils.NameSpaceName,
+ strategy utils.SchemaAutoUpdateCompatibilityStrategy) error
+
+ // GetSchemaAutoUpdateCompatibilityStrategy returns the strategy used to check the new schema provided
+ // by a producer is compatible with the current schema before it is installed
+ GetSchemaAutoUpdateCompatibilityStrategy(namespace utils.NameSpaceName) (
+ utils.SchemaAutoUpdateCompatibilityStrategy, error)
+
+ // SetSchemaCompatibilityStrategy sets the strategy used to check the new schema provided
+ // by a producer is compatible with the current schema before it is installed
+ SetSchemaCompatibilityStrategy(namespace utils.NameSpaceName,
strategy utils.SchemaCompatibilityStrategy) error
- // GetSchemaAutoUpdateCompatibilityStrategy returns the strategy used to check the a new schema provided
+ // GetSchemaCompatibilityStrategy returns the strategy used to check the new schema provided
// by a producer is compatible with the current schema before it is installed
- GetSchemaAutoUpdateCompatibilityStrategy(namespace utils.NameSpaceName) (utils.SchemaCompatibilityStrategy, error)
+ GetSchemaCompatibilityStrategy(namespace utils.NameSpaceName) (utils.SchemaCompatibilityStrategy, error)
// ClearOffloadDeleteLag clears the offload deletion lag for a namespace.
ClearOffloadDeleteLag(namespace utils.NameSpaceName) error
@@ -497,13 +507,13 @@ func (n *namespaces) GetSchemaValidationEnforced(namespace utils.NameSpaceName)
}
func (n *namespaces) SetSchemaAutoUpdateCompatibilityStrategy(namespace utils.NameSpaceName,
- strategy utils.SchemaCompatibilityStrategy) error {
+ strategy utils.SchemaAutoUpdateCompatibilityStrategy) error {
endpoint := n.pulsar.endpoint(n.basePath, namespace.String(), "schemaAutoUpdateCompatibilityStrategy")
return n.pulsar.Client.Put(endpoint, strategy.String())
}
func (n *namespaces) GetSchemaAutoUpdateCompatibilityStrategy(namespace utils.NameSpaceName) (
- utils.SchemaCompatibilityStrategy, error) {
+ utils.SchemaAutoUpdateCompatibilityStrategy, error) {
endpoint := n.pulsar.endpoint(n.basePath, namespace.String(), "schemaAutoUpdateCompatibilityStrategy")
b, err := n.pulsar.Client.GetWithQueryParams(endpoint, nil, nil, false)
if err != nil {
@@ -516,6 +526,26 @@ func (n *namespaces) GetSchemaAutoUpdateCompatibilityStrategy(namespace utils.Na
return s, nil
}
+func (n *namespaces) SetSchemaCompatibilityStrategy(namespace utils.NameSpaceName,
+ strategy utils.SchemaCompatibilityStrategy) error {
+ endpoint := n.pulsar.endpoint(n.basePath, namespace.String(), "schemaCompatibilityStrategy")
+ return n.pulsar.Client.Put(endpoint, strategy.String())
+}
+
+func (n *namespaces) GetSchemaCompatibilityStrategy(namespace utils.NameSpaceName) (
+ utils.SchemaCompatibilityStrategy, error) {
+ endpoint := n.pulsar.endpoint(n.basePath, namespace.String(), "schemaCompatibilityStrategy")
+ b, err := n.pulsar.Client.GetWithQueryParams(endpoint, nil, nil, false)
+ if err != nil {
+ return "", err
+ }
+ s, err := utils.ParseSchemaCompatibilityStrategy(strings.ReplaceAll(string(b), "\"", ""))
+ if err != nil {
+ return "", err
+ }
+ return s, nil
+}
+
func (n *namespaces) ClearOffloadDeleteLag(namespace utils.NameSpaceName) error {
endpoint := n.pulsar.endpoint(n.basePath, namespace.String(), "offloadDeletionLagMs")
return n.pulsar.Client.Delete(endpoint)
diff --git a/pulsaradmin/pkg/admin/namespace_test.go b/pulsaradmin/pkg/admin/namespace_test.go
index 8fa687ff..8161e6be 100644
--- a/pulsaradmin/pkg/admin/namespace_test.go
+++ b/pulsaradmin/pkg/admin/namespace_test.go
@@ -19,6 +19,7 @@ package admin
import (
"testing"
+ "time"
"github.com/apache/pulsar-client-go/pulsaradmin/pkg/admin/config"
"github.com/apache/pulsar-client-go/pulsaradmin/pkg/rest"
@@ -341,3 +342,156 @@ func TestNamespaces_GetOffloadThresholdInSeconds(t *testing.T) {
expected := int64(60)
assert.Equal(t, expected, offloadThresholdInSeconds)
}
+
+func TestNamespaces_SetSchemaCompatibilityStrategy(t *testing.T) {
+ config := &config.Config{}
+ admin, err := New(config)
+ require.NoError(t, err)
+ require.NotNil(t, admin)
+
+ tests := []struct {
+ name string
+ namespace string
+ strategy utils.SchemaCompatibilityStrategy
+ errReason string
+ }{
+ {
+ name: "Set Undefined strategy",
+ namespace: "public/default",
+ strategy: utils.SchemaCompatibilityStrategyUndefined,
+ errReason: "",
+ },
+ {
+ name: "Set AlwaysIncompatible strategy",
+ namespace: "public/default",
+ strategy: utils.SchemaCompatibilityStrategyAlwaysIncompatible,
+ errReason: "",
+ },
+ {
+ name: "Set AlwaysCompatible strategy",
+ namespace: "public/default",
+ strategy: utils.SchemaCompatibilityStrategyAlwaysCompatible,
+ errReason: "",
+ },
+ {
+ name: "Set Backward strategy",
+ namespace: "public/default",
+ strategy: utils.SchemaCompatibilityStrategyBackward,
+ errReason: "",
+ },
+ {
+ name: "Set Forward strategy",
+ namespace: "public/default",
+ strategy: utils.SchemaCompatibilityStrategyForward,
+ errReason: "",
+ },
+ {
+ name: "Set Full strategy",
+ namespace: "public/default",
+ strategy: utils.SchemaCompatibilityStrategyFull,
+ errReason: "",
+ },
+ {
+ name: "Set BackwardTransitive strategy",
+ namespace: "public/default",
+ strategy: utils.SchemaCompatibilityStrategyBackwardTransitive,
+ errReason: "",
+ },
+ {
+ name: "Set ForwardTransitive strategy",
+ namespace: "public/default",
+ strategy: utils.SchemaCompatibilityStrategyForwardTransitive,
+ errReason: "",
+ },
+ {
+ name: "Set FullTransitive strategy",
+ namespace: "public/default",
+ strategy: utils.SchemaCompatibilityStrategyFullTransitive,
+ errReason: "",
+ },
+ {
+ name: "Set strategy on non-existent namespace",
+ namespace: "public/nonexist",
+ strategy: utils.SchemaCompatibilityStrategyFull,
+ errReason: "Namespace does not exist",
+ },
+ {
+ name: "Set strategy on non-existent tenant",
+ namespace: "non-exist/default",
+ strategy: utils.SchemaCompatibilityStrategyFull,
+ errReason: "Tenant does not exist",
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ namespace, _ := utils.GetNamespaceName(tt.namespace)
+ err := admin.Namespaces().SetSchemaCompatibilityStrategy(*namespace, tt.strategy)
+
+ // Skip test if network connection fails (Pulsar server not running)
+ if err != nil {
+ if _, ok := err.(rest.Error); !ok {
+ t.Skipf("Skipping test due to network error: %v", err)
+ }
+ }
+
+ if tt.errReason == "" {
+ assert.Equal(t, nil, err)
+ } else {
+ if restError, ok := err.(rest.Error); ok {
+ assert.Equal(t, tt.errReason, restError.Reason)
+ }
+ }
+ })
+ }
+}
+
+func TestNamespaces_GetSchemaCompatibilityStrategy(t *testing.T) {
+ config := &config.Config{}
+ admin, err := New(config)
+ require.NoError(t, err)
+ require.NotNil(t, admin)
+
+ namespace, _ := utils.GetNamespaceName("public/default")
+
+ // Test setting and getting different strategies
+ testStrategies := []utils.SchemaCompatibilityStrategy{
+ utils.SchemaCompatibilityStrategyFull,
+ utils.SchemaCompatibilityStrategyBackward,
+ utils.SchemaCompatibilityStrategyForward,
+ utils.SchemaCompatibilityStrategyAlwaysCompatible,
+ }
+
+ for _, strategy := range testStrategies {
+ // Set the schema compatibility strategy
+ err = admin.Namespaces().SetSchemaCompatibilityStrategy(*namespace, strategy)
+ if err != nil {
+ t.Skipf("Skipping test due to connection error: %v", err)
+ }
+
+ // Wait for the strategy to be set
+ time.Sleep(5 * time.Second)
+
+ // Get and verify the strategy
+ retrievedStrategy, err := admin.Namespaces().GetSchemaCompatibilityStrategy(*namespace)
+ if err != nil {
+ t.Skipf("Skipping test due to connection error: %v", err)
+ }
+ assert.Equal(t, strategy, retrievedStrategy)
+ }
+
+ // Test getting default strategy (should be Undefined after reset)
+ err = admin.Namespaces().SetSchemaCompatibilityStrategy(*namespace, utils.SchemaCompatibilityStrategyUndefined)
+ if err != nil {
+ t.Skipf("Skipping test due to connection error: %v", err)
+ }
+
+ // Wait for the strategy to be set
+ time.Sleep(5 * time.Second)
+
+ defaultStrategy, err := admin.Namespaces().GetSchemaCompatibilityStrategy(*namespace)
+ if err != nil {
+ t.Skipf("Skipping test due to connection error: %v", err)
+ }
+ assert.Equal(t, utils.SchemaCompatibilityStrategyUndefined, defaultStrategy)
+}
diff --git a/pulsaradmin/pkg/admin/schema_test.go b/pulsaradmin/pkg/admin/schema_test.go
index 1b56fdc1..a29fad12 100644
--- a/pulsaradmin/pkg/admin/schema_test.go
+++ b/pulsaradmin/pkg/admin/schema_test.go
@@ -133,12 +133,12 @@ func TestSchemas_CreateSchemaBySchemaInfo(t *testing.T) {
compatibility, err := admin.Schemas().TestCompatibilityWithSchemaInfo(topic, schemaInfo)
assert.NoError(t, err)
assert.Equal(t, compatibility.IsCompatibility, true)
- assert.Equal(t, compatibility.SchemaCompatibilityStrategy, utils.SchemaCompatibilityStrategy("FULL"))
+ assert.Equal(t, compatibility.SchemaCompatibilityStrategy, utils.SchemaCompatibilityStrategyFull)
compatibility, err = admin.Schemas().TestCompatibilityWithPostSchemaPayload(topic, schemaPayload)
assert.NoError(t, err)
assert.Equal(t, compatibility.IsCompatibility, true)
- assert.Equal(t, compatibility.SchemaCompatibilityStrategy, utils.SchemaCompatibilityStrategy("FULL"))
+ assert.Equal(t, compatibility.SchemaCompatibilityStrategy, utils.SchemaCompatibilityStrategyFull)
err = admin.Schemas().ForceDeleteSchema(topic)
assert.NoError(t, err)
diff --git a/pulsaradmin/pkg/utils/policies.go b/pulsaradmin/pkg/utils/policies.go
index 3d727994..a75b6d66 100644
--- a/pulsaradmin/pkg/utils/policies.go
+++ b/pulsaradmin/pkg/utils/policies.go
@@ -47,33 +47,36 @@ type Policies struct {
PublishMaxMessageRate map[string]PublishRate `json:"publishMaxMessageRate"`
ClusterSubscribeRate map[string]SubscribeRate `json:"clusterSubscribeRate"`
TopicAutoCreationConfig *TopicAutoCreationConfig `json:"autoTopicCreationOverride"`
- SchemaCompatibilityStrategy SchemaCompatibilityStrategy `json:"schema_auto_update_compatibility_strategy"`
- AuthPolicies AuthPolicies `json:"auth_policies"`
- SubscriptionAuthMode SubscriptionAuthMode `json:"subscription_auth_mode"`
- IsAllowAutoUpdateSchema *bool `json:"is_allow_auto_update_schema"`
+ //nolint:lll
+ SchemaAutoUpdateCompatibilityStrategy SchemaAutoUpdateCompatibilityStrategy `json:"schema_auto_update_compatibility_strategy"`
+ SchemaCompatibilityStrategy SchemaCompatibilityStrategy `json:"schema_compatibility_strategy"`
+ AuthPolicies AuthPolicies `json:"auth_policies"`
+ SubscriptionAuthMode SubscriptionAuthMode `json:"subscription_auth_mode"`
+ IsAllowAutoUpdateSchema *bool `json:"is_allow_auto_update_schema"`
}
func NewDefaultPolicies() *Policies {
return &Policies{
- AuthPolicies: *NewAuthPolicies(),
- ReplicationClusters: make([]string, 0, 10),
- BacklogQuotaMap: make(map[BacklogQuotaType]BacklogQuota),
- TopicDispatchRate: make(map[string]DispatchRate),
- SubscriptionDispatchRate: make(map[string]DispatchRate),
- ReplicatorDispatchRate: make(map[string]DispatchRate),
- PublishMaxMessageRate: make(map[string]PublishRate),
- ClusterSubscribeRate: make(map[string]SubscribeRate),
- LatencyStatsSampleRate: make(map[string]int),
- MessageTTLInSeconds: nil,
- Deleted: false,
- EncryptionRequired: false,
- SubscriptionAuthMode: None,
- MaxProducersPerTopic: nil,
- MaxConsumersPerSubscription: nil,
- MaxConsumersPerTopic: nil,
- CompactionThreshold: nil,
- OffloadThreshold: -1,
- SchemaCompatibilityStrategy: Full,
- SchemaValidationEnforced: false,
+ AuthPolicies: *NewAuthPolicies(),
+ ReplicationClusters: make([]string, 0, 10),
+ BacklogQuotaMap: make(map[BacklogQuotaType]BacklogQuota),
+ TopicDispatchRate: make(map[string]DispatchRate),
+ SubscriptionDispatchRate: make(map[string]DispatchRate),
+ ReplicatorDispatchRate: make(map[string]DispatchRate),
+ PublishMaxMessageRate: make(map[string]PublishRate),
+ ClusterSubscribeRate: make(map[string]SubscribeRate),
+ LatencyStatsSampleRate: make(map[string]int),
+ MessageTTLInSeconds: nil,
+ Deleted: false,
+ EncryptionRequired: false,
+ SubscriptionAuthMode: None,
+ MaxProducersPerTopic: nil,
+ MaxConsumersPerSubscription: nil,
+ MaxConsumersPerTopic: nil,
+ CompactionThreshold: nil,
+ OffloadThreshold: -1,
+ SchemaCompatibilityStrategy: SchemaCompatibilityStrategyUndefined,
+ SchemaAutoUpdateCompatibilityStrategy: Full,
+ SchemaValidationEnforced: false,
}
}
diff --git a/pulsaradmin/pkg/utils/schema_strategy.go b/pulsaradmin/pkg/utils/schema_strategy.go
index 176f0e0a..343e0aa6 100644
--- a/pulsaradmin/pkg/utils/schema_strategy.go
+++ b/pulsaradmin/pkg/utils/schema_strategy.go
@@ -17,22 +17,24 @@
package utils
-import "github.com/pkg/errors"
+import (
+ "github.com/pkg/errors"
+)
-type SchemaCompatibilityStrategy string
+type SchemaAutoUpdateCompatibilityStrategy string
const (
- AutoUpdateDisabled SchemaCompatibilityStrategy = "AutoUpdateDisabled"
- Backward SchemaCompatibilityStrategy = "Backward"
- Forward SchemaCompatibilityStrategy = "Forward"
- Full SchemaCompatibilityStrategy = "Full"
- AlwaysCompatible SchemaCompatibilityStrategy = "AlwaysCompatible"
- BackwardTransitive SchemaCompatibilityStrategy = "BackwardTransitive"
- ForwardTransitive SchemaCompatibilityStrategy = "ForwardTransitive"
- FullTransitive SchemaCompatibilityStrategy = "FullTransitive"
+ AutoUpdateDisabled SchemaAutoUpdateCompatibilityStrategy = "AutoUpdateDisabled"
+ Backward SchemaAutoUpdateCompatibilityStrategy = "Backward"
+ Forward SchemaAutoUpdateCompatibilityStrategy = "Forward"
+ Full SchemaAutoUpdateCompatibilityStrategy = "Full"
+ AlwaysCompatible SchemaAutoUpdateCompatibilityStrategy = "AlwaysCompatible"
+ BackwardTransitive SchemaAutoUpdateCompatibilityStrategy = "BackwardTransitive"
+ ForwardTransitive SchemaAutoUpdateCompatibilityStrategy = "ForwardTransitive"
+ FullTransitive SchemaAutoUpdateCompatibilityStrategy = "FullTransitive"
)
-func ParseSchemaAutoUpdateCompatibilityStrategy(str string) (SchemaCompatibilityStrategy, error) {
+func ParseSchemaAutoUpdateCompatibilityStrategy(str string) (SchemaAutoUpdateCompatibilityStrategy, error) {
switch str {
case "AutoUpdateDisabled":
return AutoUpdateDisabled, nil
@@ -51,7 +53,50 @@ func ParseSchemaAutoUpdateCompatibilityStrategy(str string) (SchemaCompatibility
case "FullTransitive":
return FullTransitive, nil
default:
- return "", errors.Errorf("Invalid auth strategy %s", str)
+ return "", errors.Errorf("Invalid schema auto update compatibility strategy %s", str)
+ }
+}
+
+func (s SchemaAutoUpdateCompatibilityStrategy) String() string {
+ return string(s)
+}
+
+type SchemaCompatibilityStrategy string
+
+const (
+ SchemaCompatibilityStrategyUndefined SchemaCompatibilityStrategy = "UNDEFINED"
+ SchemaCompatibilityStrategyAlwaysIncompatible SchemaCompatibilityStrategy = "ALWAYS_INCOMPATIBLE"
+ SchemaCompatibilityStrategyAlwaysCompatible SchemaCompatibilityStrategy = "ALWAYS_COMPATIBLE"
+ SchemaCompatibilityStrategyBackward SchemaCompatibilityStrategy = "BACKWARD"
+ SchemaCompatibilityStrategyForward SchemaCompatibilityStrategy = "FORWARD"
+ SchemaCompatibilityStrategyFull SchemaCompatibilityStrategy = "FULL"
+ SchemaCompatibilityStrategyBackwardTransitive SchemaCompatibilityStrategy = "BACKWARD_TRANSITIVE"
+ SchemaCompatibilityStrategyForwardTransitive SchemaCompatibilityStrategy = "FORWARD_TRANSITIVE"
+ SchemaCompatibilityStrategyFullTransitive SchemaCompatibilityStrategy = "FULL_TRANSITIVE"
+)
+
+func ParseSchemaCompatibilityStrategy(str string) (SchemaCompatibilityStrategy, error) {
+ switch str {
+ case "UNDEFINED":
+ return SchemaCompatibilityStrategyUndefined, nil
+ case "ALWAYS_INCOMPATIBLE":
+ return SchemaCompatibilityStrategyAlwaysIncompatible, nil
+ case "ALWAYS_COMPATIBLE":
+ return SchemaCompatibilityStrategyAlwaysCompatible, nil
+ case "BACKWARD":
+ return SchemaCompatibilityStrategyBackward, nil
+ case "FORWARD":
+ return SchemaCompatibilityStrategyForward, nil
+ case "FULL":
+ return SchemaCompatibilityStrategyFull, nil
+ case "BACKWARD_TRANSITIVE":
+ return SchemaCompatibilityStrategyBackwardTransitive, nil
+ case "FORWARD_TRANSITIVE":
+ return SchemaCompatibilityStrategyForwardTransitive, nil
+ case "FULL_TRANSITIVE":
+ return SchemaCompatibilityStrategyFullTransitive, nil
+ default:
+ return "", errors.Errorf("Invalid schema compatibility strategy %s", str)
}
}
diff --git a/pulsaradmin/pkg/utils/schema_strategy_test.go b/pulsaradmin/pkg/utils/schema_strategy_test.go
new file mode 100644
index 00000000..2658f4c1
--- /dev/null
+++ b/pulsaradmin/pkg/utils/schema_strategy_test.go
@@ -0,0 +1,437 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package utils
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestParseSchemaAutoUpdateCompatibilityStrategy(t *testing.T) {
+ tests := []struct {
+ name string
+ input string
+ expected SchemaAutoUpdateCompatibilityStrategy
+ wantErr bool
+ }{
+ // Valid cases - exact match
+ {
+ name: "AutoUpdateDisabled",
+ input: "AutoUpdateDisabled",
+ expected: AutoUpdateDisabled,
+ wantErr: false,
+ },
+ {
+ name: "Backward",
+ input: "Backward",
+ expected: Backward,
+ wantErr: false,
+ },
+ {
+ name: "Forward",
+ input: "Forward",
+ expected: Forward,
+ wantErr: false,
+ },
+ {
+ name: "Full",
+ input: "Full",
+ expected: Full,
+ wantErr: false,
+ },
+ {
+ name: "AlwaysCompatible",
+ input: "AlwaysCompatible",
+ expected: AlwaysCompatible,
+ wantErr: false,
+ },
+ {
+ name: "BackwardTransitive",
+ input: "BackwardTransitive",
+ expected: BackwardTransitive,
+ wantErr: false,
+ },
+ {
+ name: "ForwardTransitive",
+ input: "ForwardTransitive",
+ expected: ForwardTransitive,
+ wantErr: false,
+ },
+ {
+ name: "FullTransitive",
+ input: "FullTransitive",
+ expected: FullTransitive,
+ wantErr: false,
+ },
+ // Valid cases - case insensitive
+ {
+ name: "autoupdatedisabled lowercase",
+ input: "autoupdatedisabled",
+ expected: "",
+ wantErr: true,
+ },
+ {
+ name: "BACKWARD uppercase",
+ input: "BACKWARD",
+ expected: "",
+ wantErr: true,
+ },
+ {
+ name: "Forward mixed case",
+ input: "forward",
+ expected: "",
+ wantErr: true,
+ },
+ {
+ name: "FULL uppercase",
+ input: "FULL",
+ expected: "",
+ wantErr: true,
+ },
+ {
+ name: "alwayscompatible lowercase",
+ input: "alwayscompatible",
+ expected: "",
+ wantErr: true,
+ },
+ {
+ name: "BACKWARDTRANSITIVE uppercase",
+ input: "BACKWARDTRANSITIVE",
+ expected: "",
+ wantErr: true,
+ },
+ {
+ name: "forwardtransitive lowercase",
+ input: "forwardtransitive",
+ expected: "",
+ wantErr: true,
+ },
+ {
+ name: "FULLTRANSITIVE uppercase",
+ input: "FULLTRANSITIVE",
+ expected: "",
+ wantErr: true,
+ },
+ // Invalid cases
+ {
+ name: "Invalid strategy",
+ input: "InvalidStrategy",
+ expected: "",
+ wantErr: true,
+ },
+ {
+ name: "Empty string",
+ input: "",
+ expected: "",
+ wantErr: true,
+ },
+ {
+ name: "Random string",
+ input: "RandomString",
+ expected: "",
+ wantErr: true,
+ },
+ {
+ name: "Partial match",
+ input: "Back",
+ expected: "",
+ wantErr: true,
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ result, err := ParseSchemaAutoUpdateCompatibilityStrategy(tt.input)
+
+ if tt.wantErr {
+ assert.Error(t, err)
+ assert.Empty(t, result)
+ assert.Contains(t, err.Error(), "Invalid schema auto update compatibility strategy")
+ } else {
+ assert.NoError(t, err)
+ assert.Equal(t, tt.expected, result)
+ }
+ })
+ }
+}
+
+func TestParseSchemaCompatibilityStrategy(t *testing.T) {
+ tests := []struct {
+ name string
+ input string
+ expected SchemaCompatibilityStrategy
+ wantErr bool
+ }{
+ // Valid cases - exact match
+ {
+ name: "Undefined",
+ input: "UNDEFINED",
+ expected: SchemaCompatibilityStrategyUndefined,
+ wantErr: false,
+ },
+ {
+ name: "AlwaysIncompatible",
+ input: "ALWAYS_INCOMPATIBLE",
+ expected: SchemaCompatibilityStrategyAlwaysIncompatible,
+ wantErr: false,
+ },
+ {
+ name: "AlwaysCompatible",
+ input: "ALWAYS_COMPATIBLE",
+ expected: SchemaCompatibilityStrategyAlwaysCompatible,
+ wantErr: false,
+ },
+ {
+ name: "Backward",
+ input: "BACKWARD",
+ expected: SchemaCompatibilityStrategyBackward,
+ wantErr: false,
+ },
+ {
+ name: "Forward",
+ input: "FORWARD",
+ expected: SchemaCompatibilityStrategyForward,
+ wantErr: false,
+ },
+ {
+ name: "Full",
+ input: "FULL",
+ expected: SchemaCompatibilityStrategyFull,
+ wantErr: false,
+ },
+ {
+ name: "BackwardTransitive",
+ input: "BACKWARD_TRANSITIVE",
+ expected: SchemaCompatibilityStrategyBackwardTransitive,
+ wantErr: false,
+ },
+ {
+ name: "ForwardTransitive",
+ input: "FORWARD_TRANSITIVE",
+ expected: SchemaCompatibilityStrategyForwardTransitive,
+ wantErr: false,
+ },
+ {
+ name: "FullTransitive",
+ input: "FULL_TRANSITIVE",
+ expected: SchemaCompatibilityStrategyFullTransitive,
+ wantErr: false,
+ },
+ // Valid cases - case insensitive
+ {
+ name: "undefined lowercase",
+ input: "undefined",
+ expected: "",
+ wantErr: true,
+ },
+ {
+ name: "ALWAYSINCOMPATIBLE uppercase",
+ input: "ALWAYSINCOMPATIBLE",
+ expected: "",
+ wantErr: true,
+ },
+ {
+ name: "alwayscompatible lowercase",
+ input: "alwayscompatible",
+ expected: "",
+ wantErr: true,
+ },
+ {
+ name: "forward lowercase",
+ input: "forward",
+ expected: "",
+ wantErr: true,
+ },
+ {
+ name: "backwardtransitive lowercase",
+ input: "backwardtransitive",
+ expected: "",
+ wantErr: true,
+ },
+ {
+ name: "FORWARDTRANSITIVE uppercase",
+ input: "FORWARDTRANSITIVE",
+ expected: "",
+ wantErr: true,
+ },
+ {
+ name: "fulltransitive lowercase",
+ input: "fulltransitive",
+ expected: "",
+ wantErr: true,
+ },
+ // Invalid cases
+ {
+ name: "Invalid strategy",
+ input: "InvalidStrategy",
+ expected: "",
+ wantErr: true,
+ },
+ {
+ name: "Empty string",
+ input: "",
+ expected: "",
+ wantErr: true,
+ },
+ {
+ name: "Random string",
+ input: "RandomString",
+ expected: "",
+ wantErr: true,
+ },
+ {
+ name: "Partial match",
+ input: "Back",
+ expected: "",
+ wantErr: true,
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ result, err := ParseSchemaCompatibilityStrategy(tt.input)
+
+ if tt.wantErr {
+ assert.Error(t, err)
+ assert.Empty(t, result)
+ assert.Contains(t, err.Error(), "Invalid schema compatibility strategy")
+ } else {
+ assert.NoError(t, err)
+ assert.Equal(t, tt.expected, result)
+ }
+ })
+ }
+}
+
+func TestSchemaAutoUpdateCompatibilityStrategy_String(t *testing.T) {
+ tests := []struct {
+ name string
+ strategy SchemaAutoUpdateCompatibilityStrategy
+ expected string
+ }{
+ {
+ name: "AutoUpdateDisabled",
+ strategy: AutoUpdateDisabled,
+ expected: "AutoUpdateDisabled",
+ },
+ {
+ name: "Backward",
+ strategy: Backward,
+ expected: "Backward",
+ },
+ {
+ name: "Forward",
+ strategy: Forward,
+ expected: "Forward",
+ },
+ {
+ name: "Full",
+ strategy: Full,
+ expected: "Full",
+ },
+ {
+ name: "AlwaysCompatible",
+ strategy: AlwaysCompatible,
+ expected: "AlwaysCompatible",
+ },
+ {
+ name: "BackwardTransitive",
+ strategy: BackwardTransitive,
+ expected: "BackwardTransitive",
+ },
+ {
+ name: "ForwardTransitive",
+ strategy: ForwardTransitive,
+ expected: "ForwardTransitive",
+ },
+ {
+ name: "FullTransitive",
+ strategy: FullTransitive,
+ expected: "FullTransitive",
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ result := tt.strategy.String()
+ assert.Equal(t, tt.expected, result)
+ })
+ }
+}
+
+func TestSchemaCompatibilityStrategy_String(t *testing.T) {
+ tests := []struct {
+ name string
+ strategy SchemaCompatibilityStrategy
+ expected string
+ }{
+ {
+ name: "Undefined",
+ strategy: SchemaCompatibilityStrategyUndefined,
+ expected: "UNDEFINED",
+ },
+ {
+ name: "AlwaysIncompatible",
+ strategy: SchemaCompatibilityStrategyAlwaysIncompatible,
+ expected: "ALWAYS_INCOMPATIBLE",
+ },
+ {
+ name: "AlwaysCompatible",
+ strategy: SchemaCompatibilityStrategyAlwaysCompatible,
+ expected: "ALWAYS_COMPATIBLE",
+ },
+ {
+ name: "Backward",
+ strategy: SchemaCompatibilityStrategyBackward,
+ expected: "BACKWARD",
+ },
+ {
+ name: "Forward",
+ strategy: SchemaCompatibilityStrategyForward,
+ expected: "FORWARD",
+ },
+ {
+ name: "Full",
+ strategy: SchemaCompatibilityStrategyFull,
+ expected: "FULL",
+ },
+ {
+ name: "BackwardTransitive",
+ strategy: SchemaCompatibilityStrategyBackwardTransitive,
+ expected: "BACKWARD_TRANSITIVE",
+ },
+ {
+ name: "ForwardTransitive",
+ strategy: SchemaCompatibilityStrategyForwardTransitive,
+ expected: "FORWARD_TRANSITIVE",
+ },
+ {
+ name: "FullTransitive",
+ strategy: SchemaCompatibilityStrategyFullTransitive,
+ expected: "FULL_TRANSITIVE",
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ result := tt.strategy.String()
+ assert.Equal(t, tt.expected, result)
+ })
+ }
+}