-
Notifications
You must be signed in to change notification settings - Fork 655
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add friendly name execution object column
Signed-off-by: wayner0628 <[email protected]>
- Loading branch information
1 parent
96c467e
commit 53d4979
Showing
8 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package transformers | ||
|
||
import ( | ||
"github.com/wolfeidau/humanhash" | ||
"k8s.io/apimachinery/pkg/util/rand" | ||
) | ||
|
||
const RandStringLength = 20 | ||
|
||
/* #nosec */ | ||
func CreateFriendlyName(seed int64) string { | ||
rand.Seed(seed) | ||
hashKey := []byte(rand.String(RandStringLength)) | ||
// Ignoring the error as it's guaranteed hash key longer than result in this context. | ||
result, _ := humanhash.Humanize(hashKey, 4) | ||
return result | ||
} |
29 changes: 29 additions & 0 deletions
29
flyteadmin/pkg/repositories/transformers/friendly_name_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package transformers | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
const AllowedFriendlyNameStr = "abcdefghijklmnopqrstuvwxyz-" | ||
const FriendlyNameLengthLimit = 255 | ||
|
||
var AllowedFriendlyNameChars = []rune(AllowedFriendlyNameStr) | ||
|
||
func TestGetExecutionName(t *testing.T) { | ||
t.Run("friendly name", func(t *testing.T) { | ||
randString := CreateFriendlyName(time.Now().UnixNano()) | ||
assert.LessOrEqual(t, len(randString), FriendlyNameLengthLimit) | ||
for i := 0; i < len(randString); i++ { | ||
assert.Contains(t, AllowedFriendlyNameChars, rune(randString[i])) | ||
} | ||
hyphenCount := strings.Count(randString, "-") | ||
assert.Equal(t, 3, hyphenCount, "FriendlyName should contain exactly three hyphens") | ||
words := strings.Split(randString, "-") | ||
assert.Equal(t, 4, len(words), "FriendlyName should be split into exactly four words") | ||
}) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters