forked from flyteorg/flyte
-
Notifications
You must be signed in to change notification settings - Fork 0
/
encoder_test.go
61 lines (57 loc) · 1.5 KB
/
encoder_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
54
55
56
57
58
59
60
61
package encoding
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestFixedLengthUniqueID(t *testing.T) {
tests := []struct {
name string
input string
maxLength int
output string
expectError bool
}{
{"smallerThanMax", "x", 5, "x", false},
{"veryLowLimit", "xx", 1, "flfryc2i", true},
{"highLimit", "xxxxxx", 5, "fufiti6i", true},
{"higherLimit", "xxxxx", 10, "xxxxx", false},
{"largeID", "xxxxxxxxxxx", 10, "fggddjly", false},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
i, err := FixedLengthUniqueID(test.input, test.maxLength)
if test.expectError {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
assert.Equal(t, i, test.output)
})
}
}
func TestFixedLengthUniqueIDForParts(t *testing.T) {
tests := []struct {
name string
parts []string
maxLength int
output string
expectError bool
}{
{"smallerThanMax", []string{"x", "y", "z"}, 10, "x-y-z", false},
{"veryLowLimit", []string{"x", "y"}, 1, "fz2jizji", true},
{"fittingID", []string{"x"}, 2, "x", false},
{"highLimit", []string{"x", "y", "z"}, 4, "fxzsoqrq", true},
{"largeID", []string{"x", "y", "z", "m", "n"}, 8, "fsigbmty", false},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
i, err := FixedLengthUniqueIDForParts(test.maxLength, test.parts...)
if test.expectError {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
assert.Equal(t, i, test.output)
})
}
}