forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pod_name_v1_test.go
40 lines (28 loc) · 1.23 KB
/
pod_name_v1_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package util
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestPodNameV1(t *testing.T) {
nodeName := "nodename"
nodeID := "1"
// short case
shortWfName := "wfname"
shortTemplateName := "templatename"
expected := fmt.Sprintf("%s-%s", shortWfName, shortTemplateName)
actual := ensurePodNamePrefixLength(expected)
assert.Equal(t, expected, actual)
name := GeneratePodName(shortWfName, nodeName, shortTemplateName, nodeID, PodNameV1)
assert.Equal(t, nodeID, name)
// long case
longWfName := "alongworkflownamethatincludeslotsofdetailsandisessentiallyalargerunonsentencewithpoorstyleandnopunctuationtobehadwhatsoever"
longTemplateName := "alongtemplatenamethatincludessliightlymoredetailsandiscertainlyalargerunonstnencewithevenworsestylisticconcernsandpreposterouslyeliminatespunctuation"
sum := len(longWfName) + len(longTemplateName)
assert.Greater(t, sum, maxK8sResourceNameLength-k8sNamingHashLength)
expected = fmt.Sprintf("%s-%s", longWfName, longTemplateName)
actual = ensurePodNamePrefixLength(expected)
assert.Equal(t, maxK8sResourceNameLength-k8sNamingHashLength-1, len(actual))
name = GeneratePodName(longWfName, nodeName, longTemplateName, nodeID, PodNameV1)
assert.Equal(t, nodeID, name)
}