GitOps for k8s
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

resourceid_test.go 929B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package flux
  2. import (
  3. "testing"
  4. )
  5. func TestResourceIDParsing(t *testing.T) {
  6. type test struct {
  7. name, id string
  8. }
  9. valid := []test{
  10. {"full", "namespace:kind/name"},
  11. {"legacy", "namespace/service"},
  12. {"dots", "namespace:kind/name.with.dots"},
  13. {"colons", "namespace:kind/name:with:colons"},
  14. {"punctuation in general", "name-space:ki_nd/punc_tu:a.tion-rules"},
  15. {"cluster-scope resource", "<cluster>:namespace/foo"},
  16. }
  17. invalid := []test{
  18. {"unqualified", "justname"},
  19. {"dots in namespace", "name.space:kind/name"},
  20. {"too many colons", "namespace:kind:name"},
  21. }
  22. for _, tc := range valid {
  23. t.Run(tc.name, func(t *testing.T) {
  24. if _, err := ParseResourceID(tc.id); err != nil {
  25. t.Error(err)
  26. }
  27. })
  28. }
  29. for _, tc := range invalid {
  30. t.Run(tc.name, func(t *testing.T) {
  31. if _, err := ParseResourceID(tc.id); err == nil {
  32. t.Errorf("expected %q to be considered invalid", tc.id)
  33. }
  34. })
  35. }
  36. }