Skip to content

Commit 789a688

Browse files
authored
Merge pull request #300 from lalitc375/test-coverage
feat(testing): Add comprehensive tests for unicode and special characters
2 parents 2463673 + 544b1e3 commit 789a688

File tree

4 files changed

+89
-2
lines changed

4 files changed

+89
-2
lines changed

fieldpath/path_test.go

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,66 @@ func TestPathString(t *testing.T) {
5050
_V(false),
5151
_V(3.14159),
5252
), `.foo[="b"][=5][=false][=3.14159]`},
53+
{
54+
name: "simple field",
55+
fp: MakePathOrDie("spec"),
56+
expect: ".spec",
57+
},
58+
{
59+
name: "app container image",
60+
fp: MakePathOrDie(
61+
"spec", "apps",
62+
KeyByFields("name", "app-🚀"),
63+
"container", "image",
64+
),
65+
expect: `.spec.apps[name="app-🚀"].container.image`,
66+
},
67+
{
68+
name: "app port",
69+
fp: MakePathOrDie(
70+
"spec", "apps",
71+
KeyByFields("name", "app-💻"),
72+
"container", "ports",
73+
KeyByFields("name", "port-🔑"),
74+
"containerPort",
75+
),
76+
expect: ".spec.apps[name=\"app-💻\"].container.ports[name=\"port-🔑\"].containerPort",
77+
},
78+
{
79+
name: "field with space",
80+
fp: MakePathOrDie("spec", "field with space"),
81+
expect: ".spec.field with space",
82+
},
83+
{
84+
name: "value with space",
85+
fp: MakePathOrDie(
86+
"spec", "apps",
87+
_V("app with space"),
88+
"container", "image",
89+
),
90+
expect: `.spec.apps[="app with space"].container.image`,
91+
},
92+
{
93+
name: "value with quotes",
94+
fp: MakePathOrDie(
95+
"spec", "apps",
96+
_V("app with \"quotes\""),
97+
"container", "image",
98+
),
99+
expect: ".spec.apps[=\"app with \\\"quotes\\\"\"].container.image",
100+
},
101+
102+
{
103+
name: "value with unicode",
104+
fp: MakePathOrDie(
105+
"spec", "apps",
106+
_V("app-with-unicøde"),
107+
"container", "image",
108+
),
109+
expect: ".spec.apps[=\"app-with-unicøde\"].container.image",
110+
},
53111
}
54112
for _, tt := range table {
55-
tt := tt
56113
t.Run(tt.name, func(t *testing.T) {
57114
t.Parallel()
58115
got := tt.fp.String()

fieldpath/serialize-pe_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func TestPathElementRoundTrip(t *testing.T) {
2525
`f:`,
2626
`f:spec`,
2727
`f:more-complicated-string`,
28+
`f:abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789`,
2829
`k:{"name":"my-container"}`,
2930
`k:{"port":"8080","protocol":"TCP"}`,
3031
`k:{"optionalField":null}`,
@@ -34,6 +35,13 @@ func TestPathElementRoundTrip(t *testing.T) {
3435
`v:"some-string"`,
3536
`v:1234`,
3637
`v:{"some":"json"}`,
38+
`k:{"name":"app-🚀"}`,
39+
`k:{"name":"app-💻"}`,
40+
`k:{"name":"app with-unicøde"}`,
41+
`k:{"name":"你好世界"}`,
42+
`k:{"name":"Привет, мир"}`,
43+
`k:{"name":"नमस्ते दुनिया"}`,
44+
`k:{"name":"👋"}`,
3745
}
3846

3947
for _, test := range tests {

fieldpath/serialize_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func TestSerializeV1GoldenData(t *testing.T) {
5151
examples := []string{
5252
`{"f:aaa":{},"f:aab":{},"f:aac":{},"f:aad":{},"f:aae":{},"f:aaf":{},"k:{\"name\":\"first\"}":{},"k:{\"name\":\"second\"}":{},"k:{\"port\":443,\"protocol\":\"tcp\"}":{},"k:{\"port\":443,\"protocol\":\"udp\"}":{},"v:1":{},"v:2":{},"v:3":{},"v:\"aa\"":{},"v:\"ab\"":{},"v:true":{},"i:1":{},"i:2":{},"i:3":{},"i:4":{}}`,
5353
`{"f:aaa":{"k:{\"name\":\"second\"}":{"v:3":{"f:aab":{}}},"v:3":{},"v:true":{}},"f:aab":{"f:aaa":{},"f:aaf":{"k:{\"port\":443,\"protocol\":\"udp\"}":{"k:{\"port\":443,\"protocol\":\"tcp\"}":{}}},"k:{\"name\":\"first\"}":{}},"f:aac":{"f:aaa":{"v:1":{}},"f:aac":{},"v:3":{"k:{\"name\":\"second\"}":{}}},"f:aad":{"f:aac":{"v:1":{}},"f:aaf":{"k:{\"name\":\"first\"}":{"k:{\"name\":\"first\"}":{}}},"i:1":{"i:1":{},"i:3":{"v:true":{}}}},"f:aae":{"f:aae":{},"k:{\"port\":443,\"protocol\":\"tcp\"}":{"k:{\"port\":443,\"protocol\":\"udp\"}":{}},"i:4":{"f:aaf":{}}},"f:aaf":{"i:1":{"f:aac":{}},"i:2":{},"i:3":{}},"k:{\"name\":\"first\"}":{"f:aad":{"f:aaf":{}}},"k:{\"port\":443,\"protocol\":\"tcp\"}":{"f:aaa":{"f:aad":{}}},"k:{\"port\":443,\"protocol\":\"udp\"}":{"f:aac":{},"k:{\"name\":\"first\"}":{"i:3":{}},"k:{\"port\":443,\"protocol\":\"udp\"}":{"i:4":{}}},"v:1":{"f:aac":{"i:4":{}},"f:aaf":{},"k:{\"port\":443,\"protocol\":\"tcp\"}":{}},"v:2":{"f:aad":{"f:aaf":{}},"i:1":{}},"v:3":{"f:aaa":{},"k:{\"name\":\"first\"}":{},"i:2":{}},"v:\"aa\"":{"f:aab":{"f:aaf":{}},"f:aae":{},"k:{\"name\":\"first\"}":{"f:aad":{}},"i:2":{}},"v:\"ab\"":{"f:aaf":{"i:4":{}},"k:{\"port\":443,\"protocol\":\"tcp\"}":{},"k:{\"port\":443,\"protocol\":\"udp\"}":{},"v:1":{"k:{\"port\":443,\"protocol\":\"udp\"}":{}},"i:1":{"f:aae":{"i:4":{}}}},"v:true":{"k:{\"name\":\"second\"}":{"f:aaa":{}},"i:2":{"k:{\"port\":443,\"protocol\":\"tcp\"}":{}}},"i:1":{"i:3":{"f:aaf":{}}},"i:2":{"f:aae":{},"k:{\"port\":443,\"protocol\":\"tcp\"}":{"v:1":{}}},"i:3":{"f:aab":{"v:true":{"v:\"aa\"":{}}},"f:aaf":{},"i:1":{}},"i:4":{"v:\"aa\"":{"f:aab":{"k:{\"name\":\"second\"}":{}}}}}`,
54+
`{"f:spec":{".":{},"f:apps":{".":{},"k:{\"name\":\"app-💻\"}":{".":{},"f:container":{".":{},"f:image":{},"f:name":{},"f:ports":{".":{},"k:{\"name\":\"port-🔑\"}":{".":{},"f:containerPort":{},"f:name":{}}}},"f:name":{}},"k:{\"name\":\"app-🚀\"}":{".":{},"f:container":{".":{},"f:image":{},"f:name":{},"f:ports":{".":{},"k:{\"name\":\"port-✅\"}":{".":{},"f:containerPort":{},"f:name":{}}}},"f:name":{}}}}}`,
5455
}
5556
for i, str := range examples {
5657
t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {

fieldpath/set_test.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,38 @@ var randomPathMaker = randomPathAlphabet(MakePathOrDie(
4848
"aad",
4949
"aae",
5050
"aaf",
51+
// All alphabets
52+
"abcdefghijklmnopqrstuvwxyz",
53+
"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
54+
// Keys
55+
KeyByFields("name", "привет"),
56+
KeyByFields("name", "你好"),
57+
KeyByFields("name", "こんにちは"),
58+
KeyByFields("name", "안녕하세요"),
59+
KeyByFields("name", "مرحبا"),
5160
KeyByFields("name", "first"),
5261
KeyByFields("name", "second"),
5362
KeyByFields("port", 443, "protocol", "tcp"),
5463
KeyByFields("port", 443, "protocol", "udp"),
64+
KeyByFields("key", "value"),
65+
KeyByFields("lang", "en-US"),
66+
KeyByFields("unicode-key", "unicode-value-🔥"),
67+
// Values
5568
_V(1),
5669
_V(2),
5770
_V(3),
5871
_V("aa"),
5972
_V("ab"),
6073
_V(true),
61-
1, 2, 3, 4,
74+
_V(0),
75+
_V(-1),
76+
_V(3.14159),
77+
_V("string with spaces"),
78+
_V("string with \"quotes\""),
79+
_V("unicode-string-你好"),
80+
_V(false),
81+
// Indices
82+
1, 2, 3, 4, 0, 5, 100, 2147483648,
6283
))
6384

6485
func BenchmarkFieldSet(b *testing.B) {

0 commit comments

Comments
 (0)