@@ -5,10 +5,12 @@ import (
5
5
"reflect"
6
6
"sort"
7
7
"testing"
8
+ "unsafe"
8
9
9
10
"github.com/prometheus/common/model"
10
11
"github.com/prometheus/prometheus/pkg/labels"
11
12
"github.com/prometheus/prometheus/pkg/textparse"
13
+ "github.com/stretchr/testify/assert"
12
14
"github.com/thanos-io/thanos/pkg/testutil"
13
15
)
14
16
@@ -113,6 +115,30 @@ func TestMetricMetadataToMetricTypeToMetricType(t *testing.T) {
113
115
}
114
116
}
115
117
118
+ func TestFromLabelAdaptersToLabels (t * testing.T ) {
119
+ input := []LabelAdapter {{Name : "hello" , Value : "world" }}
120
+ expected := labels.Labels {labels.Label {Name : "hello" , Value : "world" }}
121
+ actual := FromLabelAdaptersToLabels (input )
122
+
123
+ assert .Equal (t , expected , actual )
124
+
125
+ // All strings must NOT be copied.
126
+ assert .Equal (t , uintptr (unsafe .Pointer (& input [0 ].Name )), uintptr (unsafe .Pointer (& actual [0 ].Name )))
127
+ assert .Equal (t , uintptr (unsafe .Pointer (& input [0 ].Value )), uintptr (unsafe .Pointer (& actual [0 ].Value )))
128
+ }
129
+
130
+ func TestFromLabelAdaptersToLabelsWithCopy (t * testing.T ) {
131
+ input := []LabelAdapter {{Name : "hello" , Value : "world" }}
132
+ expected := labels.Labels {labels.Label {Name : "hello" , Value : "world" }}
133
+ actual := FromLabelAdaptersToLabelsWithCopy (input )
134
+
135
+ assert .Equal (t , expected , actual )
136
+
137
+ // All strings must be copied.
138
+ assert .NotEqual (t , uintptr (unsafe .Pointer (& input [0 ].Name )), uintptr (unsafe .Pointer (& actual [0 ].Name )))
139
+ assert .NotEqual (t , uintptr (unsafe .Pointer (& input [0 ].Value )), uintptr (unsafe .Pointer (& actual [0 ].Value )))
140
+ }
141
+
116
142
func TestQueryResponse (t * testing.T ) {
117
143
want := buildTestMatrix (10 , 10 , 10 )
118
144
have := FromQueryResponse (ToQueryResponse (want ))
0 commit comments