(t *testing.T)
| 423 | } |
| 424 | |
| 425 | func TestValidateLabels(t *testing.T) { |
| 426 | tests := []struct { |
| 427 | name string |
| 428 | labels map[string]string |
| 429 | wantErr bool |
| 430 | errMsg string |
| 431 | }{ |
| 432 | { |
| 433 | name: "Valid labels", |
| 434 | labels: map[string]string{"environment": "production", "team": "backend"}, |
| 435 | wantErr: false, |
| 436 | }, |
| 437 | { |
| 438 | name: "Empty labels", |
| 439 | labels: map[string]string{}, |
| 440 | wantErr: false, |
| 441 | }, |
| 442 | { |
| 443 | name: "Valid key with empty value", |
| 444 | labels: map[string]string{"environment": ""}, |
| 445 | wantErr: false, |
| 446 | }, |
| 447 | { |
| 448 | name: "Key starting with number", |
| 449 | labels: map[string]string{"1environment": "production"}, |
| 450 | wantErr: true, |
| 451 | errMsg: "invalid label key", |
| 452 | }, |
| 453 | { |
| 454 | name: "Key with uppercase", |
| 455 | labels: map[string]string{"Environment": "production"}, |
| 456 | wantErr: true, |
| 457 | errMsg: "invalid label key", |
| 458 | }, |
| 459 | { |
| 460 | name: "Key with special characters", |
| 461 | labels: map[string]string{"env@prod": "production"}, |
| 462 | wantErr: true, |
| 463 | errMsg: "invalid label key", |
| 464 | }, |
| 465 | { |
| 466 | name: "Value with special characters", |
| 467 | labels: map[string]string{"environment": "prod@123"}, |
| 468 | wantErr: true, |
| 469 | errMsg: "invalid label value", |
| 470 | }, |
| 471 | { |
| 472 | name: "Key too long", |
| 473 | labels: map[string]string{strings.Repeat("a", 64): "value"}, |
| 474 | wantErr: true, |
| 475 | errMsg: "invalid label key", |
| 476 | }, |
| 477 | { |
| 478 | name: "Value too long", |
| 479 | labels: map[string]string{"key": strings.Repeat("a", 64)}, |
| 480 | wantErr: true, |
| 481 | errMsg: "invalid label value", |
| 482 | }, |
nothing calls this directly
no test coverage detected