sigs.k8s.io/kueue@v0.6.2/pkg/controller/jobs/mpijob/mpijob_webhook_test.go (about) 1 /* 2 Copyright 2023 The Kubernetes 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 mpijob 18 19 import ( 20 "context" 21 "testing" 22 23 "github.com/google/go-cmp/cmp" 24 kubeflow "github.com/kubeflow/mpi-operator/pkg/apis/kubeflow/v2beta1" 25 26 testingutil "sigs.k8s.io/kueue/pkg/util/testingjobs/mpijob" 27 ) 28 29 func TestDefault(t *testing.T) { 30 testcases := map[string]struct { 31 job *kubeflow.MPIJob 32 manageJobsWithoutQueueName bool 33 want *kubeflow.MPIJob 34 }{ 35 "update the suspend field with 'manageJobsWithoutQueueName=false'": { 36 job: testingutil.MakeMPIJob("job", "default").Queue("queue").Suspend(false).Obj(), 37 want: testingutil.MakeMPIJob("job", "default").Queue("queue").Obj(), 38 }, 39 "update the suspend field 'manageJobsWithoutQueueName=true'": { 40 job: testingutil.MakeMPIJob("job", "default").Suspend(false).Obj(), 41 manageJobsWithoutQueueName: true, 42 want: testingutil.MakeMPIJob("job", "default").Obj(), 43 }, 44 } 45 for name, tc := range testcases { 46 t.Run(name, func(t *testing.T) { 47 w := &MPIJobWebhook{manageJobsWithoutQueueName: tc.manageJobsWithoutQueueName} 48 if err := w.Default(context.Background(), tc.job); err != nil { 49 t.Errorf("set defaults to a kubeflow/mpijob by a Defaulter") 50 } 51 if diff := cmp.Diff(tc.want, tc.job); len(diff) != 0 { 52 t.Errorf("Default() mismatch (-want,+got):\n%s", diff) 53 } 54 }) 55 } 56 }