Skip to content

Commit f328e0f

Browse files
committed
Add more test coverage for searialization and deserialization
1 parent 3b54170 commit f328e0f

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

fieldpath/serialize-pe_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ limitations under the License.
1616

1717
package fieldpath
1818

19-
import "testing"
19+
import (
20+
"testing"
21+
)
2022

2123
func TestPathElementRoundTrip(t *testing.T) {
2224
tests := []string{
@@ -25,8 +27,10 @@ func TestPathElementRoundTrip(t *testing.T) {
2527
`f:`,
2628
`f:spec`,
2729
`f:more-complicated-string`,
30+
`f: string-with-spaces `,
2831
`f:abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789`,
2932
`k:{"name":"my-container"}`,
33+
`k:{"name":" name with spaces "}`,
3034
`k:{"port":"8080","protocol":"TCP"}`,
3135
`k:{"optionalField":null}`,
3236
`k:{"jsonField":{"A":1,"B":null,"C":"D","E":{"F":"G"}}}`,
@@ -35,6 +39,7 @@ func TestPathElementRoundTrip(t *testing.T) {
3539
`v:"some-string"`,
3640
`v:1234`,
3741
`v:{"some":"json"}`,
42+
`v:{"some":" some with spaces "}`,
3843
`k:{"name":"app-🚀"}`,
3944
`k:{"name":"app-💻"}`,
4045
`k:{"name":"app with-unicøde"}`,
@@ -79,6 +84,7 @@ func TestDeserializePathElementError(t *testing.T) {
7984
`v:`,
8085
`k:invalid json`,
8186
`k:{"name":invalid}`,
87+
`v:{"some":" \x41"}`, // This is an invalid JSON string because \x41 is not a valid escape sequence.
8288
}
8389

8490
for _, test := range tests {

fieldpath/serialize_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +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":{}}}}}`,
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":{}}}}}`,
5555
}
5656
for i, str := range examples {
5757
t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {

fieldpath/set_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ var randomPathMaker = randomPathAlphabet(MakePathOrDie(
6161
KeyByFields("name", "second"),
6262
KeyByFields("port", 443, "protocol", "tcp"),
6363
KeyByFields("port", 443, "protocol", "udp"),
64-
KeyByFields("key", "value"),
64+
KeyByFields("key", " value with spaces "),
6565
KeyByFields("lang", "en-US"),
6666
KeyByFields("unicode-key", "unicode-value-🔥"),
6767
// Values

0 commit comments

Comments
 (0)