|
| 1 | +package controllers |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/onsi/gomega" |
| 5 | + arbv1 "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/controller/v1beta1" |
| 6 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 7 | + "testing" |
| 8 | +) |
| 9 | + |
| 10 | +func TestDiscoverInstanceTypes(t *testing.T) { |
| 11 | + g := gomega.NewGomegaWithT(t) |
| 12 | + |
| 13 | + tests := []struct { |
| 14 | + name string |
| 15 | + input *arbv1.AppWrapper |
| 16 | + expected map[string]int |
| 17 | + expectedErr error |
| 18 | + }{ |
| 19 | + { |
| 20 | + name: "Test with multiple orderedinstance", |
| 21 | + input: &arbv1.AppWrapper{ |
| 22 | + ObjectMeta: metav1.ObjectMeta{ |
| 23 | + Labels: map[string]string{ |
| 24 | + "orderedinstance": "test.instance1_test.instance2", |
| 25 | + }, |
| 26 | + }, |
| 27 | + Spec: arbv1.AppWrapperSpec{ |
| 28 | + AggrResources: arbv1.AppWrapperResourceList{ |
| 29 | + GenericItems: []arbv1.AppWrapperGenericResource{ |
| 30 | + { |
| 31 | + CustomPodResources: []arbv1.CustomPodResourceTemplate{ |
| 32 | + { |
| 33 | + Replicas: 1, |
| 34 | + }, |
| 35 | + { |
| 36 | + Replicas: 2, |
| 37 | + }, |
| 38 | + }, |
| 39 | + TypeMeta: metav1.TypeMeta{}, |
| 40 | + }, |
| 41 | + }, |
| 42 | + }, |
| 43 | + }, |
| 44 | + }, |
| 45 | + expected: map[string]int{ |
| 46 | + "test.instance1": 1, |
| 47 | + "test.instance2": 2, |
| 48 | + }, |
| 49 | + }, |
| 50 | + { |
| 51 | + name: "Test with one orderedinstance", |
| 52 | + input: &arbv1.AppWrapper{ |
| 53 | + ObjectMeta: metav1.ObjectMeta{ |
| 54 | + Labels: map[string]string{ |
| 55 | + "orderedinstance": "test.instance1", |
| 56 | + }, |
| 57 | + }, |
| 58 | + Spec: arbv1.AppWrapperSpec{ |
| 59 | + AggrResources: arbv1.AppWrapperResourceList{ |
| 60 | + GenericItems: []arbv1.AppWrapperGenericResource{ |
| 61 | + { |
| 62 | + CustomPodResources: []arbv1.CustomPodResourceTemplate{ |
| 63 | + { |
| 64 | + Replicas: 1, |
| 65 | + }, |
| 66 | + }, |
| 67 | + TypeMeta: metav1.TypeMeta{}, |
| 68 | + }, |
| 69 | + }, |
| 70 | + }, |
| 71 | + }, |
| 72 | + }, |
| 73 | + expected: map[string]int{ |
| 74 | + "test.instance1": 1, |
| 75 | + }, |
| 76 | + }, |
| 77 | + { |
| 78 | + name: "Test with empty orderedinstance", |
| 79 | + input: &arbv1.AppWrapper{ |
| 80 | + ObjectMeta: metav1.ObjectMeta{ |
| 81 | + Labels: map[string]string{ |
| 82 | + "orderedinstance": "", |
| 83 | + }, |
| 84 | + }, |
| 85 | + }, |
| 86 | + expected: map[string]int{}, |
| 87 | + }, |
| 88 | + { |
| 89 | + name: "Test with empty orderedinstance", |
| 90 | + input: &arbv1.AppWrapper{ |
| 91 | + ObjectMeta: metav1.ObjectMeta{ |
| 92 | + Labels: map[string]string{ |
| 93 | + // zero instances |
| 94 | + }, |
| 95 | + }, |
| 96 | + }, |
| 97 | + expected: map[string]int{}, |
| 98 | + }, |
| 99 | + } |
| 100 | + |
| 101 | + for _, test := range tests { |
| 102 | + t.Run(test.name, func(t *testing.T) { |
| 103 | + result := discoverInstanceTypes(test.input) |
| 104 | + g.Expect(result).To(gomega.Equal(test.expected)) |
| 105 | + }) |
| 106 | + } |
| 107 | +} |
0 commit comments