-
Notifications
You must be signed in to change notification settings - Fork 3
/
main_test.go
134 lines (128 loc) · 2.68 KB
/
main_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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package main
import (
"testing"
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestNodeCondition(t *testing.T) {
testTable := map[string]struct {
Node *corev1.Node
Expected string
}{
"Basic Case": {
Node: &corev1.Node{
Status: corev1.NodeStatus{
Conditions: []corev1.NodeCondition{
{
Type: corev1.NodeConditionType("Ready"),
Status: corev1.ConditionTrue,
},
},
},
},
Expected: "Ready",
},
}
for name, tc := range testTable {
t.Run(name, func(t *testing.T) {
actual := nodeCondition(*tc.Node)
assert.Equal(t, tc.Expected, actual, "failed")
})
}
}
func TestNodepoolLabels(t *testing.T) {
testTable := map[string]struct {
Node *corev1.Node
CustomLabel string
Expected string
}{
"no matching label": {
Node: &corev1.Node{
ObjectMeta: v1.ObjectMeta{
Labels: map[string]string{
"custom-label": "custom label",
},
},
},
Expected: "-",
},
"custom label": {
Node: &corev1.Node{
ObjectMeta: v1.ObjectMeta{
Labels: map[string]string{
"custom-label": "custom label",
},
},
},
CustomLabel: "custom-label",
Expected: "custom label",
},
"AWS": {
Node: &corev1.Node{
ObjectMeta: v1.ObjectMeta{
Labels: map[string]string{
"eks.amazonaws.com/nodegroup": "test AWS",
},
},
},
Expected: "test AWS",
},
"GCP": {
Node: &corev1.Node{
ObjectMeta: v1.ObjectMeta{
Labels: map[string]string{
"cloud.google.com/gke-nodepool": "test GCP",
},
},
},
Expected: "test GCP",
},
"AKS": {
Node: &corev1.Node{
ObjectMeta: v1.ObjectMeta{
Labels: map[string]string{
"kubernetes.azure.com/agentpool": "test AKS",
},
},
},
Expected: "test AKS",
},
"DigitalOcean": {
Node: &corev1.Node{
ObjectMeta: v1.ObjectMeta{
Labels: map[string]string{
"doks.digitalocean.com/node-pool-id": "test DigitalOcean",
},
},
},
Expected: "test DigitalOcean",
},
"v1alpha5 API": {
Node: &corev1.Node{
ObjectMeta: v1.ObjectMeta{
Labels: map[string]string{
"karpenter.sh/provisioner-name": "test v1alpha5",
},
},
},
Expected: "(Karpenter) test v1alpha5",
},
"v1beta1 API": {
Node: &corev1.Node{
ObjectMeta: v1.ObjectMeta{
Labels: map[string]string{
"karpenter.sh/nodepool": "test v1beta1",
},
},
},
Expected: "(Karpenter) test v1beta1",
},
}
for name, tc := range testTable {
t.Run(name, func(t *testing.T) {
actual := findNodepool(*tc.Node, tc.CustomLabel)
assert.Equal(t, tc.Expected, actual, "failed")
})
}
}