github.com/kubeflow/training-operator@v1.7.0/pkg/controller.v1/tensorflow/util_test.go (about) 1 // Copyright 2021 The Kubeflow Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package tensorflow 16 17 import ( 18 "testing" 19 20 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 "k8s.io/apimachinery/pkg/util/uuid" 22 23 kubeflowv1 "github.com/kubeflow/training-operator/pkg/apis/kubeflow.org/v1" 24 tftestutil "github.com/kubeflow/training-operator/pkg/controller.v1/tensorflow/testutil" 25 ) 26 27 func TestGenOwnerReference(t *testing.T) { 28 testUID := uuid.NewUUID() 29 tfJob := &kubeflowv1.TFJob{ 30 ObjectMeta: metav1.ObjectMeta{ 31 Name: tftestutil.TestTFJobName, 32 UID: testUID, 33 }, 34 } 35 36 ref := reconciler.GenOwnerReference(tfJob) 37 if ref.UID != testUID { 38 t.Errorf("Expected UID %s, got %s", testUID, ref.UID) 39 } 40 if ref.Name != tftestutil.TestTFJobName { 41 t.Errorf("Expected Name %s, got %s", tftestutil.TestTFJobName, ref.Name) 42 } 43 if ref.APIVersion != kubeflowv1.SchemeGroupVersion.String() { 44 t.Errorf("Expected APIVersion %s, got %s", kubeflowv1.SchemeGroupVersion.String(), ref.APIVersion) 45 } 46 } 47 48 func TestGenLabels(t *testing.T) { 49 testJobName := "test/key" 50 expctedVal := "test-key" 51 52 labels := reconciler.GenLabels(testJobName) 53 jobNameLabel := kubeflowv1.JobNameLabel 54 55 if labels[jobNameLabel] != expctedVal { 56 t.Errorf("Expected %s %s, got %s", jobNameLabel, expctedVal, jobNameLabel) 57 } 58 59 if labels[kubeflowv1.OperatorNameLabel] != controllerName { 60 t.Errorf("Expected %s %s, got %s", kubeflowv1.OperatorNameLabel, controllerName, 61 labels[kubeflowv1.OperatorNameLabel]) 62 } 63 }