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