You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@seata.apache.org by ji...@apache.org on 2025/11/07 16:08:27 UTC

(incubator-seata-go) branch master updated: test: improve test coverage for pkg/protocol/branch (#982)

This is an automated email from the ASF dual-hosted git repository.

jimin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-seata-go.git


The following commit(s) were added to refs/heads/master by this push:
     new 9ca5bd82 test: improve test coverage for pkg/protocol/branch (#982)
9ca5bd82 is described below

commit 9ca5bd826a58dbd4ff04edd8cd279e62ce10324d
Author: EVERFID <16...@users.noreply.github.com>
AuthorDate: Sat Nov 8 00:08:22 2025 +0800

    test: improve test coverage for pkg/protocol/branch (#982)
---
 pkg/protocol/branch/branch_test.go | 66 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)

diff --git a/pkg/protocol/branch/branch_test.go b/pkg/protocol/branch/branch_test.go
new file mode 100644
index 00000000..b521b40e
--- /dev/null
+++ b/pkg/protocol/branch/branch_test.go
@@ -0,0 +1,66 @@
+/*
+ * 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 branch
+
+import (
+	"fmt"
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+)
+
+func TestBranchStatus_String_AllCases(t *testing.T) {
+	tests := []struct {
+		status   BranchStatus
+		expected string
+	}{
+		{BranchStatusUnknown, "Unknown"},
+		{BranchStatusRegistered, "Registered"},
+		{BranchStatusPhaseoneDone, "PhaseoneDone"},
+		{BranchStatusPhaseoneFailed, "PhaseoneFailed"},
+		{BranchStatusPhaseoneTimeout, "PhaseoneTimeout"},
+		{BranchStatusPhasetwoCommitted, "PhasetwoCommitted"},
+		{BranchStatusPhasetwoCommitFailedRetryable, "PhasetwoCommitFailedRetryable"},
+		{BranchStatusPhasetwoCommitFailedUnretryable, "CommitFailedUnretryable"},
+		{BranchStatusPhasetwoRollbacked, "PhasetwoRollbacked"},
+		{BranchStatusPhasetwoRollbackFailedRetryable, "RollbackFailedRetryable"},
+		{BranchStatusPhasetwoRollbackFailedUnretryable, "RollbackFailedUnretryable"},
+		{BranchStatus(99), "99"}, // default case
+	}
+
+	for i, tt := range tests {
+		actual := tt.status.String()
+		assert.Equal(t, tt.expected, actual, "test case %d failed", i)
+
+	}
+}
+
+func TestBranchType_Constants(t *testing.T) {
+	assert.Equal(t, int8(-1), int8(BranchTypeUnknow))
+	assert.Equal(t, int8(0), int8(BranchTypeAT))
+	assert.Equal(t, int8(1), int8(BranchTypeTCC))
+	assert.Equal(t, int8(2), int8(BranchTypeSAGA))
+	assert.Equal(t, int8(3), int8(BranchTypeXA))
+}
+
+func TestBranchStatus_EnumOrder(t *testing.T) {
+	for i := 0; i <= int(BranchStatusPhasetwoRollbackFailedUnretryable); i++ {
+		s := BranchStatus(i)
+		assert.Contains(t, fmt.Sprintf("%T", s), "branch.BranchStatus")
+	}
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org