Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 58 additions & 1 deletion fieldpath/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,66 @@ func TestPathString(t *testing.T) {
_V(false),
_V(3.14159),
), `.foo[="b"][=5][=false][=3.14159]`},
{
name: "simple field",
fp: MakePathOrDie("spec"),
expect: ".spec",
},
{
name: "app container image",
fp: MakePathOrDie(
"spec", "apps",
KeyByFields("name", "app-🚀"),
"container", "image",
),
expect: `.spec.apps[name="app-🚀"].container.image`,
},
{
name: "app port",
fp: MakePathOrDie(
"spec", "apps",
KeyByFields("name", "app-💻"),
"container", "ports",
KeyByFields("name", "port-🔑"),
"containerPort",
),
expect: ".spec.apps[name=\"app-💻\"].container.ports[name=\"port-🔑\"].containerPort",
},
{
name: "field with space",
fp: MakePathOrDie("spec", "field with space"),
expect: ".spec.field with space",
},
{
name: "value with space",
fp: MakePathOrDie(
"spec", "apps",
_V("app with space"),
"container", "image",
),
expect: `.spec.apps[="app with space"].container.image`,
},
{
name: "value with quotes",
fp: MakePathOrDie(
"spec", "apps",
_V("app with \"quotes\""),
"container", "image",
),
expect: ".spec.apps[=\"app with \\\"quotes\\\"\"].container.image",
},

{
name: "value with unicode",
fp: MakePathOrDie(
"spec", "apps",
_V("app-with-unicøde"),
"container", "image",
),
expect: ".spec.apps[=\"app-with-unicøde\"].container.image",
},
}
for _, tt := range table {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got := tt.fp.String()
Expand Down
8 changes: 8 additions & 0 deletions fieldpath/serialize-pe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestPathElementRoundTrip(t *testing.T) {
`f:`,
`f:spec`,
`f:more-complicated-string`,
`f:abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789`,
`k:{"name":"my-container"}`,
`k:{"port":"8080","protocol":"TCP"}`,
`k:{"optionalField":null}`,
Expand All @@ -34,6 +35,13 @@ func TestPathElementRoundTrip(t *testing.T) {
`v:"some-string"`,
`v:1234`,
`v:{"some":"json"}`,
`k:{"name":"app-🚀"}`,
`k:{"name":"app-💻"}`,
`k:{"name":"app with-unicøde"}`,
`k:{"name":"你好世界"}`,
`k:{"name":"Привет, мир"}`,
`k:{"name":"नमस्ते दुनिया"}`,
`k:{"name":"👋"}`,
}

for _, test := range tests {
Expand Down
1 change: 1 addition & 0 deletions fieldpath/serialize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func TestSerializeV1GoldenData(t *testing.T) {
examples := []string{
`{"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":{}}`,
`{"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\"}":{}}}}}`,
`{"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":{}}}}}`,
}
for i, str := range examples {
t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {
Expand Down
23 changes: 22 additions & 1 deletion fieldpath/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,38 @@ var randomPathMaker = randomPathAlphabet(MakePathOrDie(
"aad",
"aae",
"aaf",
// All alphabets
"abcdefghijklmnopqrstuvwxyz",
"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
// Keys
KeyByFields("name", "привет"),
KeyByFields("name", "你好"),
KeyByFields("name", "こんにちは"),
KeyByFields("name", "안녕하세요"),
KeyByFields("name", "مرحبا"),
KeyByFields("name", "first"),
KeyByFields("name", "second"),
KeyByFields("port", 443, "protocol", "tcp"),
KeyByFields("port", 443, "protocol", "udp"),
KeyByFields("key", "value"),
KeyByFields("lang", "en-US"),
KeyByFields("unicode-key", "unicode-value-🔥"),
// Values
_V(1),
_V(2),
_V(3),
_V("aa"),
_V("ab"),
_V(true),
1, 2, 3, 4,
_V(0),
_V(-1),
_V(3.14159),
_V("string with spaces"),
_V("string with \"quotes\""),
_V("unicode-string-你好"),
_V(false),
// Indices
1, 2, 3, 4, 0, 5, 100, 2147483648,
))

func BenchmarkFieldSet(b *testing.B) {
Expand Down