Skip to content

Commit df5fd43

Browse files
committed
worked on PR comments
1 parent 3f71582 commit df5fd43

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed

internal/config/config.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,9 @@ func validateLabel(labelValue string) bool {
947947
const maxLength = 256
948948
labelPattern := regexp.MustCompile(regexLabelPattern)
949949
if len(labelValue) > maxLength || !labelPattern.MatchString(labelValue) {
950-
slog.Warn("Label value contains unsupported character ", "label_value", labelValue)
950+
slog.Warn("Label value contains unsupported character or exceed maximum length of 256 characters ",
951+
"label_value", labelValue)
952+
951953
return false
952954
}
953955

internal/config/config_test.go

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,51 +1413,56 @@ func createDefaultCollectorConfig() *Collector {
14131413

14141414
func TestValidateLabel(t *testing.T) {
14151415
tests := []struct {
1416-
name string
1417-
input string
1418-
wantValid bool
1416+
name string
1417+
input string
1418+
expected bool
14191419
}{
14201420
{
1421-
name: "Test 1: Valid label - simple",
1422-
input: "label123",
1423-
wantValid: true,
1421+
name: "Test 1: Valid label - simple",
1422+
input: "label123",
1423+
expected: true,
14241424
},
14251425
{
1426-
name: "Test 2: Valid label - with dash and underscore",
1427-
input: "label-123_abc",
1428-
wantValid: true,
1426+
name: "Test 2: Valid label - with dash and underscore",
1427+
input: "label-123_abc",
1428+
expected: true,
14291429
},
14301430
{
1431-
name: "Test 3: Invalid label - too long",
1432-
input: strings.Repeat("a", 257),
1433-
wantValid: false,
1431+
name: "Test 3: Invalid label - too long",
1432+
input: strings.Repeat("a", 257),
1433+
expected: false,
14341434
},
14351435
{
1436-
name: "Test 4: Invalid label - special char",
1437-
input: "label$",
1438-
wantValid: false,
1436+
name: "Test 4: Invalid label - special char",
1437+
input: "label$",
1438+
expected: false,
14391439
},
14401440
{
1441-
name: "Test 5: Invalid label - starts with dash",
1442-
input: "-label",
1443-
wantValid: false,
1441+
name: "Test 5: Invalid label - starts with dash",
1442+
input: "-label",
1443+
expected: false,
14441444
},
14451445
{
1446-
name: "Test 6: Invalid label - ends with dash",
1447-
input: "label-",
1448-
wantValid: false,
1446+
name: "Test 6: Invalid label - ends with dash",
1447+
input: "label-",
1448+
expected: false,
14491449
},
14501450
{
1451-
name: "Test 7: Invalid label - empty",
1452-
input: "",
1453-
wantValid: false,
1451+
name: "Test 7: Invalid label - empty",
1452+
input: "",
1453+
expected: false,
1454+
},
1455+
{
1456+
name: "Test 8: Invalid label - contains spaces",
1457+
input: "label 123",
1458+
expected: false,
14541459
},
14551460
}
14561461

14571462
for _, tt := range tests {
14581463
t.Run(tt.name, func(t *testing.T) {
1459-
got := validateLabel(tt.input)
1460-
assert.Equal(t, tt.wantValid, got)
1464+
actual := validateLabel(tt.input)
1465+
assert.Equal(t, tt.expected, actual)
14611466
})
14621467
}
14631468
}

0 commit comments

Comments
 (0)