(t *testing.T)
| 34 | } |
| 35 | |
| 36 | func TestGetReferenceRefVersion(t *testing.T) { |
| 37 | tests := []struct { |
| 38 | name string |
| 39 | input *TestRuntimeObj |
| 40 | expectedRefVersion string |
| 41 | }{ |
| 42 | { |
| 43 | name: "api from selflink", |
| 44 | input: &TestRuntimeObj{ |
| 45 | ObjectMeta: metav1.ObjectMeta{SelfLink: "/api/v1/namespaces"}, |
| 46 | }, |
| 47 | expectedRefVersion: "v1", |
| 48 | }, |
| 49 | { |
| 50 | name: "foo.group/v3 from selflink", |
| 51 | input: &TestRuntimeObj{ |
| 52 | ObjectMeta: metav1.ObjectMeta{SelfLink: "/apis/foo.group/v3/namespaces"}, |
| 53 | }, |
| 54 | expectedRefVersion: "foo.group/v3", |
| 55 | }, |
| 56 | } |
| 57 | |
| 58 | scheme := runtime.NewScheme() |
| 59 | scheme.AddKnownTypes(schema.GroupVersion{Group: "this", Version: "is ignored"}, &TestRuntimeObj{}) |
| 60 | |
| 61 | for _, test := range tests { |
| 62 | t.Run(test.name, func(t *testing.T) { |
| 63 | ref, err := GetReference(scheme, test.input) |
| 64 | if err != nil { |
| 65 | t.Fatal(err) |
| 66 | } |
| 67 | if test.expectedRefVersion != ref.APIVersion { |
| 68 | t.Errorf("expected %q, got %q", test.expectedRefVersion, ref.APIVersion) |
| 69 | } |
| 70 | }) |
| 71 | } |
| 72 | } |
nothing calls this directly
no test coverage detected