...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package internal
16
17 import (
18 "strings"
19 "testing"
20 )
21
22 func TestSanitize(t *testing.T) {
23 tests := []struct {
24 name string
25 input string
26 want string
27 }{
28 {
29 name: "trunacate long string",
30 input: strings.Repeat("a", 101),
31 want: strings.Repeat("a", 100),
32 },
33 {
34 name: "replace character",
35 input: "test/key-1",
36 want: "test_key_1",
37 },
38 {
39 name: "add prefix if starting with digit",
40 input: "0123456789",
41 want: "key_0123456789",
42 },
43 {
44 name: "add prefix if starting with _",
45 input: "_0123456789",
46 want: "key_0123456789",
47 },
48 {
49 name: "starts with _ after sanitization",
50 input: "/0123456789",
51 want: "key_0123456789",
52 },
53 {
54 name: "valid input",
55 input: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789",
56 want: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789",
57 },
58 }
59
60 for _, tt := range tests {
61 t.Run(tt.name, func(t *testing.T) {
62 if got, want := Sanitize(tt.input), tt.want; got != want {
63 t.Errorf("sanitize() = %q; want %q", got, want)
64 }
65 })
66 }
67 }
68
View as plain text