| Serge Bazanski | 1f78954 | 2024-05-22 14:01:50 +0200 | [diff] [blame] | 1 | package node |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestValidateLabelKeyValue(t *testing.T) { |
| 9 | for i, te := range []struct { |
| 10 | in string |
| 11 | want error |
| 12 | }{ |
| 13 | {"foo", nil}, |
| 14 | {"foo-bar.baz_barfoo", nil}, |
| 15 | {"-", ErrLabelInvalidFirstCharacter}, |
| 16 | {"-invalid", ErrLabelInvalidFirstCharacter}, |
| 17 | {"invalid-", ErrLabelInvalidLastCharacter}, |
| 18 | {"", ErrLabelEmpty}, |
| 19 | {"accordingtoallknownlawsofaviationthereisnowaythatabeeshouldbeabletofly", ErrLabelTooLong}, |
| 20 | {"example.com/annotation", ErrLabelInvalidCharacter}, |
| 21 | } { |
| 22 | if got := ValidateLabel(te.in); !errors.Is(got, te.want) { |
| 23 | t.Errorf("%d: wanted %v, got %v", i, te.want, got) |
| 24 | } |
| 25 | } |
| 26 | } |