blob: 0e8b79943cd1a765be035a91a29965844676b466 [file] [log] [blame]
Serge Bazanski1f789542024-05-22 14:01:50 +02001package node
2
3import (
4 "errors"
5 "testing"
6)
7
8func 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}