volcano.sh/volcano@v1.9.0/pkg/controllers/jobflow/jobflow_controller_util_test.go (about) 1 /* 2 Copyright 2022 The Volcano Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package jobflow 18 19 import ( 20 "testing" 21 22 v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 23 24 batch "volcano.sh/apis/pkg/apis/batch/v1alpha1" 25 ) 26 27 func TestGetJobNameFunc(t *testing.T) { 28 type args struct { 29 jobFlowName string 30 jobTemplateName string 31 } 32 tests := []struct { 33 name string 34 args args 35 want string 36 }{ 37 { 38 name: "GetJobName success case", 39 args: args{ 40 jobFlowName: "jobFlowA", 41 jobTemplateName: "jobTemplateA", 42 }, 43 want: "jobFlowA-jobTemplateA", 44 }, 45 } 46 for _, tt := range tests { 47 t.Run(tt.name, func(t *testing.T) { 48 if got := getJobName(tt.args.jobFlowName, tt.args.jobTemplateName); got != tt.want { 49 t.Errorf("getJobName() = %v, want %v", got, tt.want) 50 } 51 }) 52 } 53 } 54 55 func TestGetConnectionOfJobAndJobTemplate(t *testing.T) { 56 type args struct { 57 namespace string 58 name string 59 } 60 tests := []struct { 61 name string 62 args args 63 want string 64 }{ 65 { 66 name: "TestGetConnectionOfJobAndJobTemplate", 67 args: args{ 68 namespace: "default", 69 name: "flow", 70 }, 71 want: "default.flow", 72 }, 73 } 74 for _, tt := range tests { 75 t.Run(tt.name, func(t *testing.T) { 76 if got := GetTemplateString(tt.args.namespace, tt.args.name); got != tt.want { 77 t.Errorf("GetTemplateString() = %v, want %v", got, tt.want) 78 } 79 }) 80 } 81 } 82 83 func TestGetJobFlowNameByJob(t *testing.T) { 84 type args struct { 85 job *batch.Job 86 } 87 tests := []struct { 88 name string 89 args args 90 want string 91 }{ 92 { 93 name: "TestGetConnectionOfJobAndJobTemplate", 94 args: args{ 95 job: &batch.Job{ 96 TypeMeta: v1.TypeMeta{}, 97 ObjectMeta: v1.ObjectMeta{ 98 OwnerReferences: []v1.OwnerReference{ 99 { 100 APIVersion: "flow.volcano.sh/v1alpha1", 101 Kind: JobFlow, 102 Name: "jobflowtest", 103 UID: "", 104 Controller: nil, 105 BlockOwnerDeletion: nil, 106 }, 107 }, 108 }, 109 Spec: batch.JobSpec{}, 110 Status: batch.JobStatus{}, 111 }, 112 }, 113 want: "jobflowtest", 114 }, 115 } 116 for _, tt := range tests { 117 t.Run(tt.name, func(t *testing.T) { 118 if got := getJobFlowNameByJob(tt.args.job); got != tt.want { 119 t.Errorf("getJobFlowNameByJob() = %v, want %v", got, tt.want) 120 } 121 }) 122 } 123 }