Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
fix: Add uppercase support for GenGeneralName (#146)
Browse files Browse the repository at this point in the history
Signed-off-by: cegao <[email protected]>
  • Loading branch information
gaocegege authored Jul 23, 2021
1 parent 9ffa565 commit 577143e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ Icon
Network Trash Folder
Temporary Items
.apdisk
vendor/
2 changes: 1 addition & 1 deletion pkg/controller.v1/common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
38 changes: 28 additions & 10 deletions pkg/controller.v1/common/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down

0 comments on commit 577143e

Please sign in to comment.