github.com/kubeflow/training-operator@v1.7.0/pkg/apis/kubeflow.org/v1/mpi_validation_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 v1 16 17 import ( 18 "testing" 19 20 corev1 "k8s.io/api/core/v1" 21 "k8s.io/utils/pointer" 22 ) 23 24 func TestValidateV1MpiJobSpec(t *testing.T) { 25 testCases := []MPIJobSpec{ 26 { 27 MPIReplicaSpecs: nil, 28 }, 29 { 30 MPIReplicaSpecs: map[ReplicaType]*ReplicaSpec{ 31 MPIJobReplicaTypeLauncher: &ReplicaSpec{ 32 Template: corev1.PodTemplateSpec{ 33 Spec: corev1.PodSpec{ 34 Containers: []corev1.Container{}, 35 }, 36 }, 37 }, 38 }, 39 }, 40 { 41 MPIReplicaSpecs: map[ReplicaType]*ReplicaSpec{ 42 MPIJobReplicaTypeLauncher: &ReplicaSpec{ 43 Template: corev1.PodTemplateSpec{ 44 Spec: corev1.PodSpec{ 45 Containers: []corev1.Container{ 46 corev1.Container{ 47 Image: "", 48 }, 49 }, 50 }, 51 }, 52 }, 53 }, 54 }, 55 { 56 MPIReplicaSpecs: map[ReplicaType]*ReplicaSpec{ 57 MPIJobReplicaTypeLauncher: &ReplicaSpec{ 58 Template: corev1.PodTemplateSpec{ 59 Spec: corev1.PodSpec{ 60 Containers: []corev1.Container{ 61 corev1.Container{ 62 Name: "", 63 Image: "kubeflow/tf-dist-mnist-test:1.0", 64 }, 65 }, 66 }, 67 }, 68 }, 69 }, 70 }, 71 { 72 MPIReplicaSpecs: map[ReplicaType]*ReplicaSpec{ 73 MPIJobReplicaTypeLauncher: &ReplicaSpec{ 74 Replicas: pointer.Int32(2), 75 Template: corev1.PodTemplateSpec{ 76 Spec: corev1.PodSpec{ 77 Containers: []corev1.Container{ 78 corev1.Container{ 79 Name: "tensorflow", 80 Image: "kubeflow/tf-dist-mnist-test:1.0", 81 }, 82 }, 83 }, 84 }, 85 }, 86 }, 87 }, 88 } 89 for _, c := range testCases { 90 err := ValidateV1MpiJobSpec(&c) 91 if err == nil { 92 t.Error("Failed validate the kubeflowv1.MpiJobSpec") 93 } 94 } 95 }