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

hanahmily pushed a commit to branch sidx/query
in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb.git

commit a58c845869b5880de0d8d1aab9418643cc3d6616
Author: Gao Hongtao <[email protected]>
AuthorDate: Thu Aug 28 07:17:12 2025 +0800

    Refactor tag handling in tests: Introduce constants for tag names to 
improve code clarity and maintainability. Update test cases to utilize these 
constants, ensuring consistency across tag usage. Enhance tag copying logic in 
tests to ensure proper handling of tag attributes during element comparisons.
---
 banyand/internal/sidx/element_test.go | 21 +++++++++++++--------
 banyand/internal/sidx/part_test.go    | 30 ++++++++++++++++++++++++++++--
 2 files changed, 41 insertions(+), 10 deletions(-)

diff --git a/banyand/internal/sidx/element_test.go 
b/banyand/internal/sidx/element_test.go
index 5d2dfdfd..b12b9cb5 100644
--- a/banyand/internal/sidx/element_test.go
+++ b/banyand/internal/sidx/element_test.go
@@ -28,6 +28,11 @@ import (
        pbv1 "github.com/apache/skywalking-banyandb/pkg/pb/v1"
 )
 
+const (
+       tag1Name = "tag1"
+       tag2Name = "tag2"
+)
+
 func TestElementPoolAllocation(t *testing.T) {
        // Test pool allocation correctness
        t.Run("elements pool allocation", func(t *testing.T) {
@@ -90,10 +95,10 @@ func TestElementReset(t *testing.T) {
                es.data = [][]byte{[]byte("data1"), []byte("data2"), 
[]byte("data3")}
                // Create tag pointers
                tag1 := generateTag()
-               tag1.name = "tag1"
+               tag1.name = tag1Name
                tag1.value = []byte("value1")
                tag2 := generateTag()
-               tag2.name = "tag2"
+               tag2.name = tag2Name
                tag2.value = []byte("value2")
                tag3 := generateTag()
                tag3.name = "tag3"
@@ -138,10 +143,10 @@ func TestSizeCalculation(t *testing.T) {
                es.data = [][]byte{[]byte("data1"), []byte("data2")} // 5 + 5 = 
10 bytes
                // Create tag pointers
                tag1 := generateTag()
-               tag1.name = "tag1"
+               tag1.name = tag1Name
                tag1.value = []byte("val1")
                tag2 := generateTag()
-               tag2.name = "tag2"
+               tag2.name = tag2Name
                tag2.value = []byte("val2")
                es.tags = [][]*tag{
                        {tag1}, // 4 + 4 + 1 = 9 bytes
@@ -166,9 +171,9 @@ func TestElementsSorting(t *testing.T) {
                tag3 := generateTag()
                tag3.name = "tag3"
                tag1 := generateTag()
-               tag1.name = "tag1"
+               tag1.name = tag1Name
                tag2 := generateTag()
-               tag2.name = "tag2"
+               tag2.name = tag2Name
                tag1b := generateTag()
                tag1b.name = "tag1b"
                es.tags = [][]*tag{
@@ -204,9 +209,9 @@ func TestElementsSorting(t *testing.T) {
                es.data = [][]byte{[]byte("data2"), []byte("data1"), 
[]byte("data3")}
                // Create tag pointers
                tag2 := generateTag()
-               tag2.name = "tag2"
+               tag2.name = tag2Name
                tag1 := generateTag()
-               tag1.name = "tag1"
+               tag1.name = tag1Name
                tag3 := generateTag()
                tag3.name = "tag3"
                es.tags = [][]*tag{
diff --git a/banyand/internal/sidx/part_test.go 
b/banyand/internal/sidx/part_test.go
index 0f4ec48e..98748f4e 100644
--- a/banyand/internal/sidx/part_test.go
+++ b/banyand/internal/sidx/part_test.go
@@ -424,7 +424,18 @@ func TestMemPartFlushAndReadAllRoundTrip(t *testing.T) {
                                combined.seriesIDs = append(combined.seriesIDs, 
elems.seriesIDs...)
                                combined.userKeys = append(combined.userKeys, 
elems.userKeys...)
                                combined.data = append(combined.data, 
elems.data...)
-                               combined.tags = append(combined.tags, 
elems.tags...)
+                               for _, tagSlice := range elems.tags {
+                                       newTagSlice := make([]*tag, 0, 
len(tagSlice))
+                                       for _, t := range tagSlice {
+                                               newTag := generateTag()
+                                               newTag.name = t.name
+                                               newTag.value = 
append([]byte(nil), t.value...)
+                                               newTag.valueType = t.valueType
+                                               newTag.indexed = t.indexed
+                                               newTagSlice = 
append(newTagSlice, newTag)
+                                       }
+                                       combined.tags = append(combined.tags, 
newTagSlice)
+                               }
                        }
 
                        // Create a clean copy of original elements for 
comparison (avoid sorting corruption)
@@ -434,7 +445,18 @@ func TestMemPartFlushAndReadAllRoundTrip(t *testing.T) {
                        originalCopy.seriesIDs = append(originalCopy.seriesIDs, 
tt.elements.seriesIDs...)
                        originalCopy.userKeys = append(originalCopy.userKeys, 
tt.elements.userKeys...)
                        originalCopy.data = append(originalCopy.data, 
tt.elements.data...)
-                       originalCopy.tags = append(originalCopy.tags, 
tt.elements.tags...)
+                       for _, tagSlice := range tt.elements.tags {
+                               newTagSlice := make([]*tag, 0, len(tagSlice))
+                               for _, t := range tagSlice {
+                                       newTag := generateTag()
+                                       newTag.name = t.name
+                                       newTag.value = append([]byte(nil), 
t.value...)
+                                       newTag.valueType = t.valueType
+                                       newTag.indexed = t.indexed
+                                       newTagSlice = append(newTagSlice, 
newTag)
+                               }
+                               originalCopy.tags = append(originalCopy.tags, 
newTagSlice)
+                       }
 
                        // Sort both original copy and result for comparison
                        sort.Sort(originalCopy)
@@ -515,6 +537,10 @@ func compareElements(t *testing.T, expected, actual 
*elements) {
                sort.Slice(actualTags, func(a, b int) bool {
                        return actualTags[a].name < actualTags[b].name
                })
+               for i, tag := range expectedTags {
+                       fmt.Printf("expected tag %d: %s\n", i, tag.name)
+                       fmt.Printf("actual tag %d: %s\n", i, actualTags[i].name)
+               }
 
                for j := range expectedTags {
                        assert.Equal(t, expectedTags[j].name, 
actualTags[j].name,

Reply via email to