MCPcopy Create free account
hub / github.com/coder/coder / TestTruncate

Function TestTruncate

coderd/util/namesgenerator/namesgenerator_internal_test.go:11–66  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestTruncate(t *testing.T) {
12 t.Parallel()
13
14 tests := []struct {
15 name string
16 input string
17 maxLen int
18 want string
19 }{
20 {
21 name: "no truncation needed",
22 input: "foo1",
23 maxLen: 10,
24 want: "foo1",
25 },
26 {
27 name: "exact fit",
28 input: "foo1",
29 maxLen: 4,
30 want: "foo1",
31 },
32 {
33 name: "truncate base",
34 input: "foobar42",
35 maxLen: 5,
36 want: "foo42",
37 },
38 {
39 name: "truncate more",
40 input: "foobar3",
41 maxLen: 3,
42 want: "fo3",
43 },
44 {
45 name: "long suffix",
46 input: "foo123456",
47 maxLen: 8,
48 want: "fo123456",
49 },
50 {
51 name: "realistic name",
52 input: "condescending_proskuriakova999999",
53 maxLen: 32,
54 want: "condescending_proskuriakov999999",
55 },
56 }
57
58 for _, tt := range tests {
59 t.Run(tt.name, func(t *testing.T) {
60 t.Parallel()
61 got := truncate(tt.input, tt.maxLen)
62 assert.Equal(t, tt.want, got)
63 assert.LessOrEqual(t, len(got), tt.maxLen)
64 })
65 }
66}
67
68func TestUniqueNameLength(t *testing.T) {

Callers

nothing calls this directly

Calls 3

truncateFunction · 0.85
RunMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected