(t *testing.T)
| 29 | ) |
| 30 | |
| 31 | func TestGetOwnerRefs(t *testing.T) { |
| 32 | testCases := []struct { |
| 33 | description string |
| 34 | podName string |
| 35 | namespace string |
| 36 | pod *corev1.Pod |
| 37 | expectedOwnerRef int |
| 38 | expectError bool |
| 39 | }{ |
| 40 | { |
| 41 | description: "empty pod name returns nil", |
| 42 | podName: "", |
| 43 | namespace: "default", |
| 44 | expectedOwnerRef: 0, |
| 45 | expectError: false, |
| 46 | }, |
| 47 | { |
| 48 | description: "pod owned by DaemonSet returns two owner refs", |
| 49 | podName: "gfd-pod", |
| 50 | namespace: "gpu-operator", |
| 51 | pod: &corev1.Pod{ |
| 52 | ObjectMeta: metav1.ObjectMeta{ |
| 53 | Name: "gfd-pod", |
| 54 | Namespace: "gpu-operator", |
| 55 | UID: types.UID("pod-uid-123"), |
| 56 | OwnerReferences: []metav1.OwnerReference{ |
| 57 | { |
| 58 | APIVersion: "apps/v1", |
| 59 | Kind: "DaemonSet", |
| 60 | Name: "nvidia-gfd", |
| 61 | UID: types.UID("ds-uid-456"), |
| 62 | }, |
| 63 | }, |
| 64 | }, |
| 65 | }, |
| 66 | expectedOwnerRef: 2, |
| 67 | expectError: false, |
| 68 | }, |
| 69 | { |
| 70 | description: "pod not owned by anything returns nil", |
| 71 | podName: "standalone-pod", |
| 72 | namespace: "default", |
| 73 | pod: &corev1.Pod{ |
| 74 | ObjectMeta: metav1.ObjectMeta{ |
| 75 | Name: "standalone-pod", |
| 76 | Namespace: "default", |
| 77 | UID: types.UID("pod-uid-789"), |
| 78 | }, |
| 79 | }, |
| 80 | expectedOwnerRef: 0, |
| 81 | expectError: false, |
| 82 | }, |
| 83 | { |
| 84 | description: "pod owned by ReplicaSet returns nil", |
| 85 | podName: "rs-pod", |
| 86 | namespace: "default", |
| 87 | pod: &corev1.Pod{ |
| 88 | ObjectMeta: metav1.ObjectMeta{ |
nothing calls this directly
no test coverage detected