Skip to content

Commit ff45986

Browse files
committed
fix test
Signed-off-by: SungJin1212 <tjdwls1201@gmail.com>
1 parent e1531d8 commit ff45986

File tree

5 files changed

+24
-18
lines changed

5 files changed

+24
-18
lines changed

integration/utf8_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ overrides:
133133
require.NoError(t, writeFileToSharedDir(s, "alertmanager_configs", []byte{}))
134134

135135
// Start Cortex.
136-
cortex := e2ecortex.NewSingleBinary("cortex", flags, "", 9009, 9095)
136+
cortex := e2ecortex.NewSingleBinary("cortex", flags, "")
137137
require.NoError(t, s.StartAndWaitReady(cortex))
138138

139139
groupLabels := map[string]string{
@@ -215,9 +215,9 @@ func Test_PushQuery_UTF8(t *testing.T) {
215215

216216
metadata := []prompb.MetricMetadata{
217217
{
218-
MetricFamilyName: fmt.Sprintf("metadata.name"),
219-
Help: fmt.Sprintf("metadata.help"),
220-
Unit: fmt.Sprintf("metadata.unit"),
218+
MetricFamilyName: "metadata.name",
219+
Help: "metadata.help",
220+
Unit: "metadata.unit",
221221
},
222222
}
223223

pkg/cortex/cortex.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ func New(cfg Config) (*Cortex, error) {
383383
}
384384

385385
// set name validation scheme
386-
model.NameValidationScheme = cfg.NameValidationScheme
386+
model.NameValidationScheme = cfg.NameValidationScheme //nolint:staticcheck
387387

388388
cortex.setupThanosTracing()
389389
cortex.setupGRPCHeaderForwarding()

pkg/cortex/cortex_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func TestCortex(t *testing.T) {
4646
// these values are set as defaults but since we aren't registering them, we
4747
// need to include the defaults here. These were hardcoded in a previous version
4848
// of weaveworks server.
49+
NameValidationScheme: model.LegacyValidation,
4950
Server: server.Config{
5051
GRPCListenNetwork: server.DefaultNetwork,
5152
HTTPListenNetwork: server.DefaultNetwork,
@@ -252,9 +253,10 @@ func TestGrpcAuthMiddleware(t *testing.T) {
252253
prepareGlobalMetricsRegistry(t)
253254

254255
cfg := Config{
255-
AuthEnabled: true, // We must enable this to enable Auth middleware for gRPC server.
256-
Server: getServerConfig(t),
257-
Target: []string{API}, // Something innocent that doesn't require much config.
256+
AuthEnabled: true, // We must enable this to enable Auth middleware for gRPC server.
257+
Server: getServerConfig(t),
258+
Target: []string{API}, // Something innocent that doesn't require much config.
259+
NameValidationScheme: model.LegacyValidation,
258260
}
259261

260262
msch := &mockGrpcServiceHandler{}

pkg/distributor/distributor_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3198,8 +3198,6 @@ func prepare(tb testing.TB, cfg prepConfig) ([]*Distributor, []*mockIngester, []
31983198
if cfg.nameValidationScheme == model.UTF8Validation {
31993199
distributorCfg.NameValidationScheme = cfg.nameValidationScheme
32003200
}
3201-
// set name validation scheme
3202-
model.NameValidationScheme = distributorCfg.NameValidationScheme
32033201

32043202
if cfg.shuffleShardEnabled {
32053203
distributorCfg.ShardingStrategy = util.ShardingStrategyShuffle

pkg/util/validation/limits_test.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,23 +125,29 @@ func TestLimits_Validate(t *testing.T) {
125125
expected: errInvalidLabelValue,
126126
},
127127
"utf8: external-labels utf8 label name and value": {
128-
limits: Limits{RulerExternalLabels: labels.FromStrings("test.utf8.metric", "😄")},
129-
expected: nil,
128+
limits: Limits{RulerExternalLabels: labels.FromStrings("test.utf8.metric", "😄")},
129+
expected: nil,
130+
nameValidationScheme: model.UTF8Validation,
130131
},
131132
"utf8: external-labels invalid label name": {
132-
limits: Limits{RulerExternalLabels: labels.FromStrings("test.\xc5.metric", "😄")},
133-
expected: errInvalidLabelName,
133+
limits: Limits{RulerExternalLabels: labels.FromStrings("test.\xc5.metric", "😄")},
134+
expected: errInvalidLabelName,
135+
nameValidationScheme: model.UTF8Validation,
134136
},
135137
"utf8: external-labels invalid label value": {
136-
limits: Limits{RulerExternalLabels: labels.FromStrings("test.utf8.metric", "test.\xc5.value")},
137-
expected: errInvalidLabelValue,
138+
limits: Limits{RulerExternalLabels: labels.FromStrings("test.utf8.metric", "test.\xc5.value")},
139+
expected: errInvalidLabelValue,
140+
nameValidationScheme: model.UTF8Validation,
138141
},
139142
}
140143

141144
for testName, testData := range tests {
142-
143145
t.Run(testName, func(t *testing.T) {
144-
assert.ErrorIs(t, testData.limits.Validate(testData.nameValidationScheme, testData.shardByAllLabels, testData.activeSeriesMetricsEnabled), testData.expected)
146+
nameValidationScheme := model.LegacyValidation
147+
if testData.nameValidationScheme == model.UTF8Validation {
148+
nameValidationScheme = testData.nameValidationScheme
149+
}
150+
assert.ErrorIs(t, testData.limits.Validate(nameValidationScheme, testData.shardByAllLabels, testData.activeSeriesMetricsEnabled), testData.expected)
145151
})
146152
}
147153
}

0 commit comments

Comments
 (0)