From 9189d3a6cb05ca3e3e586d9d9a7ce5442fa9cc39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Tich=C3=A1k?= Date: Fri, 7 Aug 2026 13:57:03 +0200 Subject: [PATCH] [control-operator] labels and podname tests --- .../controller/task_controller_test.go | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 control-operator/internal/controller/task_controller_test.go diff --git a/control-operator/internal/controller/task_controller_test.go b/control-operator/internal/controller/task_controller_test.go new file mode 100644 index 00000000..94721c17 --- /dev/null +++ b/control-operator/internal/controller/task_controller_test.go @@ -0,0 +1,76 @@ +/* + * === This file is part of ALICE O² === + * + * Copyright 2026 CERN and copyright holders of ALICE O². + * Author: Michal Tichak + * + * 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 . + * + * 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) + } + } +}