Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions control-operator/internal/controller/task_controller_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* === This file is part of ALICE O² ===
*
* Copyright 2026 CERN and copyright holders of ALICE O².
* Author: Michal Tichak <michal.tichak@cern.ch>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In applying this license CERN does not waive the privileges and
* immunities granted to it by virtue of its status as an
* Intergovernmental Organization or submit itself to any jurisdiction.
*/

package controller

import (
"testing"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

aliecsv1alpha1 "github.com/AliceO2Group/Control/control-operator/api/v1alpha1"
)

func TestPodNameFromTask(t *testing.T) {
tests := []struct {
name string
taskName string
want string
}{
{name: "simple task name", taskName: "my-task", want: "aliecs-task-pod-my-task"},
{name: "empty task name", taskName: "", want: "aliecs-task-pod-"},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := podNameFromTask(tt.taskName); got != tt.want {
t.Errorf("podNameFromTask(%q) = %q, want %q", tt.taskName, got, tt.want)
}
})
}
}

func TestLabelsForTask(t *testing.T) {
task := &aliecsv1alpha1.Task{
ObjectMeta: metav1.ObjectMeta{
Name: "my-task",
},
}

want := map[string]string{
"task_name": "my-task",
"application": "ControlOperator",
}

got := labelsForTask(task)

if len(got) != len(want) {
t.Fatalf("labelsForTask() = %v, want %v", got, want)
}
for k, v := range want {
if got[k] != v {
t.Errorf("labelsForTask()[%q] = %q, want %q", k, got[k], v)
}
}
}
Loading