File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed
Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -1410,3 +1410,54 @@ func createDefaultCollectorConfig() *Collector {
14101410 },
14111411 }
14121412}
1413+
1414+ func TestValidateLabel (t * testing.T ) {
1415+ tests := []struct {
1416+ name string
1417+ input string
1418+ wantValid bool
1419+ }{
1420+ {
1421+ name : "Test 1: Valid label - simple" ,
1422+ input : "label123" ,
1423+ wantValid : true ,
1424+ },
1425+ {
1426+ name : "Test 2: Valid label - with dash and underscore" ,
1427+ input : "label-123_abc" ,
1428+ wantValid : true ,
1429+ },
1430+ {
1431+ name : "Test 3: Invalid label - too long" ,
1432+ input : strings .Repeat ("a" , 257 ),
1433+ wantValid : false ,
1434+ },
1435+ {
1436+ name : "Test 4: Invalid label - special char" ,
1437+ input : "label$" ,
1438+ wantValid : false ,
1439+ },
1440+ {
1441+ name : "Test 5: Invalid label - starts with dash" ,
1442+ input : "-label" ,
1443+ wantValid : false ,
1444+ },
1445+ {
1446+ name : "Test 6: Invalid label - ends with dash" ,
1447+ input : "label-" ,
1448+ wantValid : false ,
1449+ },
1450+ {
1451+ name : "Test 7: Invalid label - empty" ,
1452+ input : "" ,
1453+ wantValid : false ,
1454+ },
1455+ }
1456+
1457+ for _ , tt := range tests {
1458+ t .Run (tt .name , func (t * testing.T ) {
1459+ got := validateLabel (tt .input )
1460+ assert .Equal (t , tt .wantValid , got )
1461+ })
1462+ }
1463+ }
You can’t perform that action at this time.
0 commit comments