From 577143e25a56aa69132d428a9ed444c07b0c22a4 Mon Sep 17 00:00:00 2001 From: Ce Gao Date: Fri, 23 Jul 2021 19:23:07 +0800 Subject: [PATCH] fix: Add uppercase support for GenGeneralName (#146) Signed-off-by: cegao --- .gitignore | 1 + pkg/controller.v1/common/util.go | 2 +- pkg/controller.v1/common/util_test.go | 38 ++++++++++++++++++++------- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index d62b238b..8ca8ae72 100644 --- a/.gitignore +++ b/.gitignore @@ -62,3 +62,4 @@ Icon Network Trash Folder Temporary Items .apdisk +vendor/ diff --git a/pkg/controller.v1/common/util.go b/pkg/controller.v1/common/util.go index fd758194..f1800210 100644 --- a/pkg/controller.v1/common/util.go +++ b/pkg/controller.v1/common/util.go @@ -45,7 +45,7 @@ func (p ReplicasPriority) Swap(i, j int) { } func GenGeneralName(jobName string, rtype apiv1.ReplicaType, index string) string { - n := jobName + "-" + string(rtype) + "-" + index + n := jobName + "-" + strings.ToLower(string(rtype)) + "-" + index return strings.Replace(n, "/", "-", -1) } diff --git a/pkg/controller.v1/common/util_test.go b/pkg/controller.v1/common/util_test.go index b43779a0..3b87373d 100644 --- a/pkg/controller.v1/common/util_test.go +++ b/pkg/controller.v1/common/util_test.go @@ -15,21 +15,39 @@ package common import ( - "fmt" - apiv1 "github.com/kubeflow/common/pkg/apis/common/v1" - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" + + apiv1 "github.com/kubeflow/common/pkg/apis/common/v1" ) func TestGenGeneralName(t *testing.T) { - var testRType apiv1.ReplicaType = "worker" - testIndex := "1" - testKey := "1/2/3/4/5" - expectedName := fmt.Sprintf("1-2-3-4-5-%s-%s", testRType, testIndex) + tcs := []struct { + index string + key string + replicaType apiv1.ReplicaType + expectedName string + }{ + { + index: "1", + key: "1/2/3/4/5", + replicaType: "worker", + expectedName: "1-2-3-4-5-worker-1", + }, + { + index: "1", + key: "1/2/3/4/5", + replicaType: "WORKER", + expectedName: "1-2-3-4-5-worker-1", + }, + } - name := GenGeneralName(testKey, testRType, testIndex) - if name != expectedName { - t.Errorf("Expected name %s, got %s", expectedName, name) + for _, tc := range tcs { + actual := GenGeneralName(tc.key, tc.replicaType, tc.index) + if actual != tc.expectedName { + t.Errorf("Expected name %s, got %s", tc.expectedName, actual) + } } }