github.com/kubeflow/training-operator@v1.7.0/pkg/controller.v1/tensorflow/tensorflow_test.go (about) 1 // Copyright 2020 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 controller provides a Kubernetes controller for a TFJob resource. 16 package tensorflow 17 18 import ( 19 "reflect" 20 "testing" 21 ) 22 23 func TestConvertClusterSpecToSparseClusterSpec(t *testing.T) { 24 clusterSpec := ClusterSpec{ 25 "ps": {"test-tfjob-ps-0.default.svc:2222", "test-tfjob-ps-1.default.svc:2222"}, 26 "worker": {"test-tfjob-worker-0.default.svc:2222", "test-tfjob-worker-1.default.svc:2222"}, 27 } 28 workerSparseClusterSpec := convertClusterSpecToSparseClusterSpec(clusterSpec, "worker", 0) 29 psSparseClusterSpec := convertClusterSpecToSparseClusterSpec(clusterSpec, "ps", 0) 30 31 expectedWorkerSparseClusterSpec := SparseClusterSpec{ 32 Worker: map[int32]string{0: "test-tfjob-worker-0.default.svc:2222"}, 33 PS: []string{"test-tfjob-ps-0.default.svc:2222", "test-tfjob-ps-1.default.svc:2222"}, 34 } 35 expectedPSSparseClusterSpec := SparseClusterSpec{ 36 Worker: map[int32]string{}, 37 PS: []string{"test-tfjob-ps-0.default.svc:2222"}, 38 } 39 if !reflect.DeepEqual(workerSparseClusterSpec, expectedWorkerSparseClusterSpec) { 40 t.Error("sparseClusterSpec for worker is not correct!") 41 } 42 if !reflect.DeepEqual(psSparseClusterSpec, expectedPSSparseClusterSpec) { 43 t.Error("sparseClusterSpec for worker is not correct!") 44 } 45 }