forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pod_name_v2_test.go
53 lines (39 loc) · 1.95 KB
/
pod_name_v2_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
41
42
43
44
45
46
47
48
49
50
51
52
53
package util
import (
"fmt"
"hash/fnv"
"testing"
"github.com/stretchr/testify/assert"
)
func TestPodNameV2(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)
// derive the expected pod name
h := fnv.New32a()
_, _ = h.Write([]byte(nodeName))
expectedPodName := fmt.Sprintf("wfname-templatename-%v", h.Sum32())
name := GeneratePodName(shortWfName, nodeName, shortTemplateName, nodeID, PodNameV2)
assert.Equal(t, expectedPodName, 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))
longPrefix := fmt.Sprintf("%s-%s", longWfName, longTemplateName)
expectedPodName = fmt.Sprintf("%s-%v", longPrefix[0:maxK8sResourceNameLength-k8sNamingHashLength-1], h.Sum32())
name = GeneratePodName(longWfName, nodeName, longTemplateName, nodeID, PodNameV2)
assert.Equal(t, expectedPodName, name)
}