Skip to content

Commit 30cc777

Browse files
committed
[control-operator] labels and podname tests
1 parent 55f507e commit 30cc777

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

control-operator/internal/controller/task_controller_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,45 @@ func TestPodForTask(t *testing.T) {
109109
if owner.Controller == nil || !*owner.Controller {
110110
t.Errorf("owner.Controller = %v, want true", owner.Controller)
111111
}
112+
func TestPodNameFromTask(t *testing.T) {
113+
tests := []struct {
114+
name string
115+
taskName string
116+
want string
117+
}{
118+
{name: "simple task name", taskName: "my-task", want: "aliecs-task-pod-my-task"},
119+
{name: "empty task name", taskName: "", want: "aliecs-task-pod-"},
120+
}
121+
122+
for _, tt := range tests {
123+
t.Run(tt.name, func(t *testing.T) {
124+
if got := podNameFromTask(tt.taskName); got != tt.want {
125+
t.Errorf("podNameFromTask(%q) = %q, want %q", tt.taskName, got, tt.want)
126+
}
127+
})
128+
}
129+
}
130+
131+
func TestLabelsForTask(t *testing.T) {
132+
task := &aliecsv1alpha1.Task{
133+
ObjectMeta: metav1.ObjectMeta{
134+
Name: "my-task",
135+
},
136+
}
137+
138+
want := map[string]string{
139+
"task_name": "my-task",
140+
"application": "ControlOperator",
141+
}
142+
143+
got := labelsForTask(task)
144+
145+
if len(got) != len(want) {
146+
t.Fatalf("labelsForTask() = %v, want %v", got, want)
147+
}
148+
for k, v := range want {
149+
if got[k] != v {
150+
t.Errorf("labelsForTask()[%q] = %q, want %q", k, got[k], v)
151+
}
152+
}
112153
}

0 commit comments

Comments
 (0)