123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- package kube
- import "testing"
- func Test_newAnnotations(t *testing.T) {
- testCases := []struct {
- prefix string
- expectedBackendType string
- hasError bool
- }{
- {
- prefix: "flannel.alpha.coreos.com",
- expectedBackendType: "flannel.alpha.coreos.com/backend-type",
- },
- {
- prefix: "flannel.alpha.coreos.com/",
- expectedBackendType: "flannel.alpha.coreos.com/backend-type",
- },
- {
- prefix: "flannel.alpha.coreos.com/prefix",
- expectedBackendType: "flannel.alpha.coreos.com/prefix-backend-type",
- },
- {
- prefix: "flannel.alpha.coreos.com/prefix-",
- expectedBackendType: "flannel.alpha.coreos.com/prefix-backend-type",
- },
- {
- prefix: "org.com",
- expectedBackendType: "org.com/backend-type",
- },
- {
- prefix: "org9.com",
- expectedBackendType: "org9.com/backend-type",
- },
- {
- prefix: "org.com/9",
- expectedBackendType: "org.com/9-backend-type",
- },
- {
-
- prefix: "org",
- hasError: true,
- },
- {
-
- prefix: "org/",
- hasError: true,
- },
- {
-
- prefix: "org/prefix",
- hasError: true,
- },
- {
-
- prefix: "org.COM",
- hasError: true,
- },
- {
-
- prefix: "org.com/PREFIX",
- hasError: true,
- },
- }
- for i, tc := range testCases {
- as, err := newAnnotations(tc.prefix)
- if err != nil && !tc.hasError {
- t.Errorf("#%d: error = %s, want nil", i, err)
- continue
- }
- if err == nil && tc.hasError {
- t.Errorf("#%d: error = nil, want non-nil", i)
- continue
- }
- if as.BackendType != tc.expectedBackendType {
- t.Errorf("#%d: BackendType = %s, want %s", i, as.BackendType, tc.expectedBackendType)
- }
- }
- }
|